1 //===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "MCTargetDesc/ARMBaseInfo.h"
11 #include "MCTargetDesc/ARMAddressingModes.h"
12 #include "MCTargetDesc/ARMMCExpr.h"
13 #include "llvm/MC/MCParser/MCAsmLexer.h"
14 #include "llvm/MC/MCParser/MCAsmParser.h"
15 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCInstrDesc.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/MC/MCTargetAsmParser.h"
25 #include "llvm/Support/MathExtras.h"
26 #include "llvm/Support/SourceMgr.h"
27 #include "llvm/Support/TargetRegistry.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include "llvm/ADT/BitVector.h"
30 #include "llvm/ADT/OwningPtr.h"
31 #include "llvm/ADT/STLExtras.h"
32 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/ADT/StringSwitch.h"
34 #include "llvm/ADT/Twine.h"
42 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
44 class ARMAsmParser : public MCTargetAsmParser {
47 const MCRegisterInfo *MRI;
49 // Map of register aliases registers via the .req directive.
50 StringMap<unsigned> RegisterReqs;
53 ARMCC::CondCodes Cond; // Condition for IT block.
54 unsigned Mask:4; // Condition mask for instructions.
55 // Starting at first 1 (from lsb).
56 // '1' condition as indicated in IT.
57 // '0' inverse of condition (else).
58 // Count of instructions in IT block is
59 // 4 - trailingzeroes(mask)
61 bool FirstCond; // Explicit flag for when we're parsing the
62 // First instruction in the IT block. It's
63 // implied in the mask, so needs special
66 unsigned CurPosition; // Current position in parsing of IT
67 // block. In range [0,3]. Initialized
68 // according to count of instructions in block.
69 // ~0U if no active IT block.
71 bool inITBlock() { return ITState.CurPosition != ~0U;}
72 void forwardITPosition() {
73 if (!inITBlock()) return;
74 // Move to the next instruction in the IT block, if there is one. If not,
75 // mark the block as done.
76 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
77 if (++ITState.CurPosition == 5 - TZ)
78 ITState.CurPosition = ~0U; // Done with the IT block after this.
82 MCAsmParser &getParser() const { return Parser; }
83 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
85 bool Warning(SMLoc L, const Twine &Msg,
86 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
87 return Parser.Warning(L, Msg, Ranges);
89 bool Error(SMLoc L, const Twine &Msg,
90 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
91 return Parser.Error(L, Msg, Ranges);
94 int tryParseRegister();
95 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
96 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
97 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
98 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
99 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
100 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
101 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
102 unsigned &ShiftAmount);
103 bool parseDirectiveWord(unsigned Size, SMLoc L);
104 bool parseDirectiveThumb(SMLoc L);
105 bool parseDirectiveARM(SMLoc L);
106 bool parseDirectiveThumbFunc(SMLoc L);
107 bool parseDirectiveCode(SMLoc L);
108 bool parseDirectiveSyntax(SMLoc L);
109 bool parseDirectiveReq(StringRef Name, SMLoc L);
110 bool parseDirectiveUnreq(SMLoc L);
111 bool parseDirectiveArch(SMLoc L);
112 bool parseDirectiveEabiAttr(SMLoc L);
114 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
115 bool &CarrySetting, unsigned &ProcessorIMod,
117 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
118 bool &CanAcceptPredicationCode);
120 bool isThumb() const {
121 // FIXME: Can tablegen auto-generate this?
122 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
124 bool isThumbOne() const {
125 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
127 bool isThumbTwo() const {
128 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
130 bool hasV6Ops() const {
131 return STI.getFeatureBits() & ARM::HasV6Ops;
133 bool hasV7Ops() const {
134 return STI.getFeatureBits() & ARM::HasV7Ops;
137 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
138 setAvailableFeatures(FB);
140 bool isMClass() const {
141 return STI.getFeatureBits() & ARM::FeatureMClass;
144 /// @name Auto-generated Match Functions
147 #define GET_ASSEMBLER_HEADER
148 #include "ARMGenAsmMatcher.inc"
152 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
153 OperandMatchResultTy parseCoprocNumOperand(
154 SmallVectorImpl<MCParsedAsmOperand*>&);
155 OperandMatchResultTy parseCoprocRegOperand(
156 SmallVectorImpl<MCParsedAsmOperand*>&);
157 OperandMatchResultTy parseCoprocOptionOperand(
158 SmallVectorImpl<MCParsedAsmOperand*>&);
159 OperandMatchResultTy parseMemBarrierOptOperand(
160 SmallVectorImpl<MCParsedAsmOperand*>&);
161 OperandMatchResultTy parseProcIFlagsOperand(
162 SmallVectorImpl<MCParsedAsmOperand*>&);
163 OperandMatchResultTy parseMSRMaskOperand(
164 SmallVectorImpl<MCParsedAsmOperand*>&);
165 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
166 StringRef Op, int Low, int High);
167 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
168 return parsePKHImm(O, "lsl", 0, 31);
170 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
171 return parsePKHImm(O, "asr", 1, 32);
173 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
174 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
175 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
176 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
177 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
178 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
179 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
180 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
181 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
183 // Asm Match Converter Methods
184 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
185 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
186 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
187 const SmallVectorImpl<MCParsedAsmOperand*> &);
188 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
189 const SmallVectorImpl<MCParsedAsmOperand*> &);
190 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
191 const SmallVectorImpl<MCParsedAsmOperand*> &);
192 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
193 const SmallVectorImpl<MCParsedAsmOperand*> &);
194 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
195 const SmallVectorImpl<MCParsedAsmOperand*> &);
196 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
197 const SmallVectorImpl<MCParsedAsmOperand*> &);
198 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
199 const SmallVectorImpl<MCParsedAsmOperand*> &);
200 void cvtLdExtTWriteBackImm(MCInst &Inst,
201 const SmallVectorImpl<MCParsedAsmOperand*> &);
202 void cvtLdExtTWriteBackReg(MCInst &Inst,
203 const SmallVectorImpl<MCParsedAsmOperand*> &);
204 void cvtStExtTWriteBackImm(MCInst &Inst,
205 const SmallVectorImpl<MCParsedAsmOperand*> &);
206 void cvtStExtTWriteBackReg(MCInst &Inst,
207 const SmallVectorImpl<MCParsedAsmOperand*> &);
208 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
209 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
210 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
211 const SmallVectorImpl<MCParsedAsmOperand*> &);
212 void cvtThumbMultiply(MCInst &Inst,
213 const SmallVectorImpl<MCParsedAsmOperand*> &);
214 void cvtVLDwbFixed(MCInst &Inst,
215 const SmallVectorImpl<MCParsedAsmOperand*> &);
216 void cvtVLDwbRegister(MCInst &Inst,
217 const SmallVectorImpl<MCParsedAsmOperand*> &);
218 void cvtVSTwbFixed(MCInst &Inst,
219 const SmallVectorImpl<MCParsedAsmOperand*> &);
220 void cvtVSTwbRegister(MCInst &Inst,
221 const SmallVectorImpl<MCParsedAsmOperand*> &);
222 bool validateInstruction(MCInst &Inst,
223 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
224 bool processInstruction(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
226 bool shouldOmitCCOutOperand(StringRef Mnemonic,
227 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
230 enum ARMMatchResultTy {
231 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
232 Match_RequiresNotITBlock,
234 Match_RequiresThumb2,
235 #define GET_OPERAND_DIAGNOSTIC_TYPES
236 #include "ARMGenAsmMatcher.inc"
240 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
241 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
242 MCAsmParserExtension::Initialize(_Parser);
244 // Cache the MCRegisterInfo.
245 MRI = &getContext().getRegisterInfo();
247 // Initialize the set of available features.
248 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
250 // Not in an ITBlock to start with.
251 ITState.CurPosition = ~0U;
254 // Implementation of the MCTargetAsmParser interface:
255 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
256 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
257 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
258 bool ParseDirective(AsmToken DirectiveID);
260 bool mnemonicIsValid(StringRef Mnemonic) {
261 return mnemonicIsValidImpl(Mnemonic);
264 unsigned checkTargetMatchPredicate(MCInst &Inst);
266 bool MatchAndEmitInstruction(SMLoc IDLoc,
267 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
270 unsigned getMCInstOperandNum(unsigned Kind, MCInst &Inst,
271 const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
272 unsigned OperandNum, unsigned &NumMCOperands) {
273 return getMCInstOperandNumImpl(Kind, Inst, Operands, OperandNum, NumMCOperands);
276 } // end anonymous namespace
280 /// ARMOperand - Instances of this class represent a parsed ARM machine
282 class ARMOperand : public MCParsedAsmOperand {
302 k_VectorListAllLanes,
308 k_BitfieldDescriptor,
312 SMLoc StartLoc, EndLoc;
313 SmallVector<unsigned, 8> Registers;
317 ARMCC::CondCodes Val;
337 ARM_PROC::IFlags Val;
353 // A vector register list is a sequential list of 1 to 4 registers.
369 /// Combined record for all forms of ARM address expressions.
372 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
374 const MCConstantExpr *OffsetImm; // Offset immediate value
375 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
376 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
377 unsigned ShiftImm; // shift for OffsetReg.
378 unsigned Alignment; // 0 = no alignment specified
379 // n = alignment in bytes (2, 4, 8, 16, or 32)
380 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
386 ARM_AM::ShiftOpc ShiftTy;
395 ARM_AM::ShiftOpc ShiftTy;
401 ARM_AM::ShiftOpc ShiftTy;
414 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
416 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
418 StartLoc = o.StartLoc;
435 case k_DPRRegisterList:
436 case k_SPRRegisterList:
437 Registers = o.Registers;
440 case k_VectorListAllLanes:
441 case k_VectorListIndexed:
442 VectorList = o.VectorList;
449 CoprocOption = o.CoprocOption;
454 case k_MemBarrierOpt:
460 case k_PostIndexRegister:
461 PostIdxReg = o.PostIdxReg;
469 case k_ShifterImmediate:
470 ShifterImm = o.ShifterImm;
472 case k_ShiftedRegister:
473 RegShiftedReg = o.RegShiftedReg;
475 case k_ShiftedImmediate:
476 RegShiftedImm = o.RegShiftedImm;
478 case k_RotateImmediate:
481 case k_BitfieldDescriptor:
482 Bitfield = o.Bitfield;
485 VectorIndex = o.VectorIndex;
490 /// getStartLoc - Get the location of the first token of this operand.
491 SMLoc getStartLoc() const { return StartLoc; }
492 /// getEndLoc - Get the location of the last token of this operand.
493 SMLoc getEndLoc() const { return EndLoc; }
494 /// getLocRange - Get the range between the first and last token of this
496 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
498 ARMCC::CondCodes getCondCode() const {
499 assert(Kind == k_CondCode && "Invalid access!");
503 unsigned getCoproc() const {
504 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
508 StringRef getToken() const {
509 assert(Kind == k_Token && "Invalid access!");
510 return StringRef(Tok.Data, Tok.Length);
513 unsigned getReg() const {
514 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
518 const SmallVectorImpl<unsigned> &getRegList() const {
519 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
520 Kind == k_SPRRegisterList) && "Invalid access!");
524 const MCExpr *getImm() const {
525 assert(isImm() && "Invalid access!");
529 unsigned getVectorIndex() const {
530 assert(Kind == k_VectorIndex && "Invalid access!");
531 return VectorIndex.Val;
534 ARM_MB::MemBOpt getMemBarrierOpt() const {
535 assert(Kind == k_MemBarrierOpt && "Invalid access!");
539 ARM_PROC::IFlags getProcIFlags() const {
540 assert(Kind == k_ProcIFlags && "Invalid access!");
544 unsigned getMSRMask() const {
545 assert(Kind == k_MSRMask && "Invalid access!");
549 bool isCoprocNum() const { return Kind == k_CoprocNum; }
550 bool isCoprocReg() const { return Kind == k_CoprocReg; }
551 bool isCoprocOption() const { return Kind == k_CoprocOption; }
552 bool isCondCode() const { return Kind == k_CondCode; }
553 bool isCCOut() const { return Kind == k_CCOut; }
554 bool isITMask() const { return Kind == k_ITCondMask; }
555 bool isITCondCode() const { return Kind == k_CondCode; }
556 bool isImm() const { return Kind == k_Immediate; }
557 bool isFPImm() const {
558 if (!isImm()) return false;
559 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
560 if (!CE) return false;
561 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
564 bool isFBits16() const {
565 if (!isImm()) return false;
566 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
567 if (!CE) return false;
568 int64_t Value = CE->getValue();
569 return Value >= 0 && Value <= 16;
571 bool isFBits32() const {
572 if (!isImm()) return false;
573 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
574 if (!CE) return false;
575 int64_t Value = CE->getValue();
576 return Value >= 1 && Value <= 32;
578 bool isImm8s4() const {
579 if (!isImm()) return false;
580 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
581 if (!CE) return false;
582 int64_t Value = CE->getValue();
583 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
585 bool isImm0_1020s4() const {
586 if (!isImm()) return false;
587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
588 if (!CE) return false;
589 int64_t Value = CE->getValue();
590 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
592 bool isImm0_508s4() const {
593 if (!isImm()) return false;
594 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
595 if (!CE) return false;
596 int64_t Value = CE->getValue();
597 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
599 bool isImm0_508s4Neg() const {
600 if (!isImm()) return false;
601 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
602 if (!CE) return false;
603 int64_t Value = -CE->getValue();
604 // explicitly exclude zero. we want that to use the normal 0_508 version.
605 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
607 bool isImm0_255() const {
608 if (!isImm()) return false;
609 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
610 if (!CE) return false;
611 int64_t Value = CE->getValue();
612 return Value >= 0 && Value < 256;
614 bool isImm0_4095() const {
615 if (!isImm()) return false;
616 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
617 if (!CE) return false;
618 int64_t Value = CE->getValue();
619 return Value >= 0 && Value < 4096;
621 bool isImm0_4095Neg() const {
622 if (!isImm()) return false;
623 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
624 if (!CE) return false;
625 int64_t Value = -CE->getValue();
626 return Value > 0 && Value < 4096;
628 bool isImm0_1() const {
629 if (!isImm()) return false;
630 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
631 if (!CE) return false;
632 int64_t Value = CE->getValue();
633 return Value >= 0 && Value < 2;
635 bool isImm0_3() const {
636 if (!isImm()) return false;
637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
638 if (!CE) return false;
639 int64_t Value = CE->getValue();
640 return Value >= 0 && Value < 4;
642 bool isImm0_7() const {
643 if (!isImm()) return false;
644 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
645 if (!CE) return false;
646 int64_t Value = CE->getValue();
647 return Value >= 0 && Value < 8;
649 bool isImm0_15() const {
650 if (!isImm()) return false;
651 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
652 if (!CE) return false;
653 int64_t Value = CE->getValue();
654 return Value >= 0 && Value < 16;
656 bool isImm0_31() const {
657 if (!isImm()) return false;
658 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
659 if (!CE) return false;
660 int64_t Value = CE->getValue();
661 return Value >= 0 && Value < 32;
663 bool isImm0_63() const {
664 if (!isImm()) return false;
665 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
666 if (!CE) return false;
667 int64_t Value = CE->getValue();
668 return Value >= 0 && Value < 64;
670 bool isImm8() const {
671 if (!isImm()) return false;
672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
673 if (!CE) return false;
674 int64_t Value = CE->getValue();
677 bool isImm16() const {
678 if (!isImm()) return false;
679 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
680 if (!CE) return false;
681 int64_t Value = CE->getValue();
684 bool isImm32() const {
685 if (!isImm()) return false;
686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
687 if (!CE) return false;
688 int64_t Value = CE->getValue();
691 bool isShrImm8() const {
692 if (!isImm()) return false;
693 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
694 if (!CE) return false;
695 int64_t Value = CE->getValue();
696 return Value > 0 && Value <= 8;
698 bool isShrImm16() const {
699 if (!isImm()) return false;
700 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
701 if (!CE) return false;
702 int64_t Value = CE->getValue();
703 return Value > 0 && Value <= 16;
705 bool isShrImm32() const {
706 if (!isImm()) return false;
707 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
708 if (!CE) return false;
709 int64_t Value = CE->getValue();
710 return Value > 0 && Value <= 32;
712 bool isShrImm64() const {
713 if (!isImm()) return false;
714 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
715 if (!CE) return false;
716 int64_t Value = CE->getValue();
717 return Value > 0 && Value <= 64;
719 bool isImm1_7() const {
720 if (!isImm()) return false;
721 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
722 if (!CE) return false;
723 int64_t Value = CE->getValue();
724 return Value > 0 && Value < 8;
726 bool isImm1_15() const {
727 if (!isImm()) return false;
728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
729 if (!CE) return false;
730 int64_t Value = CE->getValue();
731 return Value > 0 && Value < 16;
733 bool isImm1_31() const {
734 if (!isImm()) return false;
735 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
736 if (!CE) return false;
737 int64_t Value = CE->getValue();
738 return Value > 0 && Value < 32;
740 bool isImm1_16() const {
741 if (!isImm()) return false;
742 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
743 if (!CE) return false;
744 int64_t Value = CE->getValue();
745 return Value > 0 && Value < 17;
747 bool isImm1_32() const {
748 if (!isImm()) return false;
749 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
750 if (!CE) return false;
751 int64_t Value = CE->getValue();
752 return Value > 0 && Value < 33;
754 bool isImm0_32() const {
755 if (!isImm()) return false;
756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
757 if (!CE) return false;
758 int64_t Value = CE->getValue();
759 return Value >= 0 && Value < 33;
761 bool isImm0_65535() const {
762 if (!isImm()) return false;
763 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
764 if (!CE) return false;
765 int64_t Value = CE->getValue();
766 return Value >= 0 && Value < 65536;
768 bool isImm0_65535Expr() const {
769 if (!isImm()) return false;
770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
771 // If it's not a constant expression, it'll generate a fixup and be
773 if (!CE) return true;
774 int64_t Value = CE->getValue();
775 return Value >= 0 && Value < 65536;
777 bool isImm24bit() const {
778 if (!isImm()) return false;
779 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
780 if (!CE) return false;
781 int64_t Value = CE->getValue();
782 return Value >= 0 && Value <= 0xffffff;
784 bool isImmThumbSR() const {
785 if (!isImm()) return false;
786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
787 if (!CE) return false;
788 int64_t Value = CE->getValue();
789 return Value > 0 && Value < 33;
791 bool isPKHLSLImm() const {
792 if (!isImm()) return false;
793 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
794 if (!CE) return false;
795 int64_t Value = CE->getValue();
796 return Value >= 0 && Value < 32;
798 bool isPKHASRImm() const {
799 if (!isImm()) return false;
800 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
801 if (!CE) return false;
802 int64_t Value = CE->getValue();
803 return Value > 0 && Value <= 32;
805 bool isAdrLabel() const {
806 // If we have an immediate that's not a constant, treat it as a label
807 // reference needing a fixup. If it is a constant, but it can't fit
808 // into shift immediate encoding, we reject it.
809 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
810 else return (isARMSOImm() || isARMSOImmNeg());
812 bool isARMSOImm() const {
813 if (!isImm()) return false;
814 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
815 if (!CE) return false;
816 int64_t Value = CE->getValue();
817 return ARM_AM::getSOImmVal(Value) != -1;
819 bool isARMSOImmNot() const {
820 if (!isImm()) return false;
821 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
822 if (!CE) return false;
823 int64_t Value = CE->getValue();
824 return ARM_AM::getSOImmVal(~Value) != -1;
826 bool isARMSOImmNeg() const {
827 if (!isImm()) return false;
828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
829 if (!CE) return false;
830 int64_t Value = CE->getValue();
831 // Only use this when not representable as a plain so_imm.
832 return ARM_AM::getSOImmVal(Value) == -1 &&
833 ARM_AM::getSOImmVal(-Value) != -1;
835 bool isT2SOImm() const {
836 if (!isImm()) return false;
837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
838 if (!CE) return false;
839 int64_t Value = CE->getValue();
840 return ARM_AM::getT2SOImmVal(Value) != -1;
842 bool isT2SOImmNot() const {
843 if (!isImm()) return false;
844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
845 if (!CE) return false;
846 int64_t Value = CE->getValue();
847 return ARM_AM::getT2SOImmVal(~Value) != -1;
849 bool isT2SOImmNeg() const {
850 if (!isImm()) return false;
851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
852 if (!CE) return false;
853 int64_t Value = CE->getValue();
854 // Only use this when not representable as a plain so_imm.
855 return ARM_AM::getT2SOImmVal(Value) == -1 &&
856 ARM_AM::getT2SOImmVal(-Value) != -1;
858 bool isSetEndImm() const {
859 if (!isImm()) return false;
860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
861 if (!CE) return false;
862 int64_t Value = CE->getValue();
863 return Value == 1 || Value == 0;
865 bool isReg() const { return Kind == k_Register; }
866 bool isRegList() const { return Kind == k_RegisterList; }
867 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
868 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
869 bool isToken() const { return Kind == k_Token; }
870 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
871 bool isMem() const { return Kind == k_Memory; }
872 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
873 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
874 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
875 bool isRotImm() const { return Kind == k_RotateImmediate; }
876 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
877 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
878 bool isPostIdxReg() const {
879 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
881 bool isMemNoOffset(bool alignOK = false) const {
884 // No offset of any kind.
885 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
886 (alignOK || Memory.Alignment == 0);
888 bool isMemPCRelImm12() const {
889 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
891 // Base register must be PC.
892 if (Memory.BaseRegNum != ARM::PC)
894 // Immediate offset in range [-4095, 4095].
895 if (!Memory.OffsetImm) return true;
896 int64_t Val = Memory.OffsetImm->getValue();
897 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
899 bool isAlignedMemory() const {
900 return isMemNoOffset(true);
902 bool isAddrMode2() const {
903 if (!isMem() || Memory.Alignment != 0) return false;
904 // Check for register offset.
905 if (Memory.OffsetRegNum) return true;
906 // Immediate offset in range [-4095, 4095].
907 if (!Memory.OffsetImm) return true;
908 int64_t Val = Memory.OffsetImm->getValue();
909 return Val > -4096 && Val < 4096;
911 bool isAM2OffsetImm() const {
912 if (!isImm()) return false;
913 // Immediate offset in range [-4095, 4095].
914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
915 if (!CE) return false;
916 int64_t Val = CE->getValue();
917 return Val > -4096 && Val < 4096;
919 bool isAddrMode3() const {
920 // If we have an immediate that's not a constant, treat it as a label
921 // reference needing a fixup. If it is a constant, it's something else
923 if (isImm() && !isa<MCConstantExpr>(getImm()))
925 if (!isMem() || Memory.Alignment != 0) return false;
926 // No shifts are legal for AM3.
927 if (Memory.ShiftType != ARM_AM::no_shift) return false;
928 // Check for register offset.
929 if (Memory.OffsetRegNum) return true;
930 // Immediate offset in range [-255, 255].
931 if (!Memory.OffsetImm) return true;
932 int64_t Val = Memory.OffsetImm->getValue();
933 // The #-0 offset is encoded as INT32_MIN, and we have to check
935 return (Val > -256 && Val < 256) || Val == INT32_MIN;
937 bool isAM3Offset() const {
938 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
940 if (Kind == k_PostIndexRegister)
941 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
942 // Immediate offset in range [-255, 255].
943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
944 if (!CE) return false;
945 int64_t Val = CE->getValue();
946 // Special case, #-0 is INT32_MIN.
947 return (Val > -256 && Val < 256) || Val == INT32_MIN;
949 bool isAddrMode5() const {
950 // If we have an immediate that's not a constant, treat it as a label
951 // reference needing a fixup. If it is a constant, it's something else
953 if (isImm() && !isa<MCConstantExpr>(getImm()))
955 if (!isMem() || Memory.Alignment != 0) return false;
956 // Check for register offset.
957 if (Memory.OffsetRegNum) return false;
958 // Immediate offset in range [-1020, 1020] and a multiple of 4.
959 if (!Memory.OffsetImm) return true;
960 int64_t Val = Memory.OffsetImm->getValue();
961 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
964 bool isMemTBB() const {
965 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
966 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
970 bool isMemTBH() const {
971 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
972 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
973 Memory.Alignment != 0 )
977 bool isMemRegOffset() const {
978 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
982 bool isT2MemRegOffset() const {
983 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
984 Memory.Alignment != 0)
986 // Only lsl #{0, 1, 2, 3} allowed.
987 if (Memory.ShiftType == ARM_AM::no_shift)
989 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
993 bool isMemThumbRR() const {
994 // Thumb reg+reg addressing is simple. Just two registers, a base and
995 // an offset. No shifts, negations or any other complicating factors.
996 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
997 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
999 return isARMLowRegister(Memory.BaseRegNum) &&
1000 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1002 bool isMemThumbRIs4() const {
1003 if (!isMem() || Memory.OffsetRegNum != 0 ||
1004 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1006 // Immediate offset, multiple of 4 in range [0, 124].
1007 if (!Memory.OffsetImm) return true;
1008 int64_t Val = Memory.OffsetImm->getValue();
1009 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1011 bool isMemThumbRIs2() const {
1012 if (!isMem() || Memory.OffsetRegNum != 0 ||
1013 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1015 // Immediate offset, multiple of 4 in range [0, 62].
1016 if (!Memory.OffsetImm) return true;
1017 int64_t Val = Memory.OffsetImm->getValue();
1018 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1020 bool isMemThumbRIs1() const {
1021 if (!isMem() || Memory.OffsetRegNum != 0 ||
1022 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1024 // Immediate offset in range [0, 31].
1025 if (!Memory.OffsetImm) return true;
1026 int64_t Val = Memory.OffsetImm->getValue();
1027 return Val >= 0 && Val <= 31;
1029 bool isMemThumbSPI() const {
1030 if (!isMem() || Memory.OffsetRegNum != 0 ||
1031 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1033 // Immediate offset, multiple of 4 in range [0, 1020].
1034 if (!Memory.OffsetImm) return true;
1035 int64_t Val = Memory.OffsetImm->getValue();
1036 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1038 bool isMemImm8s4Offset() const {
1039 // If we have an immediate that's not a constant, treat it as a label
1040 // reference needing a fixup. If it is a constant, it's something else
1041 // and we reject it.
1042 if (isImm() && !isa<MCConstantExpr>(getImm()))
1044 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1046 // Immediate offset a multiple of 4 in range [-1020, 1020].
1047 if (!Memory.OffsetImm) return true;
1048 int64_t Val = Memory.OffsetImm->getValue();
1049 // Special case, #-0 is INT32_MIN.
1050 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1052 bool isMemImm0_1020s4Offset() const {
1053 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1055 // Immediate offset a multiple of 4 in range [0, 1020].
1056 if (!Memory.OffsetImm) return true;
1057 int64_t Val = Memory.OffsetImm->getValue();
1058 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1060 bool isMemImm8Offset() const {
1061 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1063 // Base reg of PC isn't allowed for these encodings.
1064 if (Memory.BaseRegNum == ARM::PC) return false;
1065 // Immediate offset in range [-255, 255].
1066 if (!Memory.OffsetImm) return true;
1067 int64_t Val = Memory.OffsetImm->getValue();
1068 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1070 bool isMemPosImm8Offset() const {
1071 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1073 // Immediate offset in range [0, 255].
1074 if (!Memory.OffsetImm) return true;
1075 int64_t Val = Memory.OffsetImm->getValue();
1076 return Val >= 0 && Val < 256;
1078 bool isMemNegImm8Offset() const {
1079 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1081 // Base reg of PC isn't allowed for these encodings.
1082 if (Memory.BaseRegNum == ARM::PC) return false;
1083 // Immediate offset in range [-255, -1].
1084 if (!Memory.OffsetImm) return false;
1085 int64_t Val = Memory.OffsetImm->getValue();
1086 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1088 bool isMemUImm12Offset() const {
1089 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1091 // Immediate offset in range [0, 4095].
1092 if (!Memory.OffsetImm) return true;
1093 int64_t Val = Memory.OffsetImm->getValue();
1094 return (Val >= 0 && Val < 4096);
1096 bool isMemImm12Offset() const {
1097 // If we have an immediate that's not a constant, treat it as a label
1098 // reference needing a fixup. If it is a constant, it's something else
1099 // and we reject it.
1100 if (isImm() && !isa<MCConstantExpr>(getImm()))
1103 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1105 // Immediate offset in range [-4095, 4095].
1106 if (!Memory.OffsetImm) return true;
1107 int64_t Val = Memory.OffsetImm->getValue();
1108 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1110 bool isPostIdxImm8() const {
1111 if (!isImm()) return false;
1112 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1113 if (!CE) return false;
1114 int64_t Val = CE->getValue();
1115 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1117 bool isPostIdxImm8s4() const {
1118 if (!isImm()) return false;
1119 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1120 if (!CE) return false;
1121 int64_t Val = CE->getValue();
1122 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1126 bool isMSRMask() const { return Kind == k_MSRMask; }
1127 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1130 bool isSingleSpacedVectorList() const {
1131 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1133 bool isDoubleSpacedVectorList() const {
1134 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1136 bool isVecListOneD() const {
1137 if (!isSingleSpacedVectorList()) return false;
1138 return VectorList.Count == 1;
1141 bool isVecListDPair() const {
1142 if (!isSingleSpacedVectorList()) return false;
1143 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1144 .contains(VectorList.RegNum));
1147 bool isVecListThreeD() const {
1148 if (!isSingleSpacedVectorList()) return false;
1149 return VectorList.Count == 3;
1152 bool isVecListFourD() const {
1153 if (!isSingleSpacedVectorList()) return false;
1154 return VectorList.Count == 4;
1157 bool isVecListDPairSpaced() const {
1158 if (isSingleSpacedVectorList()) return false;
1159 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1160 .contains(VectorList.RegNum));
1163 bool isVecListThreeQ() const {
1164 if (!isDoubleSpacedVectorList()) return false;
1165 return VectorList.Count == 3;
1168 bool isVecListFourQ() const {
1169 if (!isDoubleSpacedVectorList()) return false;
1170 return VectorList.Count == 4;
1173 bool isSingleSpacedVectorAllLanes() const {
1174 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1176 bool isDoubleSpacedVectorAllLanes() const {
1177 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1179 bool isVecListOneDAllLanes() const {
1180 if (!isSingleSpacedVectorAllLanes()) return false;
1181 return VectorList.Count == 1;
1184 bool isVecListDPairAllLanes() const {
1185 if (!isSingleSpacedVectorAllLanes()) return false;
1186 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1187 .contains(VectorList.RegNum));
1190 bool isVecListDPairSpacedAllLanes() const {
1191 if (!isDoubleSpacedVectorAllLanes()) return false;
1192 return VectorList.Count == 2;
1195 bool isVecListThreeDAllLanes() const {
1196 if (!isSingleSpacedVectorAllLanes()) return false;
1197 return VectorList.Count == 3;
1200 bool isVecListThreeQAllLanes() const {
1201 if (!isDoubleSpacedVectorAllLanes()) return false;
1202 return VectorList.Count == 3;
1205 bool isVecListFourDAllLanes() const {
1206 if (!isSingleSpacedVectorAllLanes()) return false;
1207 return VectorList.Count == 4;
1210 bool isVecListFourQAllLanes() const {
1211 if (!isDoubleSpacedVectorAllLanes()) return false;
1212 return VectorList.Count == 4;
1215 bool isSingleSpacedVectorIndexed() const {
1216 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1218 bool isDoubleSpacedVectorIndexed() const {
1219 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1221 bool isVecListOneDByteIndexed() const {
1222 if (!isSingleSpacedVectorIndexed()) return false;
1223 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1226 bool isVecListOneDHWordIndexed() const {
1227 if (!isSingleSpacedVectorIndexed()) return false;
1228 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1231 bool isVecListOneDWordIndexed() const {
1232 if (!isSingleSpacedVectorIndexed()) return false;
1233 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1236 bool isVecListTwoDByteIndexed() const {
1237 if (!isSingleSpacedVectorIndexed()) return false;
1238 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1241 bool isVecListTwoDHWordIndexed() const {
1242 if (!isSingleSpacedVectorIndexed()) return false;
1243 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1246 bool isVecListTwoQWordIndexed() const {
1247 if (!isDoubleSpacedVectorIndexed()) return false;
1248 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1251 bool isVecListTwoQHWordIndexed() const {
1252 if (!isDoubleSpacedVectorIndexed()) return false;
1253 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1256 bool isVecListTwoDWordIndexed() const {
1257 if (!isSingleSpacedVectorIndexed()) return false;
1258 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1261 bool isVecListThreeDByteIndexed() const {
1262 if (!isSingleSpacedVectorIndexed()) return false;
1263 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1266 bool isVecListThreeDHWordIndexed() const {
1267 if (!isSingleSpacedVectorIndexed()) return false;
1268 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1271 bool isVecListThreeQWordIndexed() const {
1272 if (!isDoubleSpacedVectorIndexed()) return false;
1273 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1276 bool isVecListThreeQHWordIndexed() const {
1277 if (!isDoubleSpacedVectorIndexed()) return false;
1278 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1281 bool isVecListThreeDWordIndexed() const {
1282 if (!isSingleSpacedVectorIndexed()) return false;
1283 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1286 bool isVecListFourDByteIndexed() const {
1287 if (!isSingleSpacedVectorIndexed()) return false;
1288 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1291 bool isVecListFourDHWordIndexed() const {
1292 if (!isSingleSpacedVectorIndexed()) return false;
1293 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1296 bool isVecListFourQWordIndexed() const {
1297 if (!isDoubleSpacedVectorIndexed()) return false;
1298 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1301 bool isVecListFourQHWordIndexed() const {
1302 if (!isDoubleSpacedVectorIndexed()) return false;
1303 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1306 bool isVecListFourDWordIndexed() const {
1307 if (!isSingleSpacedVectorIndexed()) return false;
1308 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1311 bool isVectorIndex8() const {
1312 if (Kind != k_VectorIndex) return false;
1313 return VectorIndex.Val < 8;
1315 bool isVectorIndex16() const {
1316 if (Kind != k_VectorIndex) return false;
1317 return VectorIndex.Val < 4;
1319 bool isVectorIndex32() const {
1320 if (Kind != k_VectorIndex) return false;
1321 return VectorIndex.Val < 2;
1324 bool isNEONi8splat() const {
1325 if (!isImm()) return false;
1326 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1327 // Must be a constant.
1328 if (!CE) return false;
1329 int64_t Value = CE->getValue();
1330 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1332 return Value >= 0 && Value < 256;
1335 bool isNEONi16splat() const {
1336 if (!isImm()) return false;
1337 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1338 // Must be a constant.
1339 if (!CE) return false;
1340 int64_t Value = CE->getValue();
1341 // i16 value in the range [0,255] or [0x0100, 0xff00]
1342 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1345 bool isNEONi32splat() const {
1346 if (!isImm()) return false;
1347 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1348 // Must be a constant.
1349 if (!CE) return false;
1350 int64_t Value = CE->getValue();
1351 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1352 return (Value >= 0 && Value < 256) ||
1353 (Value >= 0x0100 && Value <= 0xff00) ||
1354 (Value >= 0x010000 && Value <= 0xff0000) ||
1355 (Value >= 0x01000000 && Value <= 0xff000000);
1358 bool isNEONi32vmov() const {
1359 if (!isImm()) return false;
1360 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1361 // Must be a constant.
1362 if (!CE) return false;
1363 int64_t Value = CE->getValue();
1364 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1365 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1366 return (Value >= 0 && Value < 256) ||
1367 (Value >= 0x0100 && Value <= 0xff00) ||
1368 (Value >= 0x010000 && Value <= 0xff0000) ||
1369 (Value >= 0x01000000 && Value <= 0xff000000) ||
1370 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1371 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1373 bool isNEONi32vmovNeg() const {
1374 if (!isImm()) return false;
1375 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1376 // Must be a constant.
1377 if (!CE) return false;
1378 int64_t Value = ~CE->getValue();
1379 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1380 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1381 return (Value >= 0 && Value < 256) ||
1382 (Value >= 0x0100 && Value <= 0xff00) ||
1383 (Value >= 0x010000 && Value <= 0xff0000) ||
1384 (Value >= 0x01000000 && Value <= 0xff000000) ||
1385 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1386 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1389 bool isNEONi64splat() const {
1390 if (!isImm()) return false;
1391 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1392 // Must be a constant.
1393 if (!CE) return false;
1394 uint64_t Value = CE->getValue();
1395 // i64 value with each byte being either 0 or 0xff.
1396 for (unsigned i = 0; i < 8; ++i)
1397 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1401 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1402 // Add as immediates when possible. Null MCExpr = 0.
1404 Inst.addOperand(MCOperand::CreateImm(0));
1405 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1406 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1408 Inst.addOperand(MCOperand::CreateExpr(Expr));
1411 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1412 assert(N == 2 && "Invalid number of operands!");
1413 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1414 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1415 Inst.addOperand(MCOperand::CreateReg(RegNum));
1418 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1419 assert(N == 1 && "Invalid number of operands!");
1420 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1423 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1424 assert(N == 1 && "Invalid number of operands!");
1425 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1428 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1429 assert(N == 1 && "Invalid number of operands!");
1430 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1433 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1434 assert(N == 1 && "Invalid number of operands!");
1435 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1438 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1439 assert(N == 1 && "Invalid number of operands!");
1440 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1443 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1444 assert(N == 1 && "Invalid number of operands!");
1445 Inst.addOperand(MCOperand::CreateReg(getReg()));
1448 void addRegOperands(MCInst &Inst, unsigned N) const {
1449 assert(N == 1 && "Invalid number of operands!");
1450 Inst.addOperand(MCOperand::CreateReg(getReg()));
1453 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1454 assert(N == 3 && "Invalid number of operands!");
1455 assert(isRegShiftedReg() &&
1456 "addRegShiftedRegOperands() on non RegShiftedReg!");
1457 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1458 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1459 Inst.addOperand(MCOperand::CreateImm(
1460 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1463 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1464 assert(N == 2 && "Invalid number of operands!");
1465 assert(isRegShiftedImm() &&
1466 "addRegShiftedImmOperands() on non RegShiftedImm!");
1467 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1468 // Shift of #32 is encoded as 0 where permitted
1469 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1470 Inst.addOperand(MCOperand::CreateImm(
1471 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1474 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1475 assert(N == 1 && "Invalid number of operands!");
1476 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1480 void addRegListOperands(MCInst &Inst, unsigned N) const {
1481 assert(N == 1 && "Invalid number of operands!");
1482 const SmallVectorImpl<unsigned> &RegList = getRegList();
1483 for (SmallVectorImpl<unsigned>::const_iterator
1484 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1485 Inst.addOperand(MCOperand::CreateReg(*I));
1488 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1489 addRegListOperands(Inst, N);
1492 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1493 addRegListOperands(Inst, N);
1496 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1497 assert(N == 1 && "Invalid number of operands!");
1498 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1499 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1502 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1503 assert(N == 1 && "Invalid number of operands!");
1504 // Munge the lsb/width into a bitfield mask.
1505 unsigned lsb = Bitfield.LSB;
1506 unsigned width = Bitfield.Width;
1507 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1508 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1509 (32 - (lsb + width)));
1510 Inst.addOperand(MCOperand::CreateImm(Mask));
1513 void addImmOperands(MCInst &Inst, unsigned N) const {
1514 assert(N == 1 && "Invalid number of operands!");
1515 addExpr(Inst, getImm());
1518 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1519 assert(N == 1 && "Invalid number of operands!");
1520 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1521 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1524 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1525 assert(N == 1 && "Invalid number of operands!");
1526 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1527 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1530 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1531 assert(N == 1 && "Invalid number of operands!");
1532 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1533 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1534 Inst.addOperand(MCOperand::CreateImm(Val));
1537 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1538 assert(N == 1 && "Invalid number of operands!");
1539 // FIXME: We really want to scale the value here, but the LDRD/STRD
1540 // instruction don't encode operands that way yet.
1541 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1542 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1545 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1546 assert(N == 1 && "Invalid number of operands!");
1547 // The immediate is scaled by four in the encoding and is stored
1548 // in the MCInst as such. Lop off the low two bits here.
1549 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1550 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1553 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 // The immediate is scaled by four in the encoding and is stored
1556 // in the MCInst as such. Lop off the low two bits here.
1557 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1558 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1561 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1562 assert(N == 1 && "Invalid number of operands!");
1563 // The immediate is scaled by four in the encoding and is stored
1564 // in the MCInst as such. Lop off the low two bits here.
1565 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1566 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1569 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1570 assert(N == 1 && "Invalid number of operands!");
1571 // The constant encodes as the immediate-1, and we store in the instruction
1572 // the bits as encoded, so subtract off one here.
1573 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1574 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1577 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1578 assert(N == 1 && "Invalid number of operands!");
1579 // The constant encodes as the immediate-1, and we store in the instruction
1580 // the bits as encoded, so subtract off one here.
1581 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1582 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1585 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1586 assert(N == 1 && "Invalid number of operands!");
1587 // The constant encodes as the immediate, except for 32, which encodes as
1589 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1590 unsigned Imm = CE->getValue();
1591 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1594 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1595 assert(N == 1 && "Invalid number of operands!");
1596 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1597 // the instruction as well.
1598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1599 int Val = CE->getValue();
1600 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1603 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1604 assert(N == 1 && "Invalid number of operands!");
1605 // The operand is actually a t2_so_imm, but we have its bitwise
1606 // negation in the assembly source, so twiddle it here.
1607 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1608 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1611 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1612 assert(N == 1 && "Invalid number of operands!");
1613 // The operand is actually a t2_so_imm, but we have its
1614 // negation in the assembly source, so twiddle it here.
1615 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1616 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1619 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1620 assert(N == 1 && "Invalid number of operands!");
1621 // The operand is actually an imm0_4095, but we have its
1622 // negation in the assembly source, so twiddle it here.
1623 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1624 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1627 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1628 assert(N == 1 && "Invalid number of operands!");
1629 // The operand is actually a so_imm, but we have its bitwise
1630 // negation in the assembly source, so twiddle it here.
1631 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1632 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1635 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1636 assert(N == 1 && "Invalid number of operands!");
1637 // The operand is actually a so_imm, but we have its
1638 // negation in the assembly source, so twiddle it here.
1639 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1640 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1643 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1644 assert(N == 1 && "Invalid number of operands!");
1645 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1648 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1649 assert(N == 1 && "Invalid number of operands!");
1650 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1653 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1654 assert(N == 1 && "Invalid number of operands!");
1655 int32_t Imm = Memory.OffsetImm->getValue();
1656 // FIXME: Handle #-0
1657 if (Imm == INT32_MIN) Imm = 0;
1658 Inst.addOperand(MCOperand::CreateImm(Imm));
1661 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1662 assert(N == 1 && "Invalid number of operands!");
1663 assert(isImm() && "Not an immediate!");
1665 // If we have an immediate that's not a constant, treat it as a label
1666 // reference needing a fixup.
1667 if (!isa<MCConstantExpr>(getImm())) {
1668 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1673 int Val = CE->getValue();
1674 Inst.addOperand(MCOperand::CreateImm(Val));
1677 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1678 assert(N == 2 && "Invalid number of operands!");
1679 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1680 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1683 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1684 assert(N == 3 && "Invalid number of operands!");
1685 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1686 if (!Memory.OffsetRegNum) {
1687 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1688 // Special case for #-0
1689 if (Val == INT32_MIN) Val = 0;
1690 if (Val < 0) Val = -Val;
1691 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1693 // For register offset, we encode the shift type and negation flag
1695 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1696 Memory.ShiftImm, Memory.ShiftType);
1698 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1699 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1700 Inst.addOperand(MCOperand::CreateImm(Val));
1703 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1704 assert(N == 2 && "Invalid number of operands!");
1705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1706 assert(CE && "non-constant AM2OffsetImm operand!");
1707 int32_t Val = CE->getValue();
1708 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1709 // Special case for #-0
1710 if (Val == INT32_MIN) Val = 0;
1711 if (Val < 0) Val = -Val;
1712 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1713 Inst.addOperand(MCOperand::CreateReg(0));
1714 Inst.addOperand(MCOperand::CreateImm(Val));
1717 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1718 assert(N == 3 && "Invalid number of operands!");
1719 // If we have an immediate that's not a constant, treat it as a label
1720 // reference needing a fixup. If it is a constant, it's something else
1721 // and we reject it.
1723 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1724 Inst.addOperand(MCOperand::CreateReg(0));
1725 Inst.addOperand(MCOperand::CreateImm(0));
1729 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1730 if (!Memory.OffsetRegNum) {
1731 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1732 // Special case for #-0
1733 if (Val == INT32_MIN) Val = 0;
1734 if (Val < 0) Val = -Val;
1735 Val = ARM_AM::getAM3Opc(AddSub, Val);
1737 // For register offset, we encode the shift type and negation flag
1739 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1741 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1742 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1743 Inst.addOperand(MCOperand::CreateImm(Val));
1746 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1747 assert(N == 2 && "Invalid number of operands!");
1748 if (Kind == k_PostIndexRegister) {
1750 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1751 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1752 Inst.addOperand(MCOperand::CreateImm(Val));
1757 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1758 int32_t Val = CE->getValue();
1759 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1760 // Special case for #-0
1761 if (Val == INT32_MIN) Val = 0;
1762 if (Val < 0) Val = -Val;
1763 Val = ARM_AM::getAM3Opc(AddSub, Val);
1764 Inst.addOperand(MCOperand::CreateReg(0));
1765 Inst.addOperand(MCOperand::CreateImm(Val));
1768 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1769 assert(N == 2 && "Invalid number of operands!");
1770 // If we have an immediate that's not a constant, treat it as a label
1771 // reference needing a fixup. If it is a constant, it's something else
1772 // and we reject it.
1774 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1775 Inst.addOperand(MCOperand::CreateImm(0));
1779 // The lower two bits are always zero and as such are not encoded.
1780 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1781 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1782 // Special case for #-0
1783 if (Val == INT32_MIN) Val = 0;
1784 if (Val < 0) Val = -Val;
1785 Val = ARM_AM::getAM5Opc(AddSub, Val);
1786 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1787 Inst.addOperand(MCOperand::CreateImm(Val));
1790 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1791 assert(N == 2 && "Invalid number of operands!");
1792 // If we have an immediate that's not a constant, treat it as a label
1793 // reference needing a fixup. If it is a constant, it's something else
1794 // and we reject it.
1796 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1797 Inst.addOperand(MCOperand::CreateImm(0));
1801 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1802 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1803 Inst.addOperand(MCOperand::CreateImm(Val));
1806 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1807 assert(N == 2 && "Invalid number of operands!");
1808 // The lower two bits are always zero and as such are not encoded.
1809 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1810 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1811 Inst.addOperand(MCOperand::CreateImm(Val));
1814 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1815 assert(N == 2 && "Invalid number of operands!");
1816 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1817 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1818 Inst.addOperand(MCOperand::CreateImm(Val));
1821 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1822 addMemImm8OffsetOperands(Inst, N);
1825 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1826 addMemImm8OffsetOperands(Inst, N);
1829 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1830 assert(N == 2 && "Invalid number of operands!");
1831 // If this is an immediate, it's a label reference.
1833 addExpr(Inst, getImm());
1834 Inst.addOperand(MCOperand::CreateImm(0));
1838 // Otherwise, it's a normal memory reg+offset.
1839 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1840 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1841 Inst.addOperand(MCOperand::CreateImm(Val));
1844 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1845 assert(N == 2 && "Invalid number of operands!");
1846 // If this is an immediate, it's a label reference.
1848 addExpr(Inst, getImm());
1849 Inst.addOperand(MCOperand::CreateImm(0));
1853 // Otherwise, it's a normal memory reg+offset.
1854 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1855 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1856 Inst.addOperand(MCOperand::CreateImm(Val));
1859 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1860 assert(N == 2 && "Invalid number of operands!");
1861 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1862 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1865 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1866 assert(N == 2 && "Invalid number of operands!");
1867 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1868 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1871 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1872 assert(N == 3 && "Invalid number of operands!");
1874 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1875 Memory.ShiftImm, Memory.ShiftType);
1876 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1877 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1878 Inst.addOperand(MCOperand::CreateImm(Val));
1881 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1882 assert(N == 3 && "Invalid number of operands!");
1883 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1884 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1885 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
1888 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1889 assert(N == 2 && "Invalid number of operands!");
1890 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1891 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1894 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1895 assert(N == 2 && "Invalid number of operands!");
1896 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1897 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1898 Inst.addOperand(MCOperand::CreateImm(Val));
1901 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1902 assert(N == 2 && "Invalid number of operands!");
1903 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1904 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1905 Inst.addOperand(MCOperand::CreateImm(Val));
1908 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1909 assert(N == 2 && "Invalid number of operands!");
1910 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1911 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1912 Inst.addOperand(MCOperand::CreateImm(Val));
1915 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1916 assert(N == 2 && "Invalid number of operands!");
1917 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1918 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1919 Inst.addOperand(MCOperand::CreateImm(Val));
1922 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1923 assert(N == 1 && "Invalid number of operands!");
1924 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1925 assert(CE && "non-constant post-idx-imm8 operand!");
1926 int Imm = CE->getValue();
1927 bool isAdd = Imm >= 0;
1928 if (Imm == INT32_MIN) Imm = 0;
1929 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1930 Inst.addOperand(MCOperand::CreateImm(Imm));
1933 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1934 assert(N == 1 && "Invalid number of operands!");
1935 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1936 assert(CE && "non-constant post-idx-imm8s4 operand!");
1937 int Imm = CE->getValue();
1938 bool isAdd = Imm >= 0;
1939 if (Imm == INT32_MIN) Imm = 0;
1940 // Immediate is scaled by 4.
1941 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1942 Inst.addOperand(MCOperand::CreateImm(Imm));
1945 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1946 assert(N == 2 && "Invalid number of operands!");
1947 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1948 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1951 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1952 assert(N == 2 && "Invalid number of operands!");
1953 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1954 // The sign, shift type, and shift amount are encoded in a single operand
1955 // using the AM2 encoding helpers.
1956 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1957 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1958 PostIdxReg.ShiftTy);
1959 Inst.addOperand(MCOperand::CreateImm(Imm));
1962 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1963 assert(N == 1 && "Invalid number of operands!");
1964 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1967 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1968 assert(N == 1 && "Invalid number of operands!");
1969 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1972 void addVecListOperands(MCInst &Inst, unsigned N) const {
1973 assert(N == 1 && "Invalid number of operands!");
1974 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1977 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1978 assert(N == 2 && "Invalid number of operands!");
1979 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1980 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1983 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1984 assert(N == 1 && "Invalid number of operands!");
1985 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1988 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1989 assert(N == 1 && "Invalid number of operands!");
1990 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1993 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1994 assert(N == 1 && "Invalid number of operands!");
1995 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1998 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1999 assert(N == 1 && "Invalid number of operands!");
2000 // The immediate encodes the type of constant as well as the value.
2001 // Mask in that this is an i8 splat.
2002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2003 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2006 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2007 assert(N == 1 && "Invalid number of operands!");
2008 // The immediate encodes the type of constant as well as the value.
2009 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2010 unsigned Value = CE->getValue();
2012 Value = (Value >> 8) | 0xa00;
2015 Inst.addOperand(MCOperand::CreateImm(Value));
2018 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2019 assert(N == 1 && "Invalid number of operands!");
2020 // The immediate encodes the type of constant as well as the value.
2021 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2022 unsigned Value = CE->getValue();
2023 if (Value >= 256 && Value <= 0xff00)
2024 Value = (Value >> 8) | 0x200;
2025 else if (Value > 0xffff && Value <= 0xff0000)
2026 Value = (Value >> 16) | 0x400;
2027 else if (Value > 0xffffff)
2028 Value = (Value >> 24) | 0x600;
2029 Inst.addOperand(MCOperand::CreateImm(Value));
2032 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2033 assert(N == 1 && "Invalid number of operands!");
2034 // The immediate encodes the type of constant as well as the value.
2035 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2036 unsigned Value = CE->getValue();
2037 if (Value >= 256 && Value <= 0xffff)
2038 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2039 else if (Value > 0xffff && Value <= 0xffffff)
2040 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2041 else if (Value > 0xffffff)
2042 Value = (Value >> 24) | 0x600;
2043 Inst.addOperand(MCOperand::CreateImm(Value));
2046 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2047 assert(N == 1 && "Invalid number of operands!");
2048 // The immediate encodes the type of constant as well as the value.
2049 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2050 unsigned Value = ~CE->getValue();
2051 if (Value >= 256 && Value <= 0xffff)
2052 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2053 else if (Value > 0xffff && Value <= 0xffffff)
2054 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2055 else if (Value > 0xffffff)
2056 Value = (Value >> 24) | 0x600;
2057 Inst.addOperand(MCOperand::CreateImm(Value));
2060 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2061 assert(N == 1 && "Invalid number of operands!");
2062 // The immediate encodes the type of constant as well as the value.
2063 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2064 uint64_t Value = CE->getValue();
2066 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2067 Imm |= (Value & 1) << i;
2069 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2072 virtual void print(raw_ostream &OS) const;
2074 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2075 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2076 Op->ITMask.Mask = Mask;
2082 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2083 ARMOperand *Op = new ARMOperand(k_CondCode);
2090 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2091 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2092 Op->Cop.Val = CopVal;
2098 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2099 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2100 Op->Cop.Val = CopVal;
2106 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2107 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2114 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2115 ARMOperand *Op = new ARMOperand(k_CCOut);
2116 Op->Reg.RegNum = RegNum;
2122 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2123 ARMOperand *Op = new ARMOperand(k_Token);
2124 Op->Tok.Data = Str.data();
2125 Op->Tok.Length = Str.size();
2131 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2132 ARMOperand *Op = new ARMOperand(k_Register);
2133 Op->Reg.RegNum = RegNum;
2139 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2144 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2145 Op->RegShiftedReg.ShiftTy = ShTy;
2146 Op->RegShiftedReg.SrcReg = SrcReg;
2147 Op->RegShiftedReg.ShiftReg = ShiftReg;
2148 Op->RegShiftedReg.ShiftImm = ShiftImm;
2154 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2158 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2159 Op->RegShiftedImm.ShiftTy = ShTy;
2160 Op->RegShiftedImm.SrcReg = SrcReg;
2161 Op->RegShiftedImm.ShiftImm = ShiftImm;
2167 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2169 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2170 Op->ShifterImm.isASR = isASR;
2171 Op->ShifterImm.Imm = Imm;
2177 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2178 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2179 Op->RotImm.Imm = Imm;
2185 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2187 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2188 Op->Bitfield.LSB = LSB;
2189 Op->Bitfield.Width = Width;
2196 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
2197 SMLoc StartLoc, SMLoc EndLoc) {
2198 KindTy Kind = k_RegisterList;
2200 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
2201 Kind = k_DPRRegisterList;
2202 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2203 contains(Regs.front().first))
2204 Kind = k_SPRRegisterList;
2206 ARMOperand *Op = new ARMOperand(Kind);
2207 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
2208 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2209 Op->Registers.push_back(I->first);
2210 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
2211 Op->StartLoc = StartLoc;
2212 Op->EndLoc = EndLoc;
2216 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2217 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2218 ARMOperand *Op = new ARMOperand(k_VectorList);
2219 Op->VectorList.RegNum = RegNum;
2220 Op->VectorList.Count = Count;
2221 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2227 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2228 bool isDoubleSpaced,
2230 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2231 Op->VectorList.RegNum = RegNum;
2232 Op->VectorList.Count = Count;
2233 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2239 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2241 bool isDoubleSpaced,
2243 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2244 Op->VectorList.RegNum = RegNum;
2245 Op->VectorList.Count = Count;
2246 Op->VectorList.LaneIndex = Index;
2247 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2253 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2255 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2256 Op->VectorIndex.Val = Idx;
2262 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2263 ARMOperand *Op = new ARMOperand(k_Immediate);
2270 static ARMOperand *CreateMem(unsigned BaseRegNum,
2271 const MCConstantExpr *OffsetImm,
2272 unsigned OffsetRegNum,
2273 ARM_AM::ShiftOpc ShiftType,
2278 ARMOperand *Op = new ARMOperand(k_Memory);
2279 Op->Memory.BaseRegNum = BaseRegNum;
2280 Op->Memory.OffsetImm = OffsetImm;
2281 Op->Memory.OffsetRegNum = OffsetRegNum;
2282 Op->Memory.ShiftType = ShiftType;
2283 Op->Memory.ShiftImm = ShiftImm;
2284 Op->Memory.Alignment = Alignment;
2285 Op->Memory.isNegative = isNegative;
2291 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2292 ARM_AM::ShiftOpc ShiftTy,
2295 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2296 Op->PostIdxReg.RegNum = RegNum;
2297 Op->PostIdxReg.isAdd = isAdd;
2298 Op->PostIdxReg.ShiftTy = ShiftTy;
2299 Op->PostIdxReg.ShiftImm = ShiftImm;
2305 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2306 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2307 Op->MBOpt.Val = Opt;
2313 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2314 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2315 Op->IFlags.Val = IFlags;
2321 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2322 ARMOperand *Op = new ARMOperand(k_MSRMask);
2323 Op->MMask.Val = MMask;
2330 } // end anonymous namespace.
2332 void ARMOperand::print(raw_ostream &OS) const {
2335 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2338 OS << "<ccout " << getReg() << ">";
2340 case k_ITCondMask: {
2341 static const char *const MaskStr[] = {
2342 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2343 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2345 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2346 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2350 OS << "<coprocessor number: " << getCoproc() << ">";
2353 OS << "<coprocessor register: " << getCoproc() << ">";
2355 case k_CoprocOption:
2356 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2359 OS << "<mask: " << getMSRMask() << ">";
2362 getImm()->print(OS);
2364 case k_MemBarrierOpt:
2365 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2369 << " base:" << Memory.BaseRegNum;
2372 case k_PostIndexRegister:
2373 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2374 << PostIdxReg.RegNum;
2375 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2376 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2377 << PostIdxReg.ShiftImm;
2380 case k_ProcIFlags: {
2381 OS << "<ARM_PROC::";
2382 unsigned IFlags = getProcIFlags();
2383 for (int i=2; i >= 0; --i)
2384 if (IFlags & (1 << i))
2385 OS << ARM_PROC::IFlagsToString(1 << i);
2390 OS << "<register " << getReg() << ">";
2392 case k_ShifterImmediate:
2393 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2394 << " #" << ShifterImm.Imm << ">";
2396 case k_ShiftedRegister:
2397 OS << "<so_reg_reg "
2398 << RegShiftedReg.SrcReg << " "
2399 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2400 << " " << RegShiftedReg.ShiftReg << ">";
2402 case k_ShiftedImmediate:
2403 OS << "<so_reg_imm "
2404 << RegShiftedImm.SrcReg << " "
2405 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2406 << " #" << RegShiftedImm.ShiftImm << ">";
2408 case k_RotateImmediate:
2409 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2411 case k_BitfieldDescriptor:
2412 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2413 << ", width: " << Bitfield.Width << ">";
2415 case k_RegisterList:
2416 case k_DPRRegisterList:
2417 case k_SPRRegisterList: {
2418 OS << "<register_list ";
2420 const SmallVectorImpl<unsigned> &RegList = getRegList();
2421 for (SmallVectorImpl<unsigned>::const_iterator
2422 I = RegList.begin(), E = RegList.end(); I != E; ) {
2424 if (++I < E) OS << ", ";
2431 OS << "<vector_list " << VectorList.Count << " * "
2432 << VectorList.RegNum << ">";
2434 case k_VectorListAllLanes:
2435 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2436 << VectorList.RegNum << ">";
2438 case k_VectorListIndexed:
2439 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2440 << VectorList.Count << " * " << VectorList.RegNum << ">";
2443 OS << "'" << getToken() << "'";
2446 OS << "<vectorindex " << getVectorIndex() << ">";
2451 /// @name Auto-generated Match Functions
2454 static unsigned MatchRegisterName(StringRef Name);
2458 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2459 SMLoc &StartLoc, SMLoc &EndLoc) {
2460 StartLoc = Parser.getTok().getLoc();
2461 RegNo = tryParseRegister();
2462 EndLoc = Parser.getTok().getLoc();
2464 return (RegNo == (unsigned)-1);
2467 /// Try to parse a register name. The token must be an Identifier when called,
2468 /// and if it is a register name the token is eaten and the register number is
2469 /// returned. Otherwise return -1.
2471 int ARMAsmParser::tryParseRegister() {
2472 const AsmToken &Tok = Parser.getTok();
2473 if (Tok.isNot(AsmToken::Identifier)) return -1;
2475 std::string lowerCase = Tok.getString().lower();
2476 unsigned RegNum = MatchRegisterName(lowerCase);
2478 RegNum = StringSwitch<unsigned>(lowerCase)
2479 .Case("r13", ARM::SP)
2480 .Case("r14", ARM::LR)
2481 .Case("r15", ARM::PC)
2482 .Case("ip", ARM::R12)
2483 // Additional register name aliases for 'gas' compatibility.
2484 .Case("a1", ARM::R0)
2485 .Case("a2", ARM::R1)
2486 .Case("a3", ARM::R2)
2487 .Case("a4", ARM::R3)
2488 .Case("v1", ARM::R4)
2489 .Case("v2", ARM::R5)
2490 .Case("v3", ARM::R6)
2491 .Case("v4", ARM::R7)
2492 .Case("v5", ARM::R8)
2493 .Case("v6", ARM::R9)
2494 .Case("v7", ARM::R10)
2495 .Case("v8", ARM::R11)
2496 .Case("sb", ARM::R9)
2497 .Case("sl", ARM::R10)
2498 .Case("fp", ARM::R11)
2502 // Check for aliases registered via .req. Canonicalize to lower case.
2503 // That's more consistent since register names are case insensitive, and
2504 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2505 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2506 // If no match, return failure.
2507 if (Entry == RegisterReqs.end())
2509 Parser.Lex(); // Eat identifier token.
2510 return Entry->getValue();
2513 Parser.Lex(); // Eat identifier token.
2518 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2519 // If a recoverable error occurs, return 1. If an irrecoverable error
2520 // occurs, return -1. An irrecoverable error is one where tokens have been
2521 // consumed in the process of trying to parse the shifter (i.e., when it is
2522 // indeed a shifter operand, but malformed).
2523 int ARMAsmParser::tryParseShiftRegister(
2524 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2525 SMLoc S = Parser.getTok().getLoc();
2526 const AsmToken &Tok = Parser.getTok();
2527 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2529 std::string lowerCase = Tok.getString().lower();
2530 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2531 .Case("asl", ARM_AM::lsl)
2532 .Case("lsl", ARM_AM::lsl)
2533 .Case("lsr", ARM_AM::lsr)
2534 .Case("asr", ARM_AM::asr)
2535 .Case("ror", ARM_AM::ror)
2536 .Case("rrx", ARM_AM::rrx)
2537 .Default(ARM_AM::no_shift);
2539 if (ShiftTy == ARM_AM::no_shift)
2542 Parser.Lex(); // Eat the operator.
2544 // The source register for the shift has already been added to the
2545 // operand list, so we need to pop it off and combine it into the shifted
2546 // register operand instead.
2547 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2548 if (!PrevOp->isReg())
2549 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2550 int SrcReg = PrevOp->getReg();
2553 if (ShiftTy == ARM_AM::rrx) {
2554 // RRX Doesn't have an explicit shift amount. The encoder expects
2555 // the shift register to be the same as the source register. Seems odd,
2559 // Figure out if this is shifted by a constant or a register (for non-RRX).
2560 if (Parser.getTok().is(AsmToken::Hash) ||
2561 Parser.getTok().is(AsmToken::Dollar)) {
2562 Parser.Lex(); // Eat hash.
2563 SMLoc ImmLoc = Parser.getTok().getLoc();
2564 const MCExpr *ShiftExpr = 0;
2565 if (getParser().ParseExpression(ShiftExpr)) {
2566 Error(ImmLoc, "invalid immediate shift value");
2569 // The expression must be evaluatable as an immediate.
2570 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2572 Error(ImmLoc, "invalid immediate shift value");
2575 // Range check the immediate.
2576 // lsl, ror: 0 <= imm <= 31
2577 // lsr, asr: 0 <= imm <= 32
2578 Imm = CE->getValue();
2580 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2581 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2582 Error(ImmLoc, "immediate shift value out of range");
2585 // shift by zero is a nop. Always send it through as lsl.
2586 // ('as' compatibility)
2588 ShiftTy = ARM_AM::lsl;
2589 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2590 ShiftReg = tryParseRegister();
2591 SMLoc L = Parser.getTok().getLoc();
2592 if (ShiftReg == -1) {
2593 Error (L, "expected immediate or register in shift operand");
2597 Error (Parser.getTok().getLoc(),
2598 "expected immediate or register in shift operand");
2603 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2604 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2606 S, Parser.getTok().getLoc()));
2608 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2609 S, Parser.getTok().getLoc()));
2615 /// Try to parse a register name. The token must be an Identifier when called.
2616 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2617 /// if there is a "writeback". 'true' if it's not a register.
2619 /// TODO this is likely to change to allow different register types and or to
2620 /// parse for a specific register type.
2622 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2623 SMLoc S = Parser.getTok().getLoc();
2624 int RegNo = tryParseRegister();
2628 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
2630 const AsmToken &ExclaimTok = Parser.getTok();
2631 if (ExclaimTok.is(AsmToken::Exclaim)) {
2632 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2633 ExclaimTok.getLoc()));
2634 Parser.Lex(); // Eat exclaim token
2638 // Also check for an index operand. This is only legal for vector registers,
2639 // but that'll get caught OK in operand matching, so we don't need to
2640 // explicitly filter everything else out here.
2641 if (Parser.getTok().is(AsmToken::LBrac)) {
2642 SMLoc SIdx = Parser.getTok().getLoc();
2643 Parser.Lex(); // Eat left bracket token.
2645 const MCExpr *ImmVal;
2646 if (getParser().ParseExpression(ImmVal))
2648 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2650 return TokError("immediate value expected for vector index");
2652 SMLoc E = Parser.getTok().getLoc();
2653 if (Parser.getTok().isNot(AsmToken::RBrac))
2654 return Error(E, "']' expected");
2656 Parser.Lex(); // Eat right bracket token.
2658 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2666 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2667 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2669 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2670 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2672 switch (Name.size()) {
2675 if (Name[0] != CoprocOp)
2691 if (Name[0] != CoprocOp || Name[1] != '1')
2695 case '0': return 10;
2696 case '1': return 11;
2697 case '2': return 12;
2698 case '3': return 13;
2699 case '4': return 14;
2700 case '5': return 15;
2705 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2706 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2707 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2708 SMLoc S = Parser.getTok().getLoc();
2709 const AsmToken &Tok = Parser.getTok();
2710 if (!Tok.is(AsmToken::Identifier))
2711 return MatchOperand_NoMatch;
2712 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2713 .Case("eq", ARMCC::EQ)
2714 .Case("ne", ARMCC::NE)
2715 .Case("hs", ARMCC::HS)
2716 .Case("cs", ARMCC::HS)
2717 .Case("lo", ARMCC::LO)
2718 .Case("cc", ARMCC::LO)
2719 .Case("mi", ARMCC::MI)
2720 .Case("pl", ARMCC::PL)
2721 .Case("vs", ARMCC::VS)
2722 .Case("vc", ARMCC::VC)
2723 .Case("hi", ARMCC::HI)
2724 .Case("ls", ARMCC::LS)
2725 .Case("ge", ARMCC::GE)
2726 .Case("lt", ARMCC::LT)
2727 .Case("gt", ARMCC::GT)
2728 .Case("le", ARMCC::LE)
2729 .Case("al", ARMCC::AL)
2732 return MatchOperand_NoMatch;
2733 Parser.Lex(); // Eat the token.
2735 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2737 return MatchOperand_Success;
2740 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2741 /// token must be an Identifier when called, and if it is a coprocessor
2742 /// number, the token is eaten and the operand is added to the operand list.
2743 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2744 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2745 SMLoc S = Parser.getTok().getLoc();
2746 const AsmToken &Tok = Parser.getTok();
2747 if (Tok.isNot(AsmToken::Identifier))
2748 return MatchOperand_NoMatch;
2750 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2752 return MatchOperand_NoMatch;
2754 Parser.Lex(); // Eat identifier token.
2755 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2756 return MatchOperand_Success;
2759 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2760 /// token must be an Identifier when called, and if it is a coprocessor
2761 /// number, the token is eaten and the operand is added to the operand list.
2762 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2763 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2764 SMLoc S = Parser.getTok().getLoc();
2765 const AsmToken &Tok = Parser.getTok();
2766 if (Tok.isNot(AsmToken::Identifier))
2767 return MatchOperand_NoMatch;
2769 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2771 return MatchOperand_NoMatch;
2773 Parser.Lex(); // Eat identifier token.
2774 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2775 return MatchOperand_Success;
2778 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2779 /// coproc_option : '{' imm0_255 '}'
2780 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2781 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2782 SMLoc S = Parser.getTok().getLoc();
2784 // If this isn't a '{', this isn't a coprocessor immediate operand.
2785 if (Parser.getTok().isNot(AsmToken::LCurly))
2786 return MatchOperand_NoMatch;
2787 Parser.Lex(); // Eat the '{'
2790 SMLoc Loc = Parser.getTok().getLoc();
2791 if (getParser().ParseExpression(Expr)) {
2792 Error(Loc, "illegal expression");
2793 return MatchOperand_ParseFail;
2795 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2796 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2797 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2798 return MatchOperand_ParseFail;
2800 int Val = CE->getValue();
2802 // Check for and consume the closing '}'
2803 if (Parser.getTok().isNot(AsmToken::RCurly))
2804 return MatchOperand_ParseFail;
2805 SMLoc E = Parser.getTok().getLoc();
2806 Parser.Lex(); // Eat the '}'
2808 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2809 return MatchOperand_Success;
2812 // For register list parsing, we need to map from raw GPR register numbering
2813 // to the enumeration values. The enumeration values aren't sorted by
2814 // register number due to our using "sp", "lr" and "pc" as canonical names.
2815 static unsigned getNextRegister(unsigned Reg) {
2816 // If this is a GPR, we need to do it manually, otherwise we can rely
2817 // on the sort ordering of the enumeration since the other reg-classes
2819 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2822 default: llvm_unreachable("Invalid GPR number!");
2823 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2824 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2825 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2826 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2827 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2828 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2829 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2830 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2834 // Return the low-subreg of a given Q register.
2835 static unsigned getDRegFromQReg(unsigned QReg) {
2837 default: llvm_unreachable("expected a Q register!");
2838 case ARM::Q0: return ARM::D0;
2839 case ARM::Q1: return ARM::D2;
2840 case ARM::Q2: return ARM::D4;
2841 case ARM::Q3: return ARM::D6;
2842 case ARM::Q4: return ARM::D8;
2843 case ARM::Q5: return ARM::D10;
2844 case ARM::Q6: return ARM::D12;
2845 case ARM::Q7: return ARM::D14;
2846 case ARM::Q8: return ARM::D16;
2847 case ARM::Q9: return ARM::D18;
2848 case ARM::Q10: return ARM::D20;
2849 case ARM::Q11: return ARM::D22;
2850 case ARM::Q12: return ARM::D24;
2851 case ARM::Q13: return ARM::D26;
2852 case ARM::Q14: return ARM::D28;
2853 case ARM::Q15: return ARM::D30;
2857 /// Parse a register list.
2859 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2860 assert(Parser.getTok().is(AsmToken::LCurly) &&
2861 "Token is not a Left Curly Brace");
2862 SMLoc S = Parser.getTok().getLoc();
2863 Parser.Lex(); // Eat '{' token.
2864 SMLoc RegLoc = Parser.getTok().getLoc();
2866 // Check the first register in the list to see what register class
2867 // this is a list of.
2868 int Reg = tryParseRegister();
2870 return Error(RegLoc, "register expected");
2872 // The reglist instructions have at most 16 registers, so reserve
2873 // space for that many.
2874 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2876 // Allow Q regs and just interpret them as the two D sub-registers.
2877 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2878 Reg = getDRegFromQReg(Reg);
2879 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2882 const MCRegisterClass *RC;
2883 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2884 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2885 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2886 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2887 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2888 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2890 return Error(RegLoc, "invalid register in register list");
2892 // Store the register.
2893 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2895 // This starts immediately after the first register token in the list,
2896 // so we can see either a comma or a minus (range separator) as a legal
2898 while (Parser.getTok().is(AsmToken::Comma) ||
2899 Parser.getTok().is(AsmToken::Minus)) {
2900 if (Parser.getTok().is(AsmToken::Minus)) {
2901 Parser.Lex(); // Eat the minus.
2902 SMLoc EndLoc = Parser.getTok().getLoc();
2903 int EndReg = tryParseRegister();
2905 return Error(EndLoc, "register expected");
2906 // Allow Q regs and just interpret them as the two D sub-registers.
2907 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2908 EndReg = getDRegFromQReg(EndReg) + 1;
2909 // If the register is the same as the start reg, there's nothing
2913 // The register must be in the same register class as the first.
2914 if (!RC->contains(EndReg))
2915 return Error(EndLoc, "invalid register in register list");
2916 // Ranges must go from low to high.
2917 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
2918 return Error(EndLoc, "bad range in register list");
2920 // Add all the registers in the range to the register list.
2921 while (Reg != EndReg) {
2922 Reg = getNextRegister(Reg);
2923 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2927 Parser.Lex(); // Eat the comma.
2928 RegLoc = Parser.getTok().getLoc();
2930 const AsmToken RegTok = Parser.getTok();
2931 Reg = tryParseRegister();
2933 return Error(RegLoc, "register expected");
2934 // Allow Q regs and just interpret them as the two D sub-registers.
2935 bool isQReg = false;
2936 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2937 Reg = getDRegFromQReg(Reg);
2940 // The register must be in the same register class as the first.
2941 if (!RC->contains(Reg))
2942 return Error(RegLoc, "invalid register in register list");
2943 // List must be monotonically increasing.
2944 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
2945 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2946 Warning(RegLoc, "register list not in ascending order");
2948 return Error(RegLoc, "register list not in ascending order");
2950 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
2951 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2952 ") in register list");
2955 // VFP register lists must also be contiguous.
2956 // It's OK to use the enumeration values directly here rather, as the
2957 // VFP register classes have the enum sorted properly.
2958 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2960 return Error(RegLoc, "non-contiguous register range");
2961 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2963 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
2966 SMLoc E = Parser.getTok().getLoc();
2967 if (Parser.getTok().isNot(AsmToken::RCurly))
2968 return Error(E, "'}' expected");
2969 Parser.Lex(); // Eat '}' token.
2971 // Push the register list operand.
2972 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
2974 // The ARM system instruction variants for LDM/STM have a '^' token here.
2975 if (Parser.getTok().is(AsmToken::Caret)) {
2976 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2977 Parser.Lex(); // Eat '^' token.
2983 // Helper function to parse the lane index for vector lists.
2984 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2985 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2986 Index = 0; // Always return a defined index value.
2987 if (Parser.getTok().is(AsmToken::LBrac)) {
2988 Parser.Lex(); // Eat the '['.
2989 if (Parser.getTok().is(AsmToken::RBrac)) {
2990 // "Dn[]" is the 'all lanes' syntax.
2991 LaneKind = AllLanes;
2992 Parser.Lex(); // Eat the ']'.
2993 return MatchOperand_Success;
2996 // There's an optional '#' token here. Normally there wouldn't be, but
2997 // inline assemble puts one in, and it's friendly to accept that.
2998 if (Parser.getTok().is(AsmToken::Hash))
2999 Parser.Lex(); // Eat the '#'
3001 const MCExpr *LaneIndex;
3002 SMLoc Loc = Parser.getTok().getLoc();
3003 if (getParser().ParseExpression(LaneIndex)) {
3004 Error(Loc, "illegal expression");
3005 return MatchOperand_ParseFail;
3007 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3009 Error(Loc, "lane index must be empty or an integer");
3010 return MatchOperand_ParseFail;
3012 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3013 Error(Parser.getTok().getLoc(), "']' expected");
3014 return MatchOperand_ParseFail;
3016 Parser.Lex(); // Eat the ']'.
3017 int64_t Val = CE->getValue();
3019 // FIXME: Make this range check context sensitive for .8, .16, .32.
3020 if (Val < 0 || Val > 7) {
3021 Error(Parser.getTok().getLoc(), "lane index out of range");
3022 return MatchOperand_ParseFail;
3025 LaneKind = IndexedLane;
3026 return MatchOperand_Success;
3029 return MatchOperand_Success;
3032 // parse a vector register list
3033 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3034 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3035 VectorLaneTy LaneKind;
3037 SMLoc S = Parser.getTok().getLoc();
3038 // As an extension (to match gas), support a plain D register or Q register
3039 // (without encosing curly braces) as a single or double entry list,
3041 if (Parser.getTok().is(AsmToken::Identifier)) {
3042 int Reg = tryParseRegister();
3044 return MatchOperand_NoMatch;
3045 SMLoc E = Parser.getTok().getLoc();
3046 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3047 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
3048 if (Res != MatchOperand_Success)
3052 E = Parser.getTok().getLoc();
3053 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3056 E = Parser.getTok().getLoc();
3057 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3061 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3066 return MatchOperand_Success;
3068 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3069 Reg = getDRegFromQReg(Reg);
3070 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
3071 if (Res != MatchOperand_Success)
3075 E = Parser.getTok().getLoc();
3076 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3077 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3078 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3081 E = Parser.getTok().getLoc();
3082 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3083 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3084 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3088 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3093 return MatchOperand_Success;
3095 Error(S, "vector register expected");
3096 return MatchOperand_ParseFail;
3099 if (Parser.getTok().isNot(AsmToken::LCurly))
3100 return MatchOperand_NoMatch;
3102 Parser.Lex(); // Eat '{' token.
3103 SMLoc RegLoc = Parser.getTok().getLoc();
3105 int Reg = tryParseRegister();
3107 Error(RegLoc, "register expected");
3108 return MatchOperand_ParseFail;
3112 unsigned FirstReg = Reg;
3113 // The list is of D registers, but we also allow Q regs and just interpret
3114 // them as the two D sub-registers.
3115 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3116 FirstReg = Reg = getDRegFromQReg(Reg);
3117 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3118 // it's ambiguous with four-register single spaced.
3122 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
3123 return MatchOperand_ParseFail;
3125 while (Parser.getTok().is(AsmToken::Comma) ||
3126 Parser.getTok().is(AsmToken::Minus)) {
3127 if (Parser.getTok().is(AsmToken::Minus)) {
3129 Spacing = 1; // Register range implies a single spaced list.
3130 else if (Spacing == 2) {
3131 Error(Parser.getTok().getLoc(),
3132 "sequential registers in double spaced list");
3133 return MatchOperand_ParseFail;
3135 Parser.Lex(); // Eat the minus.
3136 SMLoc EndLoc = Parser.getTok().getLoc();
3137 int EndReg = tryParseRegister();
3139 Error(EndLoc, "register expected");
3140 return MatchOperand_ParseFail;
3142 // Allow Q regs and just interpret them as the two D sub-registers.
3143 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3144 EndReg = getDRegFromQReg(EndReg) + 1;
3145 // If the register is the same as the start reg, there's nothing
3149 // The register must be in the same register class as the first.
3150 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3151 Error(EndLoc, "invalid register in register list");
3152 return MatchOperand_ParseFail;
3154 // Ranges must go from low to high.
3156 Error(EndLoc, "bad range in register list");
3157 return MatchOperand_ParseFail;
3159 // Parse the lane specifier if present.
3160 VectorLaneTy NextLaneKind;
3161 unsigned NextLaneIndex;
3162 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3163 return MatchOperand_ParseFail;
3164 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3165 Error(EndLoc, "mismatched lane index in register list");
3166 return MatchOperand_ParseFail;
3168 EndLoc = Parser.getTok().getLoc();
3170 // Add all the registers in the range to the register list.
3171 Count += EndReg - Reg;
3175 Parser.Lex(); // Eat the comma.
3176 RegLoc = Parser.getTok().getLoc();
3178 Reg = tryParseRegister();
3180 Error(RegLoc, "register expected");
3181 return MatchOperand_ParseFail;
3183 // vector register lists must be contiguous.
3184 // It's OK to use the enumeration values directly here rather, as the
3185 // VFP register classes have the enum sorted properly.
3187 // The list is of D registers, but we also allow Q regs and just interpret
3188 // them as the two D sub-registers.
3189 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3191 Spacing = 1; // Register range implies a single spaced list.
3192 else if (Spacing == 2) {
3194 "invalid register in double-spaced list (must be 'D' register')");
3195 return MatchOperand_ParseFail;
3197 Reg = getDRegFromQReg(Reg);
3198 if (Reg != OldReg + 1) {
3199 Error(RegLoc, "non-contiguous register range");
3200 return MatchOperand_ParseFail;
3204 // Parse the lane specifier if present.
3205 VectorLaneTy NextLaneKind;
3206 unsigned NextLaneIndex;
3207 SMLoc EndLoc = Parser.getTok().getLoc();
3208 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3209 return MatchOperand_ParseFail;
3210 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3211 Error(EndLoc, "mismatched lane index in register list");
3212 return MatchOperand_ParseFail;
3216 // Normal D register.
3217 // Figure out the register spacing (single or double) of the list if
3218 // we don't know it already.
3220 Spacing = 1 + (Reg == OldReg + 2);
3222 // Just check that it's contiguous and keep going.
3223 if (Reg != OldReg + Spacing) {
3224 Error(RegLoc, "non-contiguous register range");
3225 return MatchOperand_ParseFail;
3228 // Parse the lane specifier if present.
3229 VectorLaneTy NextLaneKind;
3230 unsigned NextLaneIndex;
3231 SMLoc EndLoc = Parser.getTok().getLoc();
3232 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3233 return MatchOperand_ParseFail;
3234 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3235 Error(EndLoc, "mismatched lane index in register list");
3236 return MatchOperand_ParseFail;
3240 SMLoc E = Parser.getTok().getLoc();
3241 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3242 Error(E, "'}' expected");
3243 return MatchOperand_ParseFail;
3245 Parser.Lex(); // Eat '}' token.
3249 // Two-register operands have been converted to the
3250 // composite register classes.
3252 const MCRegisterClass *RC = (Spacing == 1) ?
3253 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3254 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3255 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3258 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3259 (Spacing == 2), S, E));
3262 // Two-register operands have been converted to the
3263 // composite register classes.
3265 const MCRegisterClass *RC = (Spacing == 1) ?
3266 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3267 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3268 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3270 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3275 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3281 return MatchOperand_Success;
3284 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3285 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3286 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3287 SMLoc S = Parser.getTok().getLoc();
3288 const AsmToken &Tok = Parser.getTok();
3291 if (Tok.is(AsmToken::Identifier)) {
3292 StringRef OptStr = Tok.getString();
3294 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3295 .Case("sy", ARM_MB::SY)
3296 .Case("st", ARM_MB::ST)
3297 .Case("sh", ARM_MB::ISH)
3298 .Case("ish", ARM_MB::ISH)
3299 .Case("shst", ARM_MB::ISHST)
3300 .Case("ishst", ARM_MB::ISHST)
3301 .Case("nsh", ARM_MB::NSH)
3302 .Case("un", ARM_MB::NSH)
3303 .Case("nshst", ARM_MB::NSHST)
3304 .Case("unst", ARM_MB::NSHST)
3305 .Case("osh", ARM_MB::OSH)
3306 .Case("oshst", ARM_MB::OSHST)
3310 return MatchOperand_NoMatch;
3312 Parser.Lex(); // Eat identifier token.
3313 } else if (Tok.is(AsmToken::Hash) ||
3314 Tok.is(AsmToken::Dollar) ||
3315 Tok.is(AsmToken::Integer)) {
3316 if (Parser.getTok().isNot(AsmToken::Integer))
3317 Parser.Lex(); // Eat the '#'.
3318 SMLoc Loc = Parser.getTok().getLoc();
3320 const MCExpr *MemBarrierID;
3321 if (getParser().ParseExpression(MemBarrierID)) {
3322 Error(Loc, "illegal expression");
3323 return MatchOperand_ParseFail;
3326 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3328 Error(Loc, "constant expression expected");
3329 return MatchOperand_ParseFail;
3332 int Val = CE->getValue();
3334 Error(Loc, "immediate value out of range");
3335 return MatchOperand_ParseFail;
3338 Opt = ARM_MB::RESERVED_0 + Val;
3340 return MatchOperand_ParseFail;
3342 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3343 return MatchOperand_Success;
3346 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3347 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3348 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3349 SMLoc S = Parser.getTok().getLoc();
3350 const AsmToken &Tok = Parser.getTok();
3351 if (!Tok.is(AsmToken::Identifier))
3352 return MatchOperand_NoMatch;
3353 StringRef IFlagsStr = Tok.getString();
3355 // An iflags string of "none" is interpreted to mean that none of the AIF
3356 // bits are set. Not a terribly useful instruction, but a valid encoding.
3357 unsigned IFlags = 0;
3358 if (IFlagsStr != "none") {
3359 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3360 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3361 .Case("a", ARM_PROC::A)
3362 .Case("i", ARM_PROC::I)
3363 .Case("f", ARM_PROC::F)
3366 // If some specific iflag is already set, it means that some letter is
3367 // present more than once, this is not acceptable.
3368 if (Flag == ~0U || (IFlags & Flag))
3369 return MatchOperand_NoMatch;
3375 Parser.Lex(); // Eat identifier token.
3376 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3377 return MatchOperand_Success;
3380 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3381 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3382 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3383 SMLoc S = Parser.getTok().getLoc();
3384 const AsmToken &Tok = Parser.getTok();
3385 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3386 StringRef Mask = Tok.getString();
3389 // See ARMv6-M 10.1.1
3390 std::string Name = Mask.lower();
3391 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3392 // Note: in the documentation:
3393 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3394 // for MSR APSR_nzcvq.
3395 // but we do make it an alias here. This is so to get the "mask encoding"
3396 // bits correct on MSR APSR writes.
3398 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3399 // should really only be allowed when writing a special register. Note
3400 // they get dropped in the MRS instruction reading a special register as
3401 // the SYSm field is only 8 bits.
3403 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3404 // includes the DSP extension but that is not checked.
3405 .Case("apsr", 0x800)
3406 .Case("apsr_nzcvq", 0x800)
3407 .Case("apsr_g", 0x400)
3408 .Case("apsr_nzcvqg", 0xc00)
3409 .Case("iapsr", 0x801)
3410 .Case("iapsr_nzcvq", 0x801)
3411 .Case("iapsr_g", 0x401)
3412 .Case("iapsr_nzcvqg", 0xc01)
3413 .Case("eapsr", 0x802)
3414 .Case("eapsr_nzcvq", 0x802)
3415 .Case("eapsr_g", 0x402)
3416 .Case("eapsr_nzcvqg", 0xc02)
3417 .Case("xpsr", 0x803)
3418 .Case("xpsr_nzcvq", 0x803)
3419 .Case("xpsr_g", 0x403)
3420 .Case("xpsr_nzcvqg", 0xc03)
3421 .Case("ipsr", 0x805)
3422 .Case("epsr", 0x806)
3423 .Case("iepsr", 0x807)
3426 .Case("primask", 0x810)
3427 .Case("basepri", 0x811)
3428 .Case("basepri_max", 0x812)
3429 .Case("faultmask", 0x813)
3430 .Case("control", 0x814)
3433 if (FlagsVal == ~0U)
3434 return MatchOperand_NoMatch;
3436 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3437 // basepri, basepri_max and faultmask only valid for V7m.
3438 return MatchOperand_NoMatch;
3440 Parser.Lex(); // Eat identifier token.
3441 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3442 return MatchOperand_Success;
3445 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3446 size_t Start = 0, Next = Mask.find('_');
3447 StringRef Flags = "";
3448 std::string SpecReg = Mask.slice(Start, Next).lower();
3449 if (Next != StringRef::npos)
3450 Flags = Mask.slice(Next+1, Mask.size());
3452 // FlagsVal contains the complete mask:
3454 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3455 unsigned FlagsVal = 0;
3457 if (SpecReg == "apsr") {
3458 FlagsVal = StringSwitch<unsigned>(Flags)
3459 .Case("nzcvq", 0x8) // same as CPSR_f
3460 .Case("g", 0x4) // same as CPSR_s
3461 .Case("nzcvqg", 0xc) // same as CPSR_fs
3464 if (FlagsVal == ~0U) {
3466 return MatchOperand_NoMatch;
3468 FlagsVal = 8; // No flag
3470 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3471 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3472 if (Flags == "all" || Flags == "")
3474 for (int i = 0, e = Flags.size(); i != e; ++i) {
3475 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3482 // If some specific flag is already set, it means that some letter is
3483 // present more than once, this is not acceptable.
3484 if (FlagsVal == ~0U || (FlagsVal & Flag))
3485 return MatchOperand_NoMatch;
3488 } else // No match for special register.
3489 return MatchOperand_NoMatch;
3491 // Special register without flags is NOT equivalent to "fc" flags.
3492 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3493 // two lines would enable gas compatibility at the expense of breaking
3499 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3500 if (SpecReg == "spsr")
3503 Parser.Lex(); // Eat identifier token.
3504 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3505 return MatchOperand_Success;
3508 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3509 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3510 int Low, int High) {
3511 const AsmToken &Tok = Parser.getTok();
3512 if (Tok.isNot(AsmToken::Identifier)) {
3513 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3514 return MatchOperand_ParseFail;
3516 StringRef ShiftName = Tok.getString();
3517 std::string LowerOp = Op.lower();
3518 std::string UpperOp = Op.upper();
3519 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3520 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3521 return MatchOperand_ParseFail;
3523 Parser.Lex(); // Eat shift type token.
3525 // There must be a '#' and a shift amount.
3526 if (Parser.getTok().isNot(AsmToken::Hash) &&
3527 Parser.getTok().isNot(AsmToken::Dollar)) {
3528 Error(Parser.getTok().getLoc(), "'#' expected");
3529 return MatchOperand_ParseFail;
3531 Parser.Lex(); // Eat hash token.
3533 const MCExpr *ShiftAmount;
3534 SMLoc Loc = Parser.getTok().getLoc();
3535 if (getParser().ParseExpression(ShiftAmount)) {
3536 Error(Loc, "illegal expression");
3537 return MatchOperand_ParseFail;
3539 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3541 Error(Loc, "constant expression expected");
3542 return MatchOperand_ParseFail;
3544 int Val = CE->getValue();
3545 if (Val < Low || Val > High) {
3546 Error(Loc, "immediate value out of range");
3547 return MatchOperand_ParseFail;
3550 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3552 return MatchOperand_Success;
3555 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3556 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3557 const AsmToken &Tok = Parser.getTok();
3558 SMLoc S = Tok.getLoc();
3559 if (Tok.isNot(AsmToken::Identifier)) {
3560 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3561 return MatchOperand_ParseFail;
3563 int Val = StringSwitch<int>(Tok.getString())
3567 Parser.Lex(); // Eat the token.
3570 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3571 return MatchOperand_ParseFail;
3573 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3575 S, Parser.getTok().getLoc()));
3576 return MatchOperand_Success;
3579 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3580 /// instructions. Legal values are:
3581 /// lsl #n 'n' in [0,31]
3582 /// asr #n 'n' in [1,32]
3583 /// n == 32 encoded as n == 0.
3584 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3585 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3586 const AsmToken &Tok = Parser.getTok();
3587 SMLoc S = Tok.getLoc();
3588 if (Tok.isNot(AsmToken::Identifier)) {
3589 Error(S, "shift operator 'asr' or 'lsl' expected");
3590 return MatchOperand_ParseFail;
3592 StringRef ShiftName = Tok.getString();
3594 if (ShiftName == "lsl" || ShiftName == "LSL")
3596 else if (ShiftName == "asr" || ShiftName == "ASR")
3599 Error(S, "shift operator 'asr' or 'lsl' expected");
3600 return MatchOperand_ParseFail;
3602 Parser.Lex(); // Eat the operator.
3604 // A '#' and a shift amount.
3605 if (Parser.getTok().isNot(AsmToken::Hash) &&
3606 Parser.getTok().isNot(AsmToken::Dollar)) {
3607 Error(Parser.getTok().getLoc(), "'#' expected");
3608 return MatchOperand_ParseFail;
3610 Parser.Lex(); // Eat hash token.
3612 const MCExpr *ShiftAmount;
3613 SMLoc E = Parser.getTok().getLoc();
3614 if (getParser().ParseExpression(ShiftAmount)) {
3615 Error(E, "malformed shift expression");
3616 return MatchOperand_ParseFail;
3618 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3620 Error(E, "shift amount must be an immediate");
3621 return MatchOperand_ParseFail;
3624 int64_t Val = CE->getValue();
3626 // Shift amount must be in [1,32]
3627 if (Val < 1 || Val > 32) {
3628 Error(E, "'asr' shift amount must be in range [1,32]");
3629 return MatchOperand_ParseFail;
3631 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3632 if (isThumb() && Val == 32) {
3633 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3634 return MatchOperand_ParseFail;
3636 if (Val == 32) Val = 0;
3638 // Shift amount must be in [1,32]
3639 if (Val < 0 || Val > 31) {
3640 Error(E, "'lsr' shift amount must be in range [0,31]");
3641 return MatchOperand_ParseFail;
3645 E = Parser.getTok().getLoc();
3646 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3648 return MatchOperand_Success;
3651 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3652 /// of instructions. Legal values are:
3653 /// ror #n 'n' in {0, 8, 16, 24}
3654 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3655 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3656 const AsmToken &Tok = Parser.getTok();
3657 SMLoc S = Tok.getLoc();
3658 if (Tok.isNot(AsmToken::Identifier))
3659 return MatchOperand_NoMatch;
3660 StringRef ShiftName = Tok.getString();
3661 if (ShiftName != "ror" && ShiftName != "ROR")
3662 return MatchOperand_NoMatch;
3663 Parser.Lex(); // Eat the operator.
3665 // A '#' and a rotate amount.
3666 if (Parser.getTok().isNot(AsmToken::Hash) &&
3667 Parser.getTok().isNot(AsmToken::Dollar)) {
3668 Error(Parser.getTok().getLoc(), "'#' expected");
3669 return MatchOperand_ParseFail;
3671 Parser.Lex(); // Eat hash token.
3673 const MCExpr *ShiftAmount;
3674 SMLoc E = Parser.getTok().getLoc();
3675 if (getParser().ParseExpression(ShiftAmount)) {
3676 Error(E, "malformed rotate expression");
3677 return MatchOperand_ParseFail;
3679 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3681 Error(E, "rotate amount must be an immediate");
3682 return MatchOperand_ParseFail;
3685 int64_t Val = CE->getValue();
3686 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3687 // normally, zero is represented in asm by omitting the rotate operand
3689 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3690 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3691 return MatchOperand_ParseFail;
3694 E = Parser.getTok().getLoc();
3695 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3697 return MatchOperand_Success;
3700 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3701 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3702 SMLoc S = Parser.getTok().getLoc();
3703 // The bitfield descriptor is really two operands, the LSB and the width.
3704 if (Parser.getTok().isNot(AsmToken::Hash) &&
3705 Parser.getTok().isNot(AsmToken::Dollar)) {
3706 Error(Parser.getTok().getLoc(), "'#' expected");
3707 return MatchOperand_ParseFail;
3709 Parser.Lex(); // Eat hash token.
3711 const MCExpr *LSBExpr;
3712 SMLoc E = Parser.getTok().getLoc();
3713 if (getParser().ParseExpression(LSBExpr)) {
3714 Error(E, "malformed immediate expression");
3715 return MatchOperand_ParseFail;
3717 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3719 Error(E, "'lsb' operand must be an immediate");
3720 return MatchOperand_ParseFail;
3723 int64_t LSB = CE->getValue();
3724 // The LSB must be in the range [0,31]
3725 if (LSB < 0 || LSB > 31) {
3726 Error(E, "'lsb' operand must be in the range [0,31]");
3727 return MatchOperand_ParseFail;
3729 E = Parser.getTok().getLoc();
3731 // Expect another immediate operand.
3732 if (Parser.getTok().isNot(AsmToken::Comma)) {
3733 Error(Parser.getTok().getLoc(), "too few operands");
3734 return MatchOperand_ParseFail;
3736 Parser.Lex(); // Eat hash token.
3737 if (Parser.getTok().isNot(AsmToken::Hash) &&
3738 Parser.getTok().isNot(AsmToken::Dollar)) {
3739 Error(Parser.getTok().getLoc(), "'#' expected");
3740 return MatchOperand_ParseFail;
3742 Parser.Lex(); // Eat hash token.
3744 const MCExpr *WidthExpr;
3745 if (getParser().ParseExpression(WidthExpr)) {
3746 Error(E, "malformed immediate expression");
3747 return MatchOperand_ParseFail;
3749 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3751 Error(E, "'width' operand must be an immediate");
3752 return MatchOperand_ParseFail;
3755 int64_t Width = CE->getValue();
3756 // The LSB must be in the range [1,32-lsb]
3757 if (Width < 1 || Width > 32 - LSB) {
3758 Error(E, "'width' operand must be in the range [1,32-lsb]");
3759 return MatchOperand_ParseFail;
3761 E = Parser.getTok().getLoc();
3763 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3765 return MatchOperand_Success;
3768 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3769 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3770 // Check for a post-index addressing register operand. Specifically:
3771 // postidx_reg := '+' register {, shift}
3772 // | '-' register {, shift}
3773 // | register {, shift}
3775 // This method must return MatchOperand_NoMatch without consuming any tokens
3776 // in the case where there is no match, as other alternatives take other
3778 AsmToken Tok = Parser.getTok();
3779 SMLoc S = Tok.getLoc();
3780 bool haveEaten = false;
3783 if (Tok.is(AsmToken::Plus)) {
3784 Parser.Lex(); // Eat the '+' token.
3786 } else if (Tok.is(AsmToken::Minus)) {
3787 Parser.Lex(); // Eat the '-' token.
3791 if (Parser.getTok().is(AsmToken::Identifier))
3792 Reg = tryParseRegister();
3795 return MatchOperand_NoMatch;
3796 Error(Parser.getTok().getLoc(), "register expected");
3797 return MatchOperand_ParseFail;
3799 SMLoc E = Parser.getTok().getLoc();
3801 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3802 unsigned ShiftImm = 0;
3803 if (Parser.getTok().is(AsmToken::Comma)) {
3804 Parser.Lex(); // Eat the ','.
3805 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3806 return MatchOperand_ParseFail;
3809 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3812 return MatchOperand_Success;
3815 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3816 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3817 // Check for a post-index addressing register operand. Specifically:
3818 // am3offset := '+' register
3825 // This method must return MatchOperand_NoMatch without consuming any tokens
3826 // in the case where there is no match, as other alternatives take other
3828 AsmToken Tok = Parser.getTok();
3829 SMLoc S = Tok.getLoc();
3831 // Do immediates first, as we always parse those if we have a '#'.
3832 if (Parser.getTok().is(AsmToken::Hash) ||
3833 Parser.getTok().is(AsmToken::Dollar)) {
3834 Parser.Lex(); // Eat the '#'.
3835 // Explicitly look for a '-', as we need to encode negative zero
3837 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3838 const MCExpr *Offset;
3839 if (getParser().ParseExpression(Offset))
3840 return MatchOperand_ParseFail;
3841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3843 Error(S, "constant expression expected");
3844 return MatchOperand_ParseFail;
3846 SMLoc E = Tok.getLoc();
3847 // Negative zero is encoded as the flag value INT32_MIN.
3848 int32_t Val = CE->getValue();
3849 if (isNegative && Val == 0)
3853 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3855 return MatchOperand_Success;
3859 bool haveEaten = false;
3862 if (Tok.is(AsmToken::Plus)) {
3863 Parser.Lex(); // Eat the '+' token.
3865 } else if (Tok.is(AsmToken::Minus)) {
3866 Parser.Lex(); // Eat the '-' token.
3870 if (Parser.getTok().is(AsmToken::Identifier))
3871 Reg = tryParseRegister();
3874 return MatchOperand_NoMatch;
3875 Error(Parser.getTok().getLoc(), "register expected");
3876 return MatchOperand_ParseFail;
3878 SMLoc E = Parser.getTok().getLoc();
3880 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3883 return MatchOperand_Success;
3886 /// cvtT2LdrdPre - Convert parsed operands to MCInst.
3887 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3888 /// when they refer multiple MIOperands inside a single one.
3890 cvtT2LdrdPre(MCInst &Inst,
3891 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3893 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3894 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3895 // Create a writeback register dummy placeholder.
3896 Inst.addOperand(MCOperand::CreateReg(0));
3898 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3900 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3903 /// cvtT2StrdPre - Convert parsed operands to MCInst.
3904 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3905 /// when they refer multiple MIOperands inside a single one.
3907 cvtT2StrdPre(MCInst &Inst,
3908 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3909 // Create a writeback register dummy placeholder.
3910 Inst.addOperand(MCOperand::CreateReg(0));
3912 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3913 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3915 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3917 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3920 /// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3921 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3922 /// when they refer multiple MIOperands inside a single one.
3924 cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
3925 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3926 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3928 // Create a writeback register dummy placeholder.
3929 Inst.addOperand(MCOperand::CreateImm(0));
3931 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3932 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3935 /// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3936 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3937 /// when they refer multiple MIOperands inside a single one.
3939 cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
3940 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3941 // Create a writeback register dummy placeholder.
3942 Inst.addOperand(MCOperand::CreateImm(0));
3943 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3944 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3945 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3948 /// cvtLdWriteBackRegAddrMode2 - 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 cvtLdWriteBackRegAddrMode2(MCInst &Inst,
3953 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3954 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3956 // Create a writeback register dummy placeholder.
3957 Inst.addOperand(MCOperand::CreateImm(0));
3959 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3960 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3963 /// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3964 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3965 /// when they refer multiple MIOperands inside a single one.
3967 cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
3968 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3969 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3971 // Create a writeback register dummy placeholder.
3972 Inst.addOperand(MCOperand::CreateImm(0));
3974 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3975 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3979 /// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3980 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3981 /// when they refer multiple MIOperands inside a single one.
3983 cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
3984 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3985 // Create a writeback register dummy placeholder.
3986 Inst.addOperand(MCOperand::CreateImm(0));
3987 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3988 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3989 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3992 /// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3993 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3994 /// when they refer multiple MIOperands inside a single one.
3996 cvtStWriteBackRegAddrMode2(MCInst &Inst,
3997 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3998 // Create a writeback register dummy placeholder.
3999 Inst.addOperand(MCOperand::CreateImm(0));
4000 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4001 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4002 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4005 /// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4006 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4007 /// when they refer multiple MIOperands inside a single one.
4009 cvtStWriteBackRegAddrMode3(MCInst &Inst,
4010 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4011 // Create a writeback register dummy placeholder.
4012 Inst.addOperand(MCOperand::CreateImm(0));
4013 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4014 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4015 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4018 /// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4019 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4020 /// when they refer multiple MIOperands inside a single one.
4022 cvtLdExtTWriteBackImm(MCInst &Inst,
4023 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4025 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4026 // Create a writeback register dummy placeholder.
4027 Inst.addOperand(MCOperand::CreateImm(0));
4029 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4031 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4033 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4036 /// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
4037 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4038 /// when they refer multiple MIOperands inside a single one.
4040 cvtLdExtTWriteBackReg(MCInst &Inst,
4041 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4043 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4044 // Create a writeback register dummy placeholder.
4045 Inst.addOperand(MCOperand::CreateImm(0));
4047 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4049 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4051 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4054 /// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
4055 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4056 /// when they refer multiple MIOperands inside a single one.
4058 cvtStExtTWriteBackImm(MCInst &Inst,
4059 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4060 // Create a writeback register dummy placeholder.
4061 Inst.addOperand(MCOperand::CreateImm(0));
4063 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4065 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4067 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4069 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4072 /// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4073 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4074 /// when they refer multiple MIOperands inside a single one.
4076 cvtStExtTWriteBackReg(MCInst &Inst,
4077 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4078 // Create a writeback register dummy placeholder.
4079 Inst.addOperand(MCOperand::CreateImm(0));
4081 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4083 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4085 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4087 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4090 /// cvtLdrdPre - Convert parsed operands to MCInst.
4091 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4092 /// when they refer multiple MIOperands inside a single one.
4094 cvtLdrdPre(MCInst &Inst,
4095 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4097 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4098 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4099 // Create a writeback register dummy placeholder.
4100 Inst.addOperand(MCOperand::CreateImm(0));
4102 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4104 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4107 /// cvtStrdPre - Convert parsed operands to MCInst.
4108 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4109 /// when they refer multiple MIOperands inside a single one.
4111 cvtStrdPre(MCInst &Inst,
4112 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4113 // Create a writeback register dummy placeholder.
4114 Inst.addOperand(MCOperand::CreateImm(0));
4116 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4117 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4119 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4121 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4124 /// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4125 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4126 /// when they refer multiple MIOperands inside a single one.
4128 cvtLdWriteBackRegAddrMode3(MCInst &Inst,
4129 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4130 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4131 // Create a writeback register dummy placeholder.
4132 Inst.addOperand(MCOperand::CreateImm(0));
4133 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4134 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4137 /// cvtThumbMultiply - Convert parsed operands to MCInst.
4138 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4139 /// when they refer multiple MIOperands inside a single one.
4141 cvtThumbMultiply(MCInst &Inst,
4142 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4143 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4144 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4145 // If we have a three-operand form, make sure to set Rn to be the operand
4146 // that isn't the same as Rd.
4148 if (Operands.size() == 6 &&
4149 ((ARMOperand*)Operands[4])->getReg() ==
4150 ((ARMOperand*)Operands[3])->getReg())
4152 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4153 Inst.addOperand(Inst.getOperand(0));
4154 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4158 cvtVLDwbFixed(MCInst &Inst,
4159 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4161 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4162 // Create a writeback register dummy placeholder.
4163 Inst.addOperand(MCOperand::CreateImm(0));
4165 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4167 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4171 cvtVLDwbRegister(MCInst &Inst,
4172 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4174 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4175 // Create a writeback register dummy placeholder.
4176 Inst.addOperand(MCOperand::CreateImm(0));
4178 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4180 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4182 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4186 cvtVSTwbFixed(MCInst &Inst,
4187 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4188 // Create a writeback register dummy placeholder.
4189 Inst.addOperand(MCOperand::CreateImm(0));
4191 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4193 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4195 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4199 cvtVSTwbRegister(MCInst &Inst,
4200 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4201 // Create a writeback register dummy placeholder.
4202 Inst.addOperand(MCOperand::CreateImm(0));
4204 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4206 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4208 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4210 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4213 /// Parse an ARM memory expression, return false if successful else return true
4214 /// or an error. The first token must be a '[' when called.
4216 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4218 assert(Parser.getTok().is(AsmToken::LBrac) &&
4219 "Token is not a Left Bracket");
4220 S = Parser.getTok().getLoc();
4221 Parser.Lex(); // Eat left bracket token.
4223 const AsmToken &BaseRegTok = Parser.getTok();
4224 int BaseRegNum = tryParseRegister();
4225 if (BaseRegNum == -1)
4226 return Error(BaseRegTok.getLoc(), "register expected");
4228 // The next token must either be a comma or a closing bracket.
4229 const AsmToken &Tok = Parser.getTok();
4230 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
4231 return Error(Tok.getLoc(), "malformed memory operand");
4233 if (Tok.is(AsmToken::RBrac)) {
4235 Parser.Lex(); // Eat right bracket token.
4237 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4238 0, 0, false, S, E));
4240 // If there's a pre-indexing writeback marker, '!', just add it as a token
4241 // operand. It's rather odd, but syntactically valid.
4242 if (Parser.getTok().is(AsmToken::Exclaim)) {
4243 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4244 Parser.Lex(); // Eat the '!'.
4250 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4251 Parser.Lex(); // Eat the comma.
4253 // If we have a ':', it's an alignment specifier.
4254 if (Parser.getTok().is(AsmToken::Colon)) {
4255 Parser.Lex(); // Eat the ':'.
4256 E = Parser.getTok().getLoc();
4259 if (getParser().ParseExpression(Expr))
4262 // The expression has to be a constant. Memory references with relocations
4263 // don't come through here, as they use the <label> forms of the relevant
4265 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4267 return Error (E, "constant expression expected");
4270 switch (CE->getValue()) {
4273 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4274 case 16: Align = 2; break;
4275 case 32: Align = 4; break;
4276 case 64: Align = 8; break;
4277 case 128: Align = 16; break;
4278 case 256: Align = 32; break;
4281 // Now we should have the closing ']'
4282 E = Parser.getTok().getLoc();
4283 if (Parser.getTok().isNot(AsmToken::RBrac))
4284 return Error(E, "']' expected");
4285 Parser.Lex(); // Eat right bracket token.
4287 // Don't worry about range checking the value here. That's handled by
4288 // the is*() predicates.
4289 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4290 ARM_AM::no_shift, 0, Align,
4293 // If there's a pre-indexing writeback marker, '!', just add it as a token
4295 if (Parser.getTok().is(AsmToken::Exclaim)) {
4296 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4297 Parser.Lex(); // Eat the '!'.
4303 // If we have a '#', it's an immediate offset, else assume it's a register
4304 // offset. Be friendly and also accept a plain integer (without a leading
4305 // hash) for gas compatibility.
4306 if (Parser.getTok().is(AsmToken::Hash) ||
4307 Parser.getTok().is(AsmToken::Dollar) ||
4308 Parser.getTok().is(AsmToken::Integer)) {
4309 if (Parser.getTok().isNot(AsmToken::Integer))
4310 Parser.Lex(); // Eat the '#'.
4311 E = Parser.getTok().getLoc();
4313 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4314 const MCExpr *Offset;
4315 if (getParser().ParseExpression(Offset))
4318 // The expression has to be a constant. Memory references with relocations
4319 // don't come through here, as they use the <label> forms of the relevant
4321 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4323 return Error (E, "constant expression expected");
4325 // If the constant was #-0, represent it as INT32_MIN.
4326 int32_t Val = CE->getValue();
4327 if (isNegative && Val == 0)
4328 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4330 // Now we should have the closing ']'
4331 E = Parser.getTok().getLoc();
4332 if (Parser.getTok().isNot(AsmToken::RBrac))
4333 return Error(E, "']' expected");
4334 Parser.Lex(); // Eat right bracket token.
4336 // Don't worry about range checking the value here. That's handled by
4337 // the is*() predicates.
4338 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4339 ARM_AM::no_shift, 0, 0,
4342 // If there's a pre-indexing writeback marker, '!', just add it as a token
4344 if (Parser.getTok().is(AsmToken::Exclaim)) {
4345 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4346 Parser.Lex(); // Eat the '!'.
4352 // The register offset is optionally preceded by a '+' or '-'
4353 bool isNegative = false;
4354 if (Parser.getTok().is(AsmToken::Minus)) {
4356 Parser.Lex(); // Eat the '-'.
4357 } else if (Parser.getTok().is(AsmToken::Plus)) {
4359 Parser.Lex(); // Eat the '+'.
4362 E = Parser.getTok().getLoc();
4363 int OffsetRegNum = tryParseRegister();
4364 if (OffsetRegNum == -1)
4365 return Error(E, "register expected");
4367 // If there's a shift operator, handle it.
4368 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4369 unsigned ShiftImm = 0;
4370 if (Parser.getTok().is(AsmToken::Comma)) {
4371 Parser.Lex(); // Eat the ','.
4372 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4376 // Now we should have the closing ']'
4377 E = Parser.getTok().getLoc();
4378 if (Parser.getTok().isNot(AsmToken::RBrac))
4379 return Error(E, "']' expected");
4380 Parser.Lex(); // Eat right bracket token.
4382 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4383 ShiftType, ShiftImm, 0, isNegative,
4386 // If there's a pre-indexing writeback marker, '!', just add it as a token
4388 if (Parser.getTok().is(AsmToken::Exclaim)) {
4389 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4390 Parser.Lex(); // Eat the '!'.
4396 /// parseMemRegOffsetShift - one of these two:
4397 /// ( lsl | lsr | asr | ror ) , # shift_amount
4399 /// return true if it parses a shift otherwise it returns false.
4400 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4402 SMLoc Loc = Parser.getTok().getLoc();
4403 const AsmToken &Tok = Parser.getTok();
4404 if (Tok.isNot(AsmToken::Identifier))
4406 StringRef ShiftName = Tok.getString();
4407 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4408 ShiftName == "asl" || ShiftName == "ASL")
4410 else if (ShiftName == "lsr" || ShiftName == "LSR")
4412 else if (ShiftName == "asr" || ShiftName == "ASR")
4414 else if (ShiftName == "ror" || ShiftName == "ROR")
4416 else if (ShiftName == "rrx" || ShiftName == "RRX")
4419 return Error(Loc, "illegal shift operator");
4420 Parser.Lex(); // Eat shift type token.
4422 // rrx stands alone.
4424 if (St != ARM_AM::rrx) {
4425 Loc = Parser.getTok().getLoc();
4426 // A '#' and a shift amount.
4427 const AsmToken &HashTok = Parser.getTok();
4428 if (HashTok.isNot(AsmToken::Hash) &&
4429 HashTok.isNot(AsmToken::Dollar))
4430 return Error(HashTok.getLoc(), "'#' expected");
4431 Parser.Lex(); // Eat hash token.
4434 if (getParser().ParseExpression(Expr))
4436 // Range check the immediate.
4437 // lsl, ror: 0 <= imm <= 31
4438 // lsr, asr: 0 <= imm <= 32
4439 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4441 return Error(Loc, "shift amount must be an immediate");
4442 int64_t Imm = CE->getValue();
4444 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4445 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4446 return Error(Loc, "immediate shift value out of range");
4447 // If <ShiftTy> #0, turn it into a no_shift.
4450 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4459 /// parseFPImm - A floating point immediate expression operand.
4460 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4461 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4462 // Anything that can accept a floating point constant as an operand
4463 // needs to go through here, as the regular ParseExpression is
4466 // This routine still creates a generic Immediate operand, containing
4467 // a bitcast of the 64-bit floating point value. The various operands
4468 // that accept floats can check whether the value is valid for them
4469 // via the standard is*() predicates.
4471 SMLoc S = Parser.getTok().getLoc();
4473 if (Parser.getTok().isNot(AsmToken::Hash) &&
4474 Parser.getTok().isNot(AsmToken::Dollar))
4475 return MatchOperand_NoMatch;
4477 // Disambiguate the VMOV forms that can accept an FP immediate.
4478 // vmov.f32 <sreg>, #imm
4479 // vmov.f64 <dreg>, #imm
4480 // vmov.f32 <dreg>, #imm @ vector f32x2
4481 // vmov.f32 <qreg>, #imm @ vector f32x4
4483 // There are also the NEON VMOV instructions which expect an
4484 // integer constant. Make sure we don't try to parse an FPImm
4486 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4487 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4488 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4489 TyOp->getToken() != ".f64"))
4490 return MatchOperand_NoMatch;
4492 Parser.Lex(); // Eat the '#'.
4494 // Handle negation, as that still comes through as a separate token.
4495 bool isNegative = false;
4496 if (Parser.getTok().is(AsmToken::Minus)) {
4500 const AsmToken &Tok = Parser.getTok();
4501 SMLoc Loc = Tok.getLoc();
4502 if (Tok.is(AsmToken::Real)) {
4503 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4504 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4505 // If we had a '-' in front, toggle the sign bit.
4506 IntVal ^= (uint64_t)isNegative << 31;
4507 Parser.Lex(); // Eat the token.
4508 Operands.push_back(ARMOperand::CreateImm(
4509 MCConstantExpr::Create(IntVal, getContext()),
4510 S, Parser.getTok().getLoc()));
4511 return MatchOperand_Success;
4513 // Also handle plain integers. Instructions which allow floating point
4514 // immediates also allow a raw encoded 8-bit value.
4515 if (Tok.is(AsmToken::Integer)) {
4516 int64_t Val = Tok.getIntVal();
4517 Parser.Lex(); // Eat the token.
4518 if (Val > 255 || Val < 0) {
4519 Error(Loc, "encoded floating point value out of range");
4520 return MatchOperand_ParseFail;
4522 double RealVal = ARM_AM::getFPImmFloat(Val);
4523 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4524 Operands.push_back(ARMOperand::CreateImm(
4525 MCConstantExpr::Create(Val, getContext()), S,
4526 Parser.getTok().getLoc()));
4527 return MatchOperand_Success;
4530 Error(Loc, "invalid floating point immediate");
4531 return MatchOperand_ParseFail;
4534 /// Parse a arm instruction operand. For now this parses the operand regardless
4535 /// of the mnemonic.
4536 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4537 StringRef Mnemonic) {
4540 // Check if the current operand has a custom associated parser, if so, try to
4541 // custom parse the operand, or fallback to the general approach.
4542 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4543 if (ResTy == MatchOperand_Success)
4545 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4546 // there was a match, but an error occurred, in which case, just return that
4547 // the operand parsing failed.
4548 if (ResTy == MatchOperand_ParseFail)
4551 switch (getLexer().getKind()) {
4553 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4555 case AsmToken::Identifier: {
4556 if (!tryParseRegisterWithWriteBack(Operands))
4558 int Res = tryParseShiftRegister(Operands);
4559 if (Res == 0) // success
4561 else if (Res == -1) // irrecoverable error
4563 // If this is VMRS, check for the apsr_nzcv operand.
4564 if (Mnemonic == "vmrs" &&
4565 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4566 S = Parser.getTok().getLoc();
4568 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4572 // Fall though for the Identifier case that is not a register or a
4575 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4576 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4577 case AsmToken::String: // quoted label names.
4578 case AsmToken::Dot: { // . as a branch target
4579 // This was not a register so parse other operands that start with an
4580 // identifier (like labels) as expressions and create them as immediates.
4581 const MCExpr *IdVal;
4582 S = Parser.getTok().getLoc();
4583 if (getParser().ParseExpression(IdVal))
4585 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4586 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4589 case AsmToken::LBrac:
4590 return parseMemory(Operands);
4591 case AsmToken::LCurly:
4592 return parseRegisterList(Operands);
4593 case AsmToken::Dollar:
4594 case AsmToken::Hash: {
4595 // #42 -> immediate.
4596 S = Parser.getTok().getLoc();
4599 if (Parser.getTok().isNot(AsmToken::Colon)) {
4600 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4601 const MCExpr *ImmVal;
4602 if (getParser().ParseExpression(ImmVal))
4604 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4606 int32_t Val = CE->getValue();
4607 if (isNegative && Val == 0)
4608 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4610 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4611 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4614 // w/ a ':' after the '#', it's just like a plain ':'.
4617 case AsmToken::Colon: {
4618 // ":lower16:" and ":upper16:" expression prefixes
4619 // FIXME: Check it's an expression prefix,
4620 // e.g. (FOO - :lower16:BAR) isn't legal.
4621 ARMMCExpr::VariantKind RefKind;
4622 if (parsePrefix(RefKind))
4625 const MCExpr *SubExprVal;
4626 if (getParser().ParseExpression(SubExprVal))
4629 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4631 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4632 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4638 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4639 // :lower16: and :upper16:.
4640 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4641 RefKind = ARMMCExpr::VK_ARM_None;
4643 // :lower16: and :upper16: modifiers
4644 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4645 Parser.Lex(); // Eat ':'
4647 if (getLexer().isNot(AsmToken::Identifier)) {
4648 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4652 StringRef IDVal = Parser.getTok().getIdentifier();
4653 if (IDVal == "lower16") {
4654 RefKind = ARMMCExpr::VK_ARM_LO16;
4655 } else if (IDVal == "upper16") {
4656 RefKind = ARMMCExpr::VK_ARM_HI16;
4658 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4663 if (getLexer().isNot(AsmToken::Colon)) {
4664 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4667 Parser.Lex(); // Eat the last ':'
4671 /// \brief Given a mnemonic, split out possible predication code and carry
4672 /// setting letters to form a canonical mnemonic and flags.
4674 // FIXME: Would be nice to autogen this.
4675 // FIXME: This is a bit of a maze of special cases.
4676 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4677 unsigned &PredicationCode,
4679 unsigned &ProcessorIMod,
4680 StringRef &ITMask) {
4681 PredicationCode = ARMCC::AL;
4682 CarrySetting = false;
4685 // Ignore some mnemonics we know aren't predicated forms.
4687 // FIXME: Would be nice to autogen this.
4688 if ((Mnemonic == "movs" && isThumb()) ||
4689 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4690 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4691 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4692 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4693 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4694 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4695 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4696 Mnemonic == "fmuls")
4699 // First, split out any predication code. Ignore mnemonics we know aren't
4700 // predicated but do have a carry-set and so weren't caught above.
4701 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4702 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4703 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4704 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4705 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4706 .Case("eq", ARMCC::EQ)
4707 .Case("ne", ARMCC::NE)
4708 .Case("hs", ARMCC::HS)
4709 .Case("cs", ARMCC::HS)
4710 .Case("lo", ARMCC::LO)
4711 .Case("cc", ARMCC::LO)
4712 .Case("mi", ARMCC::MI)
4713 .Case("pl", ARMCC::PL)
4714 .Case("vs", ARMCC::VS)
4715 .Case("vc", ARMCC::VC)
4716 .Case("hi", ARMCC::HI)
4717 .Case("ls", ARMCC::LS)
4718 .Case("ge", ARMCC::GE)
4719 .Case("lt", ARMCC::LT)
4720 .Case("gt", ARMCC::GT)
4721 .Case("le", ARMCC::LE)
4722 .Case("al", ARMCC::AL)
4725 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4726 PredicationCode = CC;
4730 // Next, determine if we have a carry setting bit. We explicitly ignore all
4731 // the instructions we know end in 's'.
4732 if (Mnemonic.endswith("s") &&
4733 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4734 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4735 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4736 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4737 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4738 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4739 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4740 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4741 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4742 (Mnemonic == "movs" && isThumb()))) {
4743 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4744 CarrySetting = true;
4747 // The "cps" instruction can have a interrupt mode operand which is glued into
4748 // the mnemonic. Check if this is the case, split it and parse the imod op
4749 if (Mnemonic.startswith("cps")) {
4750 // Split out any imod code.
4752 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4753 .Case("ie", ARM_PROC::IE)
4754 .Case("id", ARM_PROC::ID)
4757 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4758 ProcessorIMod = IMod;
4762 // The "it" instruction has the condition mask on the end of the mnemonic.
4763 if (Mnemonic.startswith("it")) {
4764 ITMask = Mnemonic.slice(2, Mnemonic.size());
4765 Mnemonic = Mnemonic.slice(0, 2);
4771 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4772 /// inclusion of carry set or predication code operands.
4774 // FIXME: It would be nice to autogen this.
4776 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
4777 bool &CanAcceptPredicationCode) {
4778 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4779 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4780 Mnemonic == "add" || Mnemonic == "adc" ||
4781 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4782 Mnemonic == "orr" || Mnemonic == "mvn" ||
4783 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4784 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4785 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4786 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4787 Mnemonic == "mla" || Mnemonic == "smlal" ||
4788 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4789 CanAcceptCarrySet = true;
4791 CanAcceptCarrySet = false;
4793 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4794 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4795 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4796 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
4797 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4798 (Mnemonic == "clrex" && !isThumb()) ||
4799 (Mnemonic == "nop" && isThumbOne()) ||
4800 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4801 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4802 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
4803 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4805 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
4806 CanAcceptPredicationCode = false;
4808 CanAcceptPredicationCode = true;
4811 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
4812 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
4813 CanAcceptPredicationCode = false;
4817 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4818 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4819 // FIXME: This is all horribly hacky. We really need a better way to deal
4820 // with optional operands like this in the matcher table.
4822 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4823 // another does not. Specifically, the MOVW instruction does not. So we
4824 // special case it here and remove the defaulted (non-setting) cc_out
4825 // operand if that's the instruction we're trying to match.
4827 // We do this as post-processing of the explicit operands rather than just
4828 // conditionally adding the cc_out in the first place because we need
4829 // to check the type of the parsed immediate operand.
4830 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4831 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4832 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4833 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4836 // Register-register 'add' for thumb does not have a cc_out operand
4837 // when there are only two register operands.
4838 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4839 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4840 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4841 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4843 // Register-register 'add' for thumb does not have a cc_out operand
4844 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4845 // have to check the immediate range here since Thumb2 has a variant
4846 // that can handle a different range and has a cc_out operand.
4847 if (((isThumb() && Mnemonic == "add") ||
4848 (isThumbTwo() && Mnemonic == "sub")) &&
4849 Operands.size() == 6 &&
4850 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4851 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4852 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4853 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4854 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4855 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4857 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4858 // imm0_4095 variant. That's the least-preferred variant when
4859 // selecting via the generic "add" mnemonic, so to know that we
4860 // should remove the cc_out operand, we have to explicitly check that
4861 // it's not one of the other variants. Ugh.
4862 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4863 Operands.size() == 6 &&
4864 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4865 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4866 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4867 // Nest conditions rather than one big 'if' statement for readability.
4869 // If either register is a high reg, it's either one of the SP
4870 // variants (handled above) or a 32-bit encoding, so we just
4871 // check against T3. If the second register is the PC, this is an
4872 // alternate form of ADR, which uses encoding T4, so check for that too.
4873 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4874 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
4875 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4876 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4878 // If both registers are low, we're in an IT block, and the immediate is
4879 // in range, we should use encoding T1 instead, which has a cc_out.
4881 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4882 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4883 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4886 // Otherwise, we use encoding T4, which does not have a cc_out
4891 // The thumb2 multiply instruction doesn't have a CCOut register, so
4892 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4893 // use the 16-bit encoding or not.
4894 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4895 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4896 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4897 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4898 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4899 // If the registers aren't low regs, the destination reg isn't the
4900 // same as one of the source regs, or the cc_out operand is zero
4901 // outside of an IT block, we have to use the 32-bit encoding, so
4902 // remove the cc_out operand.
4903 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4904 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4905 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4907 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4908 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4909 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4910 static_cast<ARMOperand*>(Operands[4])->getReg())))
4913 // Also check the 'mul' syntax variant that doesn't specify an explicit
4914 // destination register.
4915 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4916 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4917 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4918 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4919 // If the registers aren't low regs or the cc_out operand is zero
4920 // outside of an IT block, we have to use the 32-bit encoding, so
4921 // remove the cc_out operand.
4922 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4923 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4929 // Register-register 'add/sub' for thumb does not have a cc_out operand
4930 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4931 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4932 // right, this will result in better diagnostics (which operand is off)
4934 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4935 (Operands.size() == 5 || Operands.size() == 6) &&
4936 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4937 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4938 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4939 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4940 (Operands.size() == 6 &&
4941 static_cast<ARMOperand*>(Operands[5])->isImm())))
4947 static bool isDataTypeToken(StringRef Tok) {
4948 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4949 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4950 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4951 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4952 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4953 Tok == ".f" || Tok == ".d";
4956 // FIXME: This bit should probably be handled via an explicit match class
4957 // in the .td files that matches the suffix instead of having it be
4958 // a literal string token the way it is now.
4959 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4960 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4963 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
4964 /// Parse an arm instruction mnemonic followed by its operands.
4965 bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4966 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4967 // Apply mnemonic aliases before doing anything else, as the destination
4968 // mnemnonic may include suffices and we want to handle them normally.
4969 // The generic tblgen'erated code does this later, at the start of
4970 // MatchInstructionImpl(), but that's too late for aliases that include
4971 // any sort of suffix.
4972 unsigned AvailableFeatures = getAvailableFeatures();
4973 applyMnemonicAliases(Name, AvailableFeatures);
4975 // First check for the ARM-specific .req directive.
4976 if (Parser.getTok().is(AsmToken::Identifier) &&
4977 Parser.getTok().getIdentifier() == ".req") {
4978 parseDirectiveReq(Name, NameLoc);
4979 // We always return 'error' for this, as we're done with this
4980 // statement and don't need to match the 'instruction."
4984 // Create the leading tokens for the mnemonic, split by '.' characters.
4985 size_t Start = 0, Next = Name.find('.');
4986 StringRef Mnemonic = Name.slice(Start, Next);
4988 // Split out the predication code and carry setting flag from the mnemonic.
4989 unsigned PredicationCode;
4990 unsigned ProcessorIMod;
4993 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
4994 ProcessorIMod, ITMask);
4996 // In Thumb1, only the branch (B) instruction can be predicated.
4997 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4998 Parser.EatToEndOfStatement();
4999 return Error(NameLoc, "conditional execution not supported in Thumb1");
5002 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5004 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5005 // is the mask as it will be for the IT encoding if the conditional
5006 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5007 // where the conditional bit0 is zero, the instruction post-processing
5008 // will adjust the mask accordingly.
5009 if (Mnemonic == "it") {
5010 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5011 if (ITMask.size() > 3) {
5012 Parser.EatToEndOfStatement();
5013 return Error(Loc, "too many conditions on IT instruction");
5016 for (unsigned i = ITMask.size(); i != 0; --i) {
5017 char pos = ITMask[i - 1];
5018 if (pos != 't' && pos != 'e') {
5019 Parser.EatToEndOfStatement();
5020 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5023 if (ITMask[i - 1] == 't')
5026 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5029 // FIXME: This is all a pretty gross hack. We should automatically handle
5030 // optional operands like this via tblgen.
5032 // Next, add the CCOut and ConditionCode operands, if needed.
5034 // For mnemonics which can ever incorporate a carry setting bit or predication
5035 // code, our matching model involves us always generating CCOut and
5036 // ConditionCode operands to match the mnemonic "as written" and then we let
5037 // the matcher deal with finding the right instruction or generating an
5038 // appropriate error.
5039 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5040 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
5042 // If we had a carry-set on an instruction that can't do that, issue an
5044 if (!CanAcceptCarrySet && CarrySetting) {
5045 Parser.EatToEndOfStatement();
5046 return Error(NameLoc, "instruction '" + Mnemonic +
5047 "' can not set flags, but 's' suffix specified");
5049 // If we had a predication code on an instruction that can't do that, issue an
5051 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5052 Parser.EatToEndOfStatement();
5053 return Error(NameLoc, "instruction '" + Mnemonic +
5054 "' is not predicable, but condition code specified");
5057 // Add the carry setting operand, if necessary.
5058 if (CanAcceptCarrySet) {
5059 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5060 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5064 // Add the predication code operand, if necessary.
5065 if (CanAcceptPredicationCode) {
5066 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5068 Operands.push_back(ARMOperand::CreateCondCode(
5069 ARMCC::CondCodes(PredicationCode), Loc));
5072 // Add the processor imod operand, if necessary.
5073 if (ProcessorIMod) {
5074 Operands.push_back(ARMOperand::CreateImm(
5075 MCConstantExpr::Create(ProcessorIMod, getContext()),
5079 // Add the remaining tokens in the mnemonic.
5080 while (Next != StringRef::npos) {
5082 Next = Name.find('.', Start + 1);
5083 StringRef ExtraToken = Name.slice(Start, Next);
5085 // Some NEON instructions have an optional datatype suffix that is
5086 // completely ignored. Check for that.
5087 if (isDataTypeToken(ExtraToken) &&
5088 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5091 if (ExtraToken != ".n") {
5092 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5093 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5097 // Read the remaining operands.
5098 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5099 // Read the first operand.
5100 if (parseOperand(Operands, Mnemonic)) {
5101 Parser.EatToEndOfStatement();
5105 while (getLexer().is(AsmToken::Comma)) {
5106 Parser.Lex(); // Eat the comma.
5108 // Parse and remember the operand.
5109 if (parseOperand(Operands, Mnemonic)) {
5110 Parser.EatToEndOfStatement();
5116 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5117 SMLoc Loc = getLexer().getLoc();
5118 Parser.EatToEndOfStatement();
5119 return Error(Loc, "unexpected token in argument list");
5122 Parser.Lex(); // Consume the EndOfStatement
5124 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5125 // do and don't have a cc_out optional-def operand. With some spot-checks
5126 // of the operand list, we can figure out which variant we're trying to
5127 // parse and adjust accordingly before actually matching. We shouldn't ever
5128 // try to remove a cc_out operand that was explicitly set on the the
5129 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5130 // table driven matcher doesn't fit well with the ARM instruction set.
5131 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5132 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5133 Operands.erase(Operands.begin() + 1);
5137 // ARM mode 'blx' need special handling, as the register operand version
5138 // is predicable, but the label operand version is not. So, we can't rely
5139 // on the Mnemonic based checking to correctly figure out when to put
5140 // a k_CondCode operand in the list. If we're trying to match the label
5141 // version, remove the k_CondCode operand here.
5142 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5143 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5144 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5145 Operands.erase(Operands.begin() + 1);
5149 // The vector-compare-to-zero instructions have a literal token "#0" at
5150 // the end that comes to here as an immediate operand. Convert it to a
5151 // token to play nicely with the matcher.
5152 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5153 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5154 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5155 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5156 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5157 if (CE && CE->getValue() == 0) {
5158 Operands.erase(Operands.begin() + 5);
5159 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5163 // VCMP{E} does the same thing, but with a different operand count.
5164 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5165 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5166 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5167 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5168 if (CE && CE->getValue() == 0) {
5169 Operands.erase(Operands.begin() + 4);
5170 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5174 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
5175 // end. Convert it to a token here. Take care not to convert those
5176 // that should hit the Thumb2 encoding.
5177 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
5178 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5179 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5180 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5181 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5182 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5183 if (CE && CE->getValue() == 0 &&
5185 // The cc_out operand matches the IT block.
5186 ((inITBlock() != CarrySetting) &&
5187 // Neither register operand is a high register.
5188 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5189 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
5190 Operands.erase(Operands.begin() + 5);
5191 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5199 // Validate context-sensitive operand constraints.
5201 // return 'true' if register list contains non-low GPR registers,
5202 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5203 // 'containsReg' to true.
5204 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5205 unsigned HiReg, bool &containsReg) {
5206 containsReg = false;
5207 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5208 unsigned OpReg = Inst.getOperand(i).getReg();
5211 // Anything other than a low register isn't legal here.
5212 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5218 // Check if the specified regisgter is in the register list of the inst,
5219 // starting at the indicated operand number.
5220 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5221 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5222 unsigned OpReg = Inst.getOperand(i).getReg();
5229 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5230 // the ARMInsts array) instead. Getting that here requires awkward
5231 // API changes, though. Better way?
5233 extern const MCInstrDesc ARMInsts[];
5235 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
5236 return ARMInsts[Opcode];
5239 // FIXME: We would really like to be able to tablegen'erate this.
5241 validateInstruction(MCInst &Inst,
5242 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5243 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
5244 SMLoc Loc = Operands[0]->getStartLoc();
5245 // Check the IT block state first.
5246 // NOTE: BKPT instruction has the interesting property of being
5247 // allowed in IT blocks, but not being predicable. It just always
5249 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5250 Inst.getOpcode() != ARM::BKPT) {
5252 if (ITState.FirstCond)
5253 ITState.FirstCond = false;
5255 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5256 // The instruction must be predicable.
5257 if (!MCID.isPredicable())
5258 return Error(Loc, "instructions in IT block must be predicable");
5259 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5260 unsigned ITCond = bit ? ITState.Cond :
5261 ARMCC::getOppositeCondition(ITState.Cond);
5262 if (Cond != ITCond) {
5263 // Find the condition code Operand to get its SMLoc information.
5265 for (unsigned i = 1; i < Operands.size(); ++i)
5266 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5267 CondLoc = Operands[i]->getStartLoc();
5268 return Error(CondLoc, "incorrect condition in IT block; got '" +
5269 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5270 "', but expected '" +
5271 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5273 // Check for non-'al' condition codes outside of the IT block.
5274 } else if (isThumbTwo() && MCID.isPredicable() &&
5275 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5276 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5277 Inst.getOpcode() != ARM::t2B)
5278 return Error(Loc, "predicated instructions must be in IT block");
5280 switch (Inst.getOpcode()) {
5283 case ARM::LDRD_POST:
5285 // Rt2 must be Rt + 1.
5286 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5287 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5289 return Error(Operands[3]->getStartLoc(),
5290 "destination operands must be sequential");
5294 // Rt2 must be Rt + 1.
5295 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5296 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5298 return Error(Operands[3]->getStartLoc(),
5299 "source operands must be sequential");
5303 case ARM::STRD_POST:
5305 // Rt2 must be Rt + 1.
5306 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5307 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5309 return Error(Operands[3]->getStartLoc(),
5310 "source operands must be sequential");
5315 // width must be in range [1, 32-lsb]
5316 unsigned lsb = Inst.getOperand(2).getImm();
5317 unsigned widthm1 = Inst.getOperand(3).getImm();
5318 if (widthm1 >= 32 - lsb)
5319 return Error(Operands[5]->getStartLoc(),
5320 "bitfield width must be in range [1,32-lsb]");
5324 // If we're parsing Thumb2, the .w variant is available and handles
5325 // most cases that are normally illegal for a Thumb1 LDM
5326 // instruction. We'll make the transformation in processInstruction()
5329 // Thumb LDM instructions are writeback iff the base register is not
5330 // in the register list.
5331 unsigned Rn = Inst.getOperand(0).getReg();
5332 bool hasWritebackToken =
5333 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5334 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5335 bool listContainsBase;
5336 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5337 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5338 "registers must be in range r0-r7");
5339 // If we should have writeback, then there should be a '!' token.
5340 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5341 return Error(Operands[2]->getStartLoc(),
5342 "writeback operator '!' expected");
5343 // If we should not have writeback, there must not be a '!'. This is
5344 // true even for the 32-bit wide encodings.
5345 if (listContainsBase && hasWritebackToken)
5346 return Error(Operands[3]->getStartLoc(),
5347 "writeback operator '!' not allowed when base register "
5348 "in register list");
5352 case ARM::t2LDMIA_UPD: {
5353 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5354 return Error(Operands[4]->getStartLoc(),
5355 "writeback operator '!' not allowed when base register "
5356 "in register list");
5360 // The second source operand must be the same register as the destination
5363 // In this case, we must directly check the parsed operands because the
5364 // cvtThumbMultiply() function is written in such a way that it guarantees
5365 // this first statement is always true for the new Inst. Essentially, the
5366 // destination is unconditionally copied into the second source operand
5367 // without checking to see if it matches what we actually parsed.
5368 if (Operands.size() == 6 &&
5369 (((ARMOperand*)Operands[3])->getReg() !=
5370 ((ARMOperand*)Operands[5])->getReg()) &&
5371 (((ARMOperand*)Operands[3])->getReg() !=
5372 ((ARMOperand*)Operands[4])->getReg())) {
5373 return Error(Operands[3]->getStartLoc(),
5374 "destination register must match source register");
5378 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5379 // so only issue a diagnostic for thumb1. The instructions will be
5380 // switched to the t2 encodings in processInstruction() if necessary.
5382 bool listContainsBase;
5383 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5385 return Error(Operands[2]->getStartLoc(),
5386 "registers must be in range r0-r7 or pc");
5390 bool listContainsBase;
5391 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5393 return Error(Operands[2]->getStartLoc(),
5394 "registers must be in range r0-r7 or lr");
5397 case ARM::tSTMIA_UPD: {
5398 bool listContainsBase;
5399 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5400 return Error(Operands[4]->getStartLoc(),
5401 "registers must be in range r0-r7");
5404 case ARM::tADDrSP: {
5405 // If the non-SP source operand and the destination operand are not the
5406 // same, we need thumb2 (for the wide encoding), or we have an error.
5407 if (!isThumbTwo() &&
5408 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5409 return Error(Operands[4]->getStartLoc(),
5410 "source register must be the same as destination");
5419 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5421 default: llvm_unreachable("unexpected opcode!");
5423 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5424 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5425 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5426 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5427 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5428 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5429 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5430 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5431 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5434 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5435 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5436 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5437 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5438 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5440 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5441 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5442 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5443 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5444 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5446 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5447 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5448 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5449 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5450 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5453 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5454 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5455 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5456 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5457 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5458 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5459 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5460 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5461 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5462 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5463 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5464 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5465 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5466 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5467 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5470 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5471 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5472 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5473 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5474 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5475 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5476 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5477 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5478 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5479 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5480 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5481 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5482 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5483 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5484 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5485 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5486 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5487 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5490 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5491 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5492 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5493 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5494 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5495 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5496 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5497 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5498 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5499 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5500 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5501 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5502 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5503 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5504 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5507 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5508 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5509 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5510 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5511 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5512 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5513 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5514 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5515 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5516 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5517 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5518 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5519 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5520 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5521 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5522 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5523 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5524 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5528 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5530 default: llvm_unreachable("unexpected opcode!");
5532 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5533 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5534 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5535 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5536 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5537 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5538 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5539 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5540 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5543 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5544 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5545 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5546 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5547 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5548 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5549 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5550 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5551 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5552 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5553 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5554 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5555 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5556 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5557 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5560 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5561 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5562 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5563 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5564 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5565 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5566 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5567 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5568 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5569 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5570 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5571 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5572 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5573 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5574 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5575 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5576 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5577 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5580 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5581 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5582 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5583 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5584 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5585 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5586 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5587 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5588 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5589 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5590 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5591 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5592 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5593 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5594 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5597 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5598 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5599 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5600 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5601 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5602 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5603 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5604 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5605 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5606 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5607 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5608 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5609 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5610 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5611 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5612 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5613 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5614 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5617 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5618 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5619 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5620 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5621 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5622 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5623 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5624 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5625 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5626 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5627 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5628 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5629 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5630 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5631 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5634 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5635 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5636 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5637 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5638 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5639 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5640 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5641 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5642 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5643 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5644 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5645 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5646 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5647 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5648 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5649 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5650 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5651 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5654 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5655 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5656 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5657 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5658 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5659 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5660 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5661 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5662 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5663 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5664 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5665 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5666 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5667 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5668 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5669 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5670 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5671 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5676 processInstruction(MCInst &Inst,
5677 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5678 switch (Inst.getOpcode()) {
5679 // Aliases for alternate PC+imm syntax of LDR instructions.
5680 case ARM::t2LDRpcrel:
5681 Inst.setOpcode(ARM::t2LDRpci);
5683 case ARM::t2LDRBpcrel:
5684 Inst.setOpcode(ARM::t2LDRBpci);
5686 case ARM::t2LDRHpcrel:
5687 Inst.setOpcode(ARM::t2LDRHpci);
5689 case ARM::t2LDRSBpcrel:
5690 Inst.setOpcode(ARM::t2LDRSBpci);
5692 case ARM::t2LDRSHpcrel:
5693 Inst.setOpcode(ARM::t2LDRSHpci);
5695 // Handle NEON VST complex aliases.
5696 case ARM::VST1LNdWB_register_Asm_8:
5697 case ARM::VST1LNdWB_register_Asm_16:
5698 case ARM::VST1LNdWB_register_Asm_32: {
5700 // Shuffle the operands around so the lane index operand is in the
5703 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5704 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5705 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5706 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5707 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5708 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5709 TmpInst.addOperand(Inst.getOperand(1)); // lane
5710 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5711 TmpInst.addOperand(Inst.getOperand(6));
5716 case ARM::VST2LNdWB_register_Asm_8:
5717 case ARM::VST2LNdWB_register_Asm_16:
5718 case ARM::VST2LNdWB_register_Asm_32:
5719 case ARM::VST2LNqWB_register_Asm_16:
5720 case ARM::VST2LNqWB_register_Asm_32: {
5722 // Shuffle the operands around so the lane index operand is in the
5725 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5726 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5727 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5728 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5729 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5730 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5731 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5733 TmpInst.addOperand(Inst.getOperand(1)); // lane
5734 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5735 TmpInst.addOperand(Inst.getOperand(6));
5740 case ARM::VST3LNdWB_register_Asm_8:
5741 case ARM::VST3LNdWB_register_Asm_16:
5742 case ARM::VST3LNdWB_register_Asm_32:
5743 case ARM::VST3LNqWB_register_Asm_16:
5744 case ARM::VST3LNqWB_register_Asm_32: {
5746 // Shuffle the operands around so the lane index operand is in the
5749 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5750 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5751 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5752 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5753 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5754 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5755 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5759 TmpInst.addOperand(Inst.getOperand(1)); // lane
5760 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5761 TmpInst.addOperand(Inst.getOperand(6));
5766 case ARM::VST4LNdWB_register_Asm_8:
5767 case ARM::VST4LNdWB_register_Asm_16:
5768 case ARM::VST4LNdWB_register_Asm_32:
5769 case ARM::VST4LNqWB_register_Asm_16:
5770 case ARM::VST4LNqWB_register_Asm_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_wb
5777 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5778 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5779 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5780 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5783 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5785 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5787 TmpInst.addOperand(Inst.getOperand(1)); // lane
5788 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5789 TmpInst.addOperand(Inst.getOperand(6));
5794 case ARM::VST1LNdWB_fixed_Asm_8:
5795 case ARM::VST1LNdWB_fixed_Asm_16:
5796 case ARM::VST1LNdWB_fixed_Asm_32: {
5798 // Shuffle the operands around so the lane index operand is in the
5801 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5802 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5803 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5804 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5805 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5806 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5807 TmpInst.addOperand(Inst.getOperand(1)); // lane
5808 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5809 TmpInst.addOperand(Inst.getOperand(5));
5814 case ARM::VST2LNdWB_fixed_Asm_8:
5815 case ARM::VST2LNdWB_fixed_Asm_16:
5816 case ARM::VST2LNdWB_fixed_Asm_32:
5817 case ARM::VST2LNqWB_fixed_Asm_16:
5818 case ARM::VST2LNqWB_fixed_Asm_32: {
5820 // Shuffle the operands around so the lane index operand is in the
5823 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5824 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5825 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5826 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5827 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5828 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5829 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5831 TmpInst.addOperand(Inst.getOperand(1)); // lane
5832 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5833 TmpInst.addOperand(Inst.getOperand(5));
5838 case ARM::VST3LNdWB_fixed_Asm_8:
5839 case ARM::VST3LNdWB_fixed_Asm_16:
5840 case ARM::VST3LNdWB_fixed_Asm_32:
5841 case ARM::VST3LNqWB_fixed_Asm_16:
5842 case ARM::VST3LNqWB_fixed_Asm_32: {
5844 // Shuffle the operands around so the lane index operand is in the
5847 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5848 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5849 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5850 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5851 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5852 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5853 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5855 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5857 TmpInst.addOperand(Inst.getOperand(1)); // lane
5858 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5859 TmpInst.addOperand(Inst.getOperand(5));
5864 case ARM::VST4LNdWB_fixed_Asm_8:
5865 case ARM::VST4LNdWB_fixed_Asm_16:
5866 case ARM::VST4LNdWB_fixed_Asm_32:
5867 case ARM::VST4LNqWB_fixed_Asm_16:
5868 case ARM::VST4LNqWB_fixed_Asm_32: {
5870 // Shuffle the operands around so the lane index operand is in the
5873 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5874 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5875 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5876 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5877 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5878 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5881 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5883 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5885 TmpInst.addOperand(Inst.getOperand(1)); // lane
5886 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5887 TmpInst.addOperand(Inst.getOperand(5));
5892 case ARM::VST1LNdAsm_8:
5893 case ARM::VST1LNdAsm_16:
5894 case ARM::VST1LNdAsm_32: {
5896 // Shuffle the operands around so the lane index operand is in the
5899 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5900 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5901 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5902 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5903 TmpInst.addOperand(Inst.getOperand(1)); // lane
5904 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5905 TmpInst.addOperand(Inst.getOperand(5));
5910 case ARM::VST2LNdAsm_8:
5911 case ARM::VST2LNdAsm_16:
5912 case ARM::VST2LNdAsm_32:
5913 case ARM::VST2LNqAsm_16:
5914 case ARM::VST2LNqAsm_32: {
5916 // Shuffle the operands around so the lane index operand is in the
5919 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5920 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5921 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5922 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5923 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5925 TmpInst.addOperand(Inst.getOperand(1)); // lane
5926 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5927 TmpInst.addOperand(Inst.getOperand(5));
5932 case ARM::VST3LNdAsm_8:
5933 case ARM::VST3LNdAsm_16:
5934 case ARM::VST3LNdAsm_32:
5935 case ARM::VST3LNqAsm_16:
5936 case ARM::VST3LNqAsm_32: {
5938 // Shuffle the operands around so the lane index operand is in the
5941 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5942 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5943 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5944 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5945 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5947 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5949 TmpInst.addOperand(Inst.getOperand(1)); // lane
5950 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5951 TmpInst.addOperand(Inst.getOperand(5));
5956 case ARM::VST4LNdAsm_8:
5957 case ARM::VST4LNdAsm_16:
5958 case ARM::VST4LNdAsm_32:
5959 case ARM::VST4LNqAsm_16:
5960 case ARM::VST4LNqAsm_32: {
5962 // Shuffle the operands around so the lane index operand is in the
5965 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5966 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5967 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5968 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5969 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5971 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5973 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5975 TmpInst.addOperand(Inst.getOperand(1)); // lane
5976 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5977 TmpInst.addOperand(Inst.getOperand(5));
5982 // Handle NEON VLD complex aliases.
5983 case ARM::VLD1LNdWB_register_Asm_8:
5984 case ARM::VLD1LNdWB_register_Asm_16:
5985 case ARM::VLD1LNdWB_register_Asm_32: {
5987 // Shuffle the operands around so the lane index operand is in the
5990 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5991 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5992 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5993 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5994 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5995 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5996 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5997 TmpInst.addOperand(Inst.getOperand(1)); // lane
5998 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5999 TmpInst.addOperand(Inst.getOperand(6));
6004 case ARM::VLD2LNdWB_register_Asm_8:
6005 case ARM::VLD2LNdWB_register_Asm_16:
6006 case ARM::VLD2LNdWB_register_Asm_32:
6007 case ARM::VLD2LNqWB_register_Asm_16:
6008 case ARM::VLD2LNqWB_register_Asm_32: {
6010 // Shuffle the operands around so the lane index operand is in the
6013 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6014 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6015 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6017 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6018 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6019 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6020 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6021 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6022 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6024 TmpInst.addOperand(Inst.getOperand(1)); // lane
6025 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6026 TmpInst.addOperand(Inst.getOperand(6));
6031 case ARM::VLD3LNdWB_register_Asm_8:
6032 case ARM::VLD3LNdWB_register_Asm_16:
6033 case ARM::VLD3LNdWB_register_Asm_32:
6034 case ARM::VLD3LNqWB_register_Asm_16:
6035 case ARM::VLD3LNqWB_register_Asm_32: {
6037 // Shuffle the operands around so the lane index operand is in the
6040 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6041 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6042 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6044 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6046 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6047 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6048 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6049 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6050 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6051 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6053 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6055 TmpInst.addOperand(Inst.getOperand(1)); // lane
6056 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6057 TmpInst.addOperand(Inst.getOperand(6));
6062 case ARM::VLD4LNdWB_register_Asm_8:
6063 case ARM::VLD4LNdWB_register_Asm_16:
6064 case ARM::VLD4LNdWB_register_Asm_32:
6065 case ARM::VLD4LNqWB_register_Asm_16:
6066 case ARM::VLD4LNqWB_register_Asm_32: {
6068 // Shuffle the operands around so the lane index operand is in the
6071 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6072 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6073 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6075 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6077 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6079 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6080 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6081 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6082 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6083 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6084 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6086 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6088 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6090 TmpInst.addOperand(Inst.getOperand(1)); // lane
6091 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6092 TmpInst.addOperand(Inst.getOperand(6));
6097 case ARM::VLD1LNdWB_fixed_Asm_8:
6098 case ARM::VLD1LNdWB_fixed_Asm_16:
6099 case ARM::VLD1LNdWB_fixed_Asm_32: {
6101 // Shuffle the operands around so the lane index operand is in the
6104 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6105 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6106 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6107 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6108 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6109 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6110 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6111 TmpInst.addOperand(Inst.getOperand(1)); // lane
6112 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6113 TmpInst.addOperand(Inst.getOperand(5));
6118 case ARM::VLD2LNdWB_fixed_Asm_8:
6119 case ARM::VLD2LNdWB_fixed_Asm_16:
6120 case ARM::VLD2LNdWB_fixed_Asm_32:
6121 case ARM::VLD2LNqWB_fixed_Asm_16:
6122 case ARM::VLD2LNqWB_fixed_Asm_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(Inst.getOperand(2)); // Rn_wb
6132 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6133 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6134 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6135 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6136 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6138 TmpInst.addOperand(Inst.getOperand(1)); // lane
6139 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6140 TmpInst.addOperand(Inst.getOperand(5));
6145 case ARM::VLD3LNdWB_fixed_Asm_8:
6146 case ARM::VLD3LNdWB_fixed_Asm_16:
6147 case ARM::VLD3LNdWB_fixed_Asm_32:
6148 case ARM::VLD3LNqWB_fixed_Asm_16:
6149 case ARM::VLD3LNqWB_fixed_Asm_32: {
6151 // Shuffle the operands around so the lane index operand is in the
6154 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6155 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6156 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6158 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6160 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6161 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6162 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6163 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6164 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6165 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6167 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6169 TmpInst.addOperand(Inst.getOperand(1)); // lane
6170 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6171 TmpInst.addOperand(Inst.getOperand(5));
6176 case ARM::VLD4LNdWB_fixed_Asm_8:
6177 case ARM::VLD4LNdWB_fixed_Asm_16:
6178 case ARM::VLD4LNdWB_fixed_Asm_32:
6179 case ARM::VLD4LNqWB_fixed_Asm_16:
6180 case ARM::VLD4LNqWB_fixed_Asm_32: {
6182 // Shuffle the operands around so the lane index operand is in the
6185 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6186 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6187 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6191 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6193 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6194 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6195 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6196 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6197 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6198 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6200 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6202 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6204 TmpInst.addOperand(Inst.getOperand(1)); // lane
6205 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6206 TmpInst.addOperand(Inst.getOperand(5));
6211 case ARM::VLD1LNdAsm_8:
6212 case ARM::VLD1LNdAsm_16:
6213 case ARM::VLD1LNdAsm_32: {
6215 // Shuffle the operands around so the lane index operand is in the
6218 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6219 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6220 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6221 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6222 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6223 TmpInst.addOperand(Inst.getOperand(1)); // lane
6224 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6225 TmpInst.addOperand(Inst.getOperand(5));
6230 case ARM::VLD2LNdAsm_8:
6231 case ARM::VLD2LNdAsm_16:
6232 case ARM::VLD2LNdAsm_32:
6233 case ARM::VLD2LNqAsm_16:
6234 case ARM::VLD2LNqAsm_32: {
6236 // Shuffle the operands around so the lane index operand is in the
6239 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6240 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6241 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6243 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6244 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6245 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6246 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6248 TmpInst.addOperand(Inst.getOperand(1)); // lane
6249 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6250 TmpInst.addOperand(Inst.getOperand(5));
6255 case ARM::VLD3LNdAsm_8:
6256 case ARM::VLD3LNdAsm_16:
6257 case ARM::VLD3LNdAsm_32:
6258 case ARM::VLD3LNqAsm_16:
6259 case ARM::VLD3LNqAsm_32: {
6261 // Shuffle the operands around so the lane index operand is in the
6264 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6265 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6266 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6268 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6270 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6271 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6272 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6273 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6275 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6277 TmpInst.addOperand(Inst.getOperand(1)); // lane
6278 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6279 TmpInst.addOperand(Inst.getOperand(5));
6284 case ARM::VLD4LNdAsm_8:
6285 case ARM::VLD4LNdAsm_16:
6286 case ARM::VLD4LNdAsm_32:
6287 case ARM::VLD4LNqAsm_16:
6288 case ARM::VLD4LNqAsm_32: {
6290 // Shuffle the operands around so the lane index operand is in the
6293 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6294 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6295 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6297 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6299 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6301 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6302 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6303 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== 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)); // lane
6311 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6312 TmpInst.addOperand(Inst.getOperand(5));
6317 // VLD3DUP single 3-element structure to all lanes instructions.
6318 case ARM::VLD3DUPdAsm_8:
6319 case ARM::VLD3DUPdAsm_16:
6320 case ARM::VLD3DUPdAsm_32:
6321 case ARM::VLD3DUPqAsm_8:
6322 case ARM::VLD3DUPqAsm_16:
6323 case ARM::VLD3DUPqAsm_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(Inst.getOperand(1)); // Rn
6333 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6334 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6335 TmpInst.addOperand(Inst.getOperand(4));
6340 case ARM::VLD3DUPdWB_fixed_Asm_8:
6341 case ARM::VLD3DUPdWB_fixed_Asm_16:
6342 case ARM::VLD3DUPdWB_fixed_Asm_32:
6343 case ARM::VLD3DUPqWB_fixed_Asm_8:
6344 case ARM::VLD3DUPqWB_fixed_Asm_16:
6345 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6348 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6349 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6350 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6352 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6354 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6355 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6356 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6357 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6358 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6359 TmpInst.addOperand(Inst.getOperand(4));
6364 case ARM::VLD3DUPdWB_register_Asm_8:
6365 case ARM::VLD3DUPdWB_register_Asm_16:
6366 case ARM::VLD3DUPdWB_register_Asm_32:
6367 case ARM::VLD3DUPqWB_register_Asm_8:
6368 case ARM::VLD3DUPqWB_register_Asm_16:
6369 case ARM::VLD3DUPqWB_register_Asm_32: {
6372 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6373 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6374 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6376 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6378 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6379 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6380 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6381 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6382 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6383 TmpInst.addOperand(Inst.getOperand(5));
6388 // VLD3 multiple 3-element structure instructions.
6389 case ARM::VLD3dAsm_8:
6390 case ARM::VLD3dAsm_16:
6391 case ARM::VLD3dAsm_32:
6392 case ARM::VLD3qAsm_8:
6393 case ARM::VLD3qAsm_16:
6394 case ARM::VLD3qAsm_32: {
6397 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6398 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6399 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6401 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6403 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6404 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6405 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6406 TmpInst.addOperand(Inst.getOperand(4));
6411 case ARM::VLD3dWB_fixed_Asm_8:
6412 case ARM::VLD3dWB_fixed_Asm_16:
6413 case ARM::VLD3dWB_fixed_Asm_32:
6414 case ARM::VLD3qWB_fixed_Asm_8:
6415 case ARM::VLD3qWB_fixed_Asm_16:
6416 case ARM::VLD3qWB_fixed_Asm_32: {
6419 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6420 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6421 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6423 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6425 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6426 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6427 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6428 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6429 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6430 TmpInst.addOperand(Inst.getOperand(4));
6435 case ARM::VLD3dWB_register_Asm_8:
6436 case ARM::VLD3dWB_register_Asm_16:
6437 case ARM::VLD3dWB_register_Asm_32:
6438 case ARM::VLD3qWB_register_Asm_8:
6439 case ARM::VLD3qWB_register_Asm_16:
6440 case ARM::VLD3qWB_register_Asm_32: {
6443 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6444 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6445 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6447 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6449 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6450 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6451 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6452 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6453 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6454 TmpInst.addOperand(Inst.getOperand(5));
6459 // VLD4DUP single 3-element structure to all lanes instructions.
6460 case ARM::VLD4DUPdAsm_8:
6461 case ARM::VLD4DUPdAsm_16:
6462 case ARM::VLD4DUPdAsm_32:
6463 case ARM::VLD4DUPqAsm_8:
6464 case ARM::VLD4DUPqAsm_16:
6465 case ARM::VLD4DUPqAsm_32: {
6468 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6469 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6470 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6472 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6474 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6476 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6477 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6478 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6479 TmpInst.addOperand(Inst.getOperand(4));
6484 case ARM::VLD4DUPdWB_fixed_Asm_8:
6485 case ARM::VLD4DUPdWB_fixed_Asm_16:
6486 case ARM::VLD4DUPdWB_fixed_Asm_32:
6487 case ARM::VLD4DUPqWB_fixed_Asm_8:
6488 case ARM::VLD4DUPqWB_fixed_Asm_16:
6489 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6492 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6493 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6494 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6496 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6498 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6500 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6501 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6502 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6503 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6504 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6505 TmpInst.addOperand(Inst.getOperand(4));
6510 case ARM::VLD4DUPdWB_register_Asm_8:
6511 case ARM::VLD4DUPdWB_register_Asm_16:
6512 case ARM::VLD4DUPdWB_register_Asm_32:
6513 case ARM::VLD4DUPqWB_register_Asm_8:
6514 case ARM::VLD4DUPqWB_register_Asm_16:
6515 case ARM::VLD4DUPqWB_register_Asm_32: {
6518 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6519 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6520 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6522 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6524 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6526 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6527 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6528 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6529 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6530 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6531 TmpInst.addOperand(Inst.getOperand(5));
6536 // VLD4 multiple 4-element structure instructions.
6537 case ARM::VLD4dAsm_8:
6538 case ARM::VLD4dAsm_16:
6539 case ARM::VLD4dAsm_32:
6540 case ARM::VLD4qAsm_8:
6541 case ARM::VLD4qAsm_16:
6542 case ARM::VLD4qAsm_32: {
6545 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6546 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6547 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6549 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6551 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6553 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6554 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6555 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6556 TmpInst.addOperand(Inst.getOperand(4));
6561 case ARM::VLD4dWB_fixed_Asm_8:
6562 case ARM::VLD4dWB_fixed_Asm_16:
6563 case ARM::VLD4dWB_fixed_Asm_32:
6564 case ARM::VLD4qWB_fixed_Asm_8:
6565 case ARM::VLD4qWB_fixed_Asm_16:
6566 case ARM::VLD4qWB_fixed_Asm_32: {
6569 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6570 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6571 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6573 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6575 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6577 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6578 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6579 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6580 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6581 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6582 TmpInst.addOperand(Inst.getOperand(4));
6587 case ARM::VLD4dWB_register_Asm_8:
6588 case ARM::VLD4dWB_register_Asm_16:
6589 case ARM::VLD4dWB_register_Asm_32:
6590 case ARM::VLD4qWB_register_Asm_8:
6591 case ARM::VLD4qWB_register_Asm_16:
6592 case ARM::VLD4qWB_register_Asm_32: {
6595 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6596 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6599 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6601 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6603 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6604 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6605 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6606 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6607 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6608 TmpInst.addOperand(Inst.getOperand(5));
6613 // VST3 multiple 3-element structure instructions.
6614 case ARM::VST3dAsm_8:
6615 case ARM::VST3dAsm_16:
6616 case ARM::VST3dAsm_32:
6617 case ARM::VST3qAsm_8:
6618 case ARM::VST3qAsm_16:
6619 case ARM::VST3qAsm_32: {
6622 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6623 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6624 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6625 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6626 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6628 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6630 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6631 TmpInst.addOperand(Inst.getOperand(4));
6636 case ARM::VST3dWB_fixed_Asm_8:
6637 case ARM::VST3dWB_fixed_Asm_16:
6638 case ARM::VST3dWB_fixed_Asm_32:
6639 case ARM::VST3qWB_fixed_Asm_8:
6640 case ARM::VST3qWB_fixed_Asm_16:
6641 case ARM::VST3qWB_fixed_Asm_32: {
6644 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6645 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6646 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6647 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6648 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6649 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6650 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6652 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6654 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6655 TmpInst.addOperand(Inst.getOperand(4));
6660 case ARM::VST3dWB_register_Asm_8:
6661 case ARM::VST3dWB_register_Asm_16:
6662 case ARM::VST3dWB_register_Asm_32:
6663 case ARM::VST3qWB_register_Asm_8:
6664 case ARM::VST3qWB_register_Asm_16:
6665 case ARM::VST3qWB_register_Asm_32: {
6668 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6669 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6670 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6671 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6672 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6673 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6678 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6679 TmpInst.addOperand(Inst.getOperand(5));
6684 // VST4 multiple 3-element structure instructions.
6685 case ARM::VST4dAsm_8:
6686 case ARM::VST4dAsm_16:
6687 case ARM::VST4dAsm_32:
6688 case ARM::VST4qAsm_8:
6689 case ARM::VST4qAsm_16:
6690 case ARM::VST4qAsm_32: {
6693 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6694 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6695 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6696 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6697 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6699 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6701 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6703 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6704 TmpInst.addOperand(Inst.getOperand(4));
6709 case ARM::VST4dWB_fixed_Asm_8:
6710 case ARM::VST4dWB_fixed_Asm_16:
6711 case ARM::VST4dWB_fixed_Asm_32:
6712 case ARM::VST4qWB_fixed_Asm_8:
6713 case ARM::VST4qWB_fixed_Asm_16:
6714 case ARM::VST4qWB_fixed_Asm_32: {
6717 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6718 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6719 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6720 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6721 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6722 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6723 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6725 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6727 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6729 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6730 TmpInst.addOperand(Inst.getOperand(4));
6735 case ARM::VST4dWB_register_Asm_8:
6736 case ARM::VST4dWB_register_Asm_16:
6737 case ARM::VST4dWB_register_Asm_32:
6738 case ARM::VST4qWB_register_Asm_8:
6739 case ARM::VST4qWB_register_Asm_16:
6740 case ARM::VST4qWB_register_Asm_32: {
6743 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6744 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6745 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6746 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6747 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6748 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6749 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6751 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6755 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6756 TmpInst.addOperand(Inst.getOperand(5));
6761 // Handle encoding choice for the shift-immediate instructions.
6764 case ARM::t2ASRri: {
6765 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6766 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6767 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6768 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6769 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6771 switch (Inst.getOpcode()) {
6772 default: llvm_unreachable("unexpected opcode");
6773 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6774 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6775 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6777 // The Thumb1 operands aren't in the same order. Awesome, eh?
6779 TmpInst.setOpcode(NewOpc);
6780 TmpInst.addOperand(Inst.getOperand(0));
6781 TmpInst.addOperand(Inst.getOperand(5));
6782 TmpInst.addOperand(Inst.getOperand(1));
6783 TmpInst.addOperand(Inst.getOperand(2));
6784 TmpInst.addOperand(Inst.getOperand(3));
6785 TmpInst.addOperand(Inst.getOperand(4));
6792 // Handle the Thumb2 mode MOV complex aliases.
6794 case ARM::t2MOVSsr: {
6795 // Which instruction to expand to depends on the CCOut operand and
6796 // whether we're in an IT block if the register operands are low
6798 bool isNarrow = false;
6799 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6800 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6801 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6802 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6803 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6807 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6808 default: llvm_unreachable("unexpected opcode!");
6809 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6810 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6811 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6812 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6814 TmpInst.setOpcode(newOpc);
6815 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6817 TmpInst.addOperand(MCOperand::CreateReg(
6818 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6819 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6820 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6821 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6822 TmpInst.addOperand(Inst.getOperand(5));
6824 TmpInst.addOperand(MCOperand::CreateReg(
6825 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6830 case ARM::t2MOVSsi: {
6831 // Which instruction to expand to depends on the CCOut operand and
6832 // whether we're in an IT block if the register operands are low
6834 bool isNarrow = false;
6835 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6836 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6837 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6841 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6842 default: llvm_unreachable("unexpected opcode!");
6843 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6844 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6845 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6846 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
6847 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
6849 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6850 if (Amount == 32) Amount = 0;
6851 TmpInst.setOpcode(newOpc);
6852 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6854 TmpInst.addOperand(MCOperand::CreateReg(
6855 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6856 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6857 if (newOpc != ARM::t2RRX)
6858 TmpInst.addOperand(MCOperand::CreateImm(Amount));
6859 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6860 TmpInst.addOperand(Inst.getOperand(4));
6862 TmpInst.addOperand(MCOperand::CreateReg(
6863 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6867 // Handle the ARM mode MOV complex aliases.
6872 ARM_AM::ShiftOpc ShiftTy;
6873 switch(Inst.getOpcode()) {
6874 default: llvm_unreachable("unexpected opcode!");
6875 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6876 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6877 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6878 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6880 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6882 TmpInst.setOpcode(ARM::MOVsr);
6883 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6884 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6885 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6886 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6887 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6888 TmpInst.addOperand(Inst.getOperand(4));
6889 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6897 ARM_AM::ShiftOpc ShiftTy;
6898 switch(Inst.getOpcode()) {
6899 default: llvm_unreachable("unexpected opcode!");
6900 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6901 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6902 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6903 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6905 // A shift by zero is a plain MOVr, not a MOVsi.
6906 unsigned Amt = Inst.getOperand(2).getImm();
6907 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
6908 // A shift by 32 should be encoded as 0 when permitted
6909 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6911 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
6913 TmpInst.setOpcode(Opc);
6914 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6915 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6916 if (Opc == ARM::MOVsi)
6917 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6918 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6919 TmpInst.addOperand(Inst.getOperand(4));
6920 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6925 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6927 TmpInst.setOpcode(ARM::MOVsi);
6928 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6929 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6930 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6931 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6932 TmpInst.addOperand(Inst.getOperand(3));
6933 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6937 case ARM::t2LDMIA_UPD: {
6938 // If this is a load of a single register, then we should use
6939 // a post-indexed LDR instruction instead, per the ARM ARM.
6940 if (Inst.getNumOperands() != 5)
6943 TmpInst.setOpcode(ARM::t2LDR_POST);
6944 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6945 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6946 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6947 TmpInst.addOperand(MCOperand::CreateImm(4));
6948 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6949 TmpInst.addOperand(Inst.getOperand(3));
6953 case ARM::t2STMDB_UPD: {
6954 // If this is a store of a single register, then we should use
6955 // a pre-indexed STR instruction instead, per the ARM ARM.
6956 if (Inst.getNumOperands() != 5)
6959 TmpInst.setOpcode(ARM::t2STR_PRE);
6960 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6961 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6962 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6963 TmpInst.addOperand(MCOperand::CreateImm(-4));
6964 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6965 TmpInst.addOperand(Inst.getOperand(3));
6969 case ARM::LDMIA_UPD:
6970 // If this is a load of a single register via a 'pop', then we should use
6971 // a post-indexed LDR instruction instead, per the ARM ARM.
6972 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6973 Inst.getNumOperands() == 5) {
6975 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6976 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6977 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6978 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6979 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6980 TmpInst.addOperand(MCOperand::CreateImm(4));
6981 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6982 TmpInst.addOperand(Inst.getOperand(3));
6987 case ARM::STMDB_UPD:
6988 // If this is a store of a single register via a 'push', then we should use
6989 // a pre-indexed STR instruction instead, per the ARM ARM.
6990 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6991 Inst.getNumOperands() == 5) {
6993 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6994 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6995 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6996 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6997 TmpInst.addOperand(MCOperand::CreateImm(-4));
6998 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6999 TmpInst.addOperand(Inst.getOperand(3));
7003 case ARM::t2ADDri12:
7004 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7005 // mnemonic was used (not "addw"), encoding T3 is preferred.
7006 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7007 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7009 Inst.setOpcode(ARM::t2ADDri);
7010 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7012 case ARM::t2SUBri12:
7013 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7014 // mnemonic was used (not "subw"), encoding T3 is preferred.
7015 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7016 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7018 Inst.setOpcode(ARM::t2SUBri);
7019 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7022 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7023 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7024 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7025 // to encoding T1 if <Rd> is omitted."
7026 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7027 Inst.setOpcode(ARM::tADDi3);
7032 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7033 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7034 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7035 // to encoding T1 if <Rd> is omitted."
7036 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7037 Inst.setOpcode(ARM::tSUBi3);
7042 case ARM::t2SUBri: {
7043 // If the destination and first source operand are the same, and
7044 // the flags are compatible with the current IT status, use encoding T2
7045 // instead of T3. For compatibility with the system 'as'. Make sure the
7046 // wide encoding wasn't explicit.
7047 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7048 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7049 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7050 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7051 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7052 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7053 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7056 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7057 ARM::tADDi8 : ARM::tSUBi8);
7058 TmpInst.addOperand(Inst.getOperand(0));
7059 TmpInst.addOperand(Inst.getOperand(5));
7060 TmpInst.addOperand(Inst.getOperand(0));
7061 TmpInst.addOperand(Inst.getOperand(2));
7062 TmpInst.addOperand(Inst.getOperand(3));
7063 TmpInst.addOperand(Inst.getOperand(4));
7067 case ARM::t2ADDrr: {
7068 // If the destination and first source operand are the same, and
7069 // there's no setting of the flags, use encoding T2 instead of T3.
7070 // Note that this is only for ADD, not SUB. This mirrors the system
7071 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7072 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7073 Inst.getOperand(5).getReg() != 0 ||
7074 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7075 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7078 TmpInst.setOpcode(ARM::tADDhirr);
7079 TmpInst.addOperand(Inst.getOperand(0));
7080 TmpInst.addOperand(Inst.getOperand(0));
7081 TmpInst.addOperand(Inst.getOperand(2));
7082 TmpInst.addOperand(Inst.getOperand(3));
7083 TmpInst.addOperand(Inst.getOperand(4));
7087 case ARM::tADDrSP: {
7088 // If the non-SP source operand and the destination operand are not the
7089 // same, we need to use the 32-bit encoding if it's available.
7090 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7091 Inst.setOpcode(ARM::t2ADDrr);
7092 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7098 // A Thumb conditional branch outside of an IT block is a tBcc.
7099 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7100 Inst.setOpcode(ARM::tBcc);
7105 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7106 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7107 Inst.setOpcode(ARM::t2Bcc);
7112 // If the conditional is AL or we're in an IT block, we really want t2B.
7113 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7114 Inst.setOpcode(ARM::t2B);
7119 // If the conditional is AL, we really want tB.
7120 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7121 Inst.setOpcode(ARM::tB);
7126 // If the register list contains any high registers, or if the writeback
7127 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7128 // instead if we're in Thumb2. Otherwise, this should have generated
7129 // an error in validateInstruction().
7130 unsigned Rn = Inst.getOperand(0).getReg();
7131 bool hasWritebackToken =
7132 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7133 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7134 bool listContainsBase;
7135 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7136 (!listContainsBase && !hasWritebackToken) ||
7137 (listContainsBase && hasWritebackToken)) {
7138 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7139 assert (isThumbTwo());
7140 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7141 // If we're switching to the updating version, we need to insert
7142 // the writeback tied operand.
7143 if (hasWritebackToken)
7144 Inst.insert(Inst.begin(),
7145 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7150 case ARM::tSTMIA_UPD: {
7151 // If the register list contains any high registers, we need to use
7152 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7153 // should have generated an error in validateInstruction().
7154 unsigned Rn = Inst.getOperand(0).getReg();
7155 bool listContainsBase;
7156 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7157 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7158 assert (isThumbTwo());
7159 Inst.setOpcode(ARM::t2STMIA_UPD);
7165 bool listContainsBase;
7166 // If the register list contains any high registers, we need to use
7167 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7168 // should have generated an error in validateInstruction().
7169 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7171 assert (isThumbTwo());
7172 Inst.setOpcode(ARM::t2LDMIA_UPD);
7173 // Add the base register and writeback operands.
7174 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7175 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7179 bool listContainsBase;
7180 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7182 assert (isThumbTwo());
7183 Inst.setOpcode(ARM::t2STMDB_UPD);
7184 // Add the base register and writeback operands.
7185 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7186 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7190 // If we can use the 16-bit encoding and the user didn't explicitly
7191 // request the 32-bit variant, transform it here.
7192 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7193 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7194 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7195 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7196 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7197 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7198 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7199 // The operands aren't in the same order for tMOVi8...
7201 TmpInst.setOpcode(ARM::tMOVi8);
7202 TmpInst.addOperand(Inst.getOperand(0));
7203 TmpInst.addOperand(Inst.getOperand(4));
7204 TmpInst.addOperand(Inst.getOperand(1));
7205 TmpInst.addOperand(Inst.getOperand(2));
7206 TmpInst.addOperand(Inst.getOperand(3));
7213 // If we can use the 16-bit encoding and the user didn't explicitly
7214 // request the 32-bit variant, transform it here.
7215 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7216 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7217 Inst.getOperand(2).getImm() == ARMCC::AL &&
7218 Inst.getOperand(4).getReg() == ARM::CPSR &&
7219 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7220 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7221 // The operands aren't the same for tMOV[S]r... (no cc_out)
7223 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7224 TmpInst.addOperand(Inst.getOperand(0));
7225 TmpInst.addOperand(Inst.getOperand(1));
7226 TmpInst.addOperand(Inst.getOperand(2));
7227 TmpInst.addOperand(Inst.getOperand(3));
7237 // If we can use the 16-bit encoding and the user didn't explicitly
7238 // request the 32-bit variant, transform it here.
7239 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7240 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7241 Inst.getOperand(2).getImm() == 0 &&
7242 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7243 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7245 switch (Inst.getOpcode()) {
7246 default: llvm_unreachable("Illegal opcode!");
7247 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7248 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7249 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7250 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7252 // The operands aren't the same for thumb1 (no rotate operand).
7254 TmpInst.setOpcode(NewOpc);
7255 TmpInst.addOperand(Inst.getOperand(0));
7256 TmpInst.addOperand(Inst.getOperand(1));
7257 TmpInst.addOperand(Inst.getOperand(3));
7258 TmpInst.addOperand(Inst.getOperand(4));
7265 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7266 // rrx shifts and asr/lsr of #32 is encoded as 0
7267 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7269 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7270 // Shifting by zero is accepted as a vanilla 'MOVr'
7272 TmpInst.setOpcode(ARM::MOVr);
7273 TmpInst.addOperand(Inst.getOperand(0));
7274 TmpInst.addOperand(Inst.getOperand(1));
7275 TmpInst.addOperand(Inst.getOperand(3));
7276 TmpInst.addOperand(Inst.getOperand(4));
7277 TmpInst.addOperand(Inst.getOperand(5));
7290 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7291 if (SOpc == ARM_AM::rrx) return false;
7292 switch (Inst.getOpcode()) {
7293 default: llvm_unreachable("unexpected opcode!");
7294 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7295 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7296 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7297 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7298 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7299 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7301 // If the shift is by zero, use the non-shifted instruction definition.
7302 // The exception is for right shifts, where 0 == 32
7303 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7304 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7306 TmpInst.setOpcode(newOpc);
7307 TmpInst.addOperand(Inst.getOperand(0));
7308 TmpInst.addOperand(Inst.getOperand(1));
7309 TmpInst.addOperand(Inst.getOperand(2));
7310 TmpInst.addOperand(Inst.getOperand(4));
7311 TmpInst.addOperand(Inst.getOperand(5));
7312 TmpInst.addOperand(Inst.getOperand(6));
7320 // The mask bits for all but the first condition are represented as
7321 // the low bit of the condition code value implies 't'. We currently
7322 // always have 1 implies 't', so XOR toggle the bits if the low bit
7323 // of the condition code is zero.
7324 MCOperand &MO = Inst.getOperand(1);
7325 unsigned Mask = MO.getImm();
7326 unsigned OrigMask = Mask;
7327 unsigned TZ = CountTrailingZeros_32(Mask);
7328 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7329 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7330 for (unsigned i = 3; i != TZ; --i)
7335 // Set up the IT block state according to the IT instruction we just
7337 assert(!inITBlock() && "nested IT blocks?!");
7338 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7339 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7340 ITState.CurPosition = 0;
7341 ITState.FirstCond = true;
7351 // Assemblers should use the narrow encodings of these instructions when permissible.
7352 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7353 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7354 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7355 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7356 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7357 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7358 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7360 switch (Inst.getOpcode()) {
7361 default: llvm_unreachable("unexpected opcode");
7362 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7363 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7364 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7365 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7366 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7367 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7370 TmpInst.setOpcode(NewOpc);
7371 TmpInst.addOperand(Inst.getOperand(0));
7372 TmpInst.addOperand(Inst.getOperand(5));
7373 TmpInst.addOperand(Inst.getOperand(1));
7374 TmpInst.addOperand(Inst.getOperand(2));
7375 TmpInst.addOperand(Inst.getOperand(3));
7376 TmpInst.addOperand(Inst.getOperand(4));
7387 // Assemblers should use the narrow encodings of these instructions when permissible.
7388 // These instructions are special in that they are commutable, so shorter encodings
7389 // are available more often.
7390 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7391 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7392 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7393 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7394 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7395 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7396 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7397 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7399 switch (Inst.getOpcode()) {
7400 default: llvm_unreachable("unexpected opcode");
7401 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7402 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7403 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7404 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7407 TmpInst.setOpcode(NewOpc);
7408 TmpInst.addOperand(Inst.getOperand(0));
7409 TmpInst.addOperand(Inst.getOperand(5));
7410 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7411 TmpInst.addOperand(Inst.getOperand(1));
7412 TmpInst.addOperand(Inst.getOperand(2));
7414 TmpInst.addOperand(Inst.getOperand(2));
7415 TmpInst.addOperand(Inst.getOperand(1));
7417 TmpInst.addOperand(Inst.getOperand(3));
7418 TmpInst.addOperand(Inst.getOperand(4));
7428 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7429 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7430 // suffix depending on whether they're in an IT block or not.
7431 unsigned Opc = Inst.getOpcode();
7432 const MCInstrDesc &MCID = getInstDesc(Opc);
7433 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7434 assert(MCID.hasOptionalDef() &&
7435 "optionally flag setting instruction missing optional def operand");
7436 assert(MCID.NumOperands == Inst.getNumOperands() &&
7437 "operand count mismatch!");
7438 // Find the optional-def operand (cc_out).
7441 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7444 // If we're parsing Thumb1, reject it completely.
7445 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7446 return Match_MnemonicFail;
7447 // If we're parsing Thumb2, which form is legal depends on whether we're
7449 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7451 return Match_RequiresITBlock;
7452 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7454 return Match_RequiresNotITBlock;
7456 // Some high-register supporting Thumb1 encodings only allow both registers
7457 // to be from r0-r7 when in Thumb2.
7458 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7459 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7460 isARMLowRegister(Inst.getOperand(2).getReg()))
7461 return Match_RequiresThumb2;
7462 // Others only require ARMv6 or later.
7463 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7464 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7465 isARMLowRegister(Inst.getOperand(1).getReg()))
7466 return Match_RequiresV6;
7467 return Match_Success;
7470 static const char *getSubtargetFeatureName(unsigned Val);
7472 MatchAndEmitInstruction(SMLoc IDLoc,
7473 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7478 unsigned MatchResult;
7480 MatchResult = MatchInstructionImpl(Operands, Kind, Inst, ErrorInfo);
7481 switch (MatchResult) {
7484 // Context sensitive operand constraints aren't handled by the matcher,
7485 // so check them here.
7486 if (validateInstruction(Inst, Operands)) {
7487 // Still progress the IT block, otherwise one wrong condition causes
7488 // nasty cascading errors.
7489 forwardITPosition();
7493 // Some instructions need post-processing to, for example, tweak which
7494 // encoding is selected. Loop on it while changes happen so the
7495 // individual transformations can chain off each other. E.g.,
7496 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7497 while (processInstruction(Inst, Operands))
7500 // Only move forward at the very end so that everything in validate
7501 // and process gets a consistent answer about whether we're in an IT
7503 forwardITPosition();
7505 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7506 // doesn't actually encode.
7507 if (Inst.getOpcode() == ARM::ITasm)
7511 Out.EmitInstruction(Inst);
7513 case Match_MissingFeature: {
7514 assert(ErrorInfo && "Unknown missing feature!");
7515 // Special case the error message for the very common case where only
7516 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7517 std::string Msg = "instruction requires:";
7519 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7520 if (ErrorInfo & Mask) {
7522 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7526 return Error(IDLoc, Msg);
7528 case Match_InvalidOperand: {
7529 SMLoc ErrorLoc = IDLoc;
7530 if (ErrorInfo != ~0U) {
7531 if (ErrorInfo >= Operands.size())
7532 return Error(IDLoc, "too few operands for instruction");
7534 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7535 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7538 return Error(ErrorLoc, "invalid operand for instruction");
7540 case Match_MnemonicFail:
7541 return Error(IDLoc, "invalid instruction",
7542 ((ARMOperand*)Operands[0])->getLocRange());
7543 case Match_RequiresNotITBlock:
7544 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7545 case Match_RequiresITBlock:
7546 return Error(IDLoc, "instruction only valid inside IT block");
7547 case Match_RequiresV6:
7548 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7549 case Match_RequiresThumb2:
7550 return Error(IDLoc, "instruction variant requires Thumb2");
7551 case Match_ImmRange0_15: {
7552 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7553 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7554 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7558 llvm_unreachable("Implement any new match types added!");
7561 /// parseDirective parses the arm specific directives
7562 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7563 StringRef IDVal = DirectiveID.getIdentifier();
7564 if (IDVal == ".word")
7565 return parseDirectiveWord(4, DirectiveID.getLoc());
7566 else if (IDVal == ".thumb")
7567 return parseDirectiveThumb(DirectiveID.getLoc());
7568 else if (IDVal == ".arm")
7569 return parseDirectiveARM(DirectiveID.getLoc());
7570 else if (IDVal == ".thumb_func")
7571 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7572 else if (IDVal == ".code")
7573 return parseDirectiveCode(DirectiveID.getLoc());
7574 else if (IDVal == ".syntax")
7575 return parseDirectiveSyntax(DirectiveID.getLoc());
7576 else if (IDVal == ".unreq")
7577 return parseDirectiveUnreq(DirectiveID.getLoc());
7578 else if (IDVal == ".arch")
7579 return parseDirectiveArch(DirectiveID.getLoc());
7580 else if (IDVal == ".eabi_attribute")
7581 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7585 /// parseDirectiveWord
7586 /// ::= .word [ expression (, expression)* ]
7587 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7588 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7590 const MCExpr *Value;
7591 if (getParser().ParseExpression(Value))
7594 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
7596 if (getLexer().is(AsmToken::EndOfStatement))
7599 // FIXME: Improve diagnostic.
7600 if (getLexer().isNot(AsmToken::Comma))
7601 return Error(L, "unexpected token in directive");
7610 /// parseDirectiveThumb
7612 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7613 if (getLexer().isNot(AsmToken::EndOfStatement))
7614 return Error(L, "unexpected token in directive");
7619 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7623 /// parseDirectiveARM
7625 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7626 if (getLexer().isNot(AsmToken::EndOfStatement))
7627 return Error(L, "unexpected token in directive");
7632 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7636 /// parseDirectiveThumbFunc
7637 /// ::= .thumbfunc symbol_name
7638 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7639 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7640 bool isMachO = MAI.hasSubsectionsViaSymbols();
7642 bool needFuncName = true;
7644 // Darwin asm has (optionally) function name after .thumb_func direction
7647 const AsmToken &Tok = Parser.getTok();
7648 if (Tok.isNot(AsmToken::EndOfStatement)) {
7649 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7650 return Error(L, "unexpected token in .thumb_func directive");
7651 Name = Tok.getIdentifier();
7652 Parser.Lex(); // Consume the identifier token.
7653 needFuncName = false;
7657 if (getLexer().isNot(AsmToken::EndOfStatement))
7658 return Error(L, "unexpected token in directive");
7660 // Eat the end of statement and any blank lines that follow.
7661 while (getLexer().is(AsmToken::EndOfStatement))
7664 // FIXME: assuming function name will be the line following .thumb_func
7665 // We really should be checking the next symbol definition even if there's
7666 // stuff in between.
7668 Name = Parser.getTok().getIdentifier();
7671 // Mark symbol as a thumb symbol.
7672 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7673 getParser().getStreamer().EmitThumbFunc(Func);
7677 /// parseDirectiveSyntax
7678 /// ::= .syntax unified | divided
7679 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7680 const AsmToken &Tok = Parser.getTok();
7681 if (Tok.isNot(AsmToken::Identifier))
7682 return Error(L, "unexpected token in .syntax directive");
7683 StringRef Mode = Tok.getString();
7684 if (Mode == "unified" || Mode == "UNIFIED")
7686 else if (Mode == "divided" || Mode == "DIVIDED")
7687 return Error(L, "'.syntax divided' arm asssembly not supported");
7689 return Error(L, "unrecognized syntax mode in .syntax directive");
7691 if (getLexer().isNot(AsmToken::EndOfStatement))
7692 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7695 // TODO tell the MC streamer the mode
7696 // getParser().getStreamer().Emit???();
7700 /// parseDirectiveCode
7701 /// ::= .code 16 | 32
7702 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7703 const AsmToken &Tok = Parser.getTok();
7704 if (Tok.isNot(AsmToken::Integer))
7705 return Error(L, "unexpected token in .code directive");
7706 int64_t Val = Parser.getTok().getIntVal();
7712 return Error(L, "invalid operand to .code directive");
7714 if (getLexer().isNot(AsmToken::EndOfStatement))
7715 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7721 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7725 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7731 /// parseDirectiveReq
7732 /// ::= name .req registername
7733 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7734 Parser.Lex(); // Eat the '.req' token.
7736 SMLoc SRegLoc, ERegLoc;
7737 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7738 Parser.EatToEndOfStatement();
7739 return Error(SRegLoc, "register name expected");
7742 // Shouldn't be anything else.
7743 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7744 Parser.EatToEndOfStatement();
7745 return Error(Parser.getTok().getLoc(),
7746 "unexpected input in .req directive.");
7749 Parser.Lex(); // Consume the EndOfStatement
7751 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7752 return Error(SRegLoc, "redefinition of '" + Name +
7753 "' does not match original.");
7758 /// parseDirectiveUneq
7759 /// ::= .unreq registername
7760 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7761 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7762 Parser.EatToEndOfStatement();
7763 return Error(L, "unexpected input in .unreq directive.");
7765 RegisterReqs.erase(Parser.getTok().getIdentifier());
7766 Parser.Lex(); // Eat the identifier.
7770 /// parseDirectiveArch
7772 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7776 /// parseDirectiveEabiAttr
7777 /// ::= .eabi_attribute int, int
7778 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7782 extern "C" void LLVMInitializeARMAsmLexer();
7784 /// Force static initialization.
7785 extern "C" void LLVMInitializeARMAsmParser() {
7786 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7787 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
7788 LLVMInitializeARMAsmLexer();
7791 #define GET_REGISTER_MATCHER
7792 #define GET_SUBTARGET_FEATURE_NAME
7793 #define GET_MATCHER_IMPLEMENTATION
7794 #include "ARMGenAsmMatcher.inc"