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 "ARMBuildAttrs.h"
11 #include "ARMFPUName.h"
12 #include "ARMFeatures.h"
13 #include "llvm/MC/MCTargetAsmParser.h"
14 #include "MCTargetDesc/ARMAddressingModes.h"
15 #include "MCTargetDesc/ARMArchName.h"
16 #include "MCTargetDesc/ARMBaseInfo.h"
17 #include "MCTargetDesc/ARMMCExpr.h"
18 #include "llvm/ADT/BitVector.h"
19 #include "llvm/ADT/OwningPtr.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/ADT/StringSwitch.h"
24 #include "llvm/ADT/Twine.h"
25 #include "llvm/MC/MCAsmInfo.h"
26 #include "llvm/MC/MCAssembler.h"
27 #include "llvm/MC/MCContext.h"
28 #include "llvm/MC/MCELFStreamer.h"
29 #include "llvm/MC/MCExpr.h"
30 #include "llvm/MC/MCInst.h"
31 #include "llvm/MC/MCInstrDesc.h"
32 #include "llvm/MC/MCInstrInfo.h"
33 #include "llvm/MC/MCParser/MCAsmLexer.h"
34 #include "llvm/MC/MCParser/MCAsmParser.h"
35 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
36 #include "llvm/MC/MCRegisterInfo.h"
37 #include "llvm/MC/MCStreamer.h"
38 #include "llvm/MC/MCSubtargetInfo.h"
39 #include "llvm/Support/ELF.h"
40 #include "llvm/Support/MathExtras.h"
41 #include "llvm/Support/SourceMgr.h"
42 #include "llvm/Support/TargetRegistry.h"
43 #include "llvm/Support/raw_ostream.h"
51 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
53 class ARMAsmParser : public MCTargetAsmParser {
56 const MCInstrInfo &MII;
57 const MCRegisterInfo *MRI;
59 ARMTargetStreamer &getTargetStreamer() {
60 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
61 return static_cast<ARMTargetStreamer &>(TS);
64 // Unwind directives state
70 void resetUnwindDirectiveParserState() {
72 CantUnwindLoc = SMLoc();
73 PersonalityLoc = SMLoc();
74 HandlerDataLoc = SMLoc();
78 // Map of register aliases registers via the .req directive.
79 StringMap<unsigned> RegisterReqs;
81 bool NextSymbolIsThumb;
84 ARMCC::CondCodes Cond; // Condition for IT block.
85 unsigned Mask:4; // Condition mask for instructions.
86 // Starting at first 1 (from lsb).
87 // '1' condition as indicated in IT.
88 // '0' inverse of condition (else).
89 // Count of instructions in IT block is
90 // 4 - trailingzeroes(mask)
92 bool FirstCond; // Explicit flag for when we're parsing the
93 // First instruction in the IT block. It's
94 // implied in the mask, so needs special
97 unsigned CurPosition; // Current position in parsing of IT
98 // block. In range [0,3]. Initialized
99 // according to count of instructions in block.
100 // ~0U if no active IT block.
102 bool inITBlock() { return ITState.CurPosition != ~0U;}
103 void forwardITPosition() {
104 if (!inITBlock()) return;
105 // Move to the next instruction in the IT block, if there is one. If not,
106 // mark the block as done.
107 unsigned TZ = countTrailingZeros(ITState.Mask);
108 if (++ITState.CurPosition == 5 - TZ)
109 ITState.CurPosition = ~0U; // Done with the IT block after this.
113 MCAsmParser &getParser() const { return Parser; }
114 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
116 bool Warning(SMLoc L, const Twine &Msg,
117 ArrayRef<SMRange> Ranges = None) {
118 return Parser.Warning(L, Msg, Ranges);
120 bool Error(SMLoc L, const Twine &Msg,
121 ArrayRef<SMRange> Ranges = None) {
122 return Parser.Error(L, Msg, Ranges);
125 int tryParseRegister();
126 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
127 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
128 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
129 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
130 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
131 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
132 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
133 unsigned &ShiftAmount);
134 bool parseDirectiveWord(unsigned Size, SMLoc L);
135 bool parseDirectiveThumb(SMLoc L);
136 bool parseDirectiveARM(SMLoc L);
137 bool parseDirectiveThumbFunc(SMLoc L);
138 bool parseDirectiveCode(SMLoc L);
139 bool parseDirectiveSyntax(SMLoc L);
140 bool parseDirectiveReq(StringRef Name, SMLoc L);
141 bool parseDirectiveUnreq(SMLoc L);
142 bool parseDirectiveArch(SMLoc L);
143 bool parseDirectiveEabiAttr(SMLoc L);
144 bool parseDirectiveCPU(SMLoc L);
145 bool parseDirectiveFPU(SMLoc L);
146 bool parseDirectiveFnStart(SMLoc L);
147 bool parseDirectiveFnEnd(SMLoc L);
148 bool parseDirectiveCantUnwind(SMLoc L);
149 bool parseDirectivePersonality(SMLoc L);
150 bool parseDirectiveHandlerData(SMLoc L);
151 bool parseDirectiveSetFP(SMLoc L);
152 bool parseDirectivePad(SMLoc L);
153 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
154 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
156 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
157 bool &CarrySetting, unsigned &ProcessorIMod,
159 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
160 bool &CanAcceptCarrySet,
161 bool &CanAcceptPredicationCode);
163 bool isThumb() const {
164 // FIXME: Can tablegen auto-generate this?
165 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
167 bool isThumbOne() const {
168 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
170 bool isThumbTwo() const {
171 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
173 bool hasThumb() const {
174 return STI.getFeatureBits() & ARM::HasV4TOps;
176 bool hasV6Ops() const {
177 return STI.getFeatureBits() & ARM::HasV6Ops;
179 bool hasV6MOps() const {
180 return STI.getFeatureBits() & ARM::HasV6MOps;
182 bool hasV7Ops() const {
183 return STI.getFeatureBits() & ARM::HasV7Ops;
185 bool hasV8Ops() const {
186 return STI.getFeatureBits() & ARM::HasV8Ops;
188 bool hasARM() const {
189 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
193 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
194 setAvailableFeatures(FB);
196 bool isMClass() const {
197 return STI.getFeatureBits() & ARM::FeatureMClass;
200 /// @name Auto-generated Match Functions
203 #define GET_ASSEMBLER_HEADER
204 #include "ARMGenAsmMatcher.inc"
208 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
209 OperandMatchResultTy parseCoprocNumOperand(
210 SmallVectorImpl<MCParsedAsmOperand*>&);
211 OperandMatchResultTy parseCoprocRegOperand(
212 SmallVectorImpl<MCParsedAsmOperand*>&);
213 OperandMatchResultTy parseCoprocOptionOperand(
214 SmallVectorImpl<MCParsedAsmOperand*>&);
215 OperandMatchResultTy parseMemBarrierOptOperand(
216 SmallVectorImpl<MCParsedAsmOperand*>&);
217 OperandMatchResultTy parseInstSyncBarrierOptOperand(
218 SmallVectorImpl<MCParsedAsmOperand*>&);
219 OperandMatchResultTy parseProcIFlagsOperand(
220 SmallVectorImpl<MCParsedAsmOperand*>&);
221 OperandMatchResultTy parseMSRMaskOperand(
222 SmallVectorImpl<MCParsedAsmOperand*>&);
223 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
224 StringRef Op, int Low, int High);
225 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
226 return parsePKHImm(O, "lsl", 0, 31);
228 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
229 return parsePKHImm(O, "asr", 1, 32);
231 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
232 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
233 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
234 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
235 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
236 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
237 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
238 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
239 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
242 // Asm Match Converter Methods
243 void cvtThumbMultiply(MCInst &Inst,
244 const SmallVectorImpl<MCParsedAsmOperand*> &);
245 void cvtThumbBranches(MCInst &Inst,
246 const SmallVectorImpl<MCParsedAsmOperand*> &);
248 bool validateInstruction(MCInst &Inst,
249 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
250 bool processInstruction(MCInst &Inst,
251 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
252 bool shouldOmitCCOutOperand(StringRef Mnemonic,
253 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
254 bool shouldOmitPredicateOperand(StringRef Mnemonic,
255 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
257 enum ARMMatchResultTy {
258 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
259 Match_RequiresNotITBlock,
261 Match_RequiresThumb2,
262 #define GET_OPERAND_DIAGNOSTIC_TYPES
263 #include "ARMGenAsmMatcher.inc"
267 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
268 const MCInstrInfo &MII)
269 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
270 MCAsmParserExtension::Initialize(_Parser);
272 // Cache the MCRegisterInfo.
273 MRI = getContext().getRegisterInfo();
275 // Initialize the set of available features.
276 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
278 // Not in an ITBlock to start with.
279 ITState.CurPosition = ~0U;
281 NextSymbolIsThumb = false;
284 // Implementation of the MCTargetAsmParser interface:
285 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
286 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
288 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
289 bool ParseDirective(AsmToken DirectiveID);
291 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
292 unsigned checkTargetMatchPredicate(MCInst &Inst);
294 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
295 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
296 MCStreamer &Out, unsigned &ErrorInfo,
297 bool MatchingInlineAsm);
298 void onLabelParsed(MCSymbol *Symbol);
301 } // end anonymous namespace
305 /// ARMOperand - Instances of this class represent a parsed ARM machine
307 class ARMOperand : public MCParsedAsmOperand {
317 k_InstSyncBarrierOpt,
328 k_VectorListAllLanes,
334 k_BitfieldDescriptor,
338 SMLoc StartLoc, EndLoc;
339 SmallVector<unsigned, 8> Registers;
342 ARMCC::CondCodes Val;
349 struct CoprocOptionOp {
362 ARM_ISB::InstSyncBOpt Val;
366 ARM_PROC::IFlags Val;
382 // A vector register list is a sequential list of 1 to 4 registers.
383 struct VectorListOp {
390 struct VectorIndexOp {
398 /// Combined record for all forms of ARM address expressions.
401 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
403 const MCConstantExpr *OffsetImm; // Offset immediate value
404 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
405 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
406 unsigned ShiftImm; // shift for OffsetReg.
407 unsigned Alignment; // 0 = no alignment specified
408 // n = alignment in bytes (2, 4, 8, 16, or 32)
409 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
412 struct PostIdxRegOp {
415 ARM_AM::ShiftOpc ShiftTy;
419 struct ShifterImmOp {
424 struct RegShiftedRegOp {
425 ARM_AM::ShiftOpc ShiftTy;
431 struct RegShiftedImmOp {
432 ARM_AM::ShiftOpc ShiftTy;
449 struct CoprocOptionOp CoprocOption;
450 struct MBOptOp MBOpt;
451 struct ISBOptOp ISBOpt;
452 struct ITMaskOp ITMask;
453 struct IFlagsOp IFlags;
454 struct MMaskOp MMask;
457 struct VectorListOp VectorList;
458 struct VectorIndexOp VectorIndex;
460 struct MemoryOp Memory;
461 struct PostIdxRegOp PostIdxReg;
462 struct ShifterImmOp ShifterImm;
463 struct RegShiftedRegOp RegShiftedReg;
464 struct RegShiftedImmOp RegShiftedImm;
465 struct RotImmOp RotImm;
466 struct BitfieldOp Bitfield;
469 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
471 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
473 StartLoc = o.StartLoc;
490 case k_DPRRegisterList:
491 case k_SPRRegisterList:
492 Registers = o.Registers;
495 case k_VectorListAllLanes:
496 case k_VectorListIndexed:
497 VectorList = o.VectorList;
504 CoprocOption = o.CoprocOption;
509 case k_MemBarrierOpt:
512 case k_InstSyncBarrierOpt:
517 case k_PostIndexRegister:
518 PostIdxReg = o.PostIdxReg;
526 case k_ShifterImmediate:
527 ShifterImm = o.ShifterImm;
529 case k_ShiftedRegister:
530 RegShiftedReg = o.RegShiftedReg;
532 case k_ShiftedImmediate:
533 RegShiftedImm = o.RegShiftedImm;
535 case k_RotateImmediate:
538 case k_BitfieldDescriptor:
539 Bitfield = o.Bitfield;
542 VectorIndex = o.VectorIndex;
547 /// getStartLoc - Get the location of the first token of this operand.
548 SMLoc getStartLoc() const { return StartLoc; }
549 /// getEndLoc - Get the location of the last token of this operand.
550 SMLoc getEndLoc() const { return EndLoc; }
551 /// getLocRange - Get the range between the first and last token of this
553 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
555 ARMCC::CondCodes getCondCode() const {
556 assert(Kind == k_CondCode && "Invalid access!");
560 unsigned getCoproc() const {
561 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
565 StringRef getToken() const {
566 assert(Kind == k_Token && "Invalid access!");
567 return StringRef(Tok.Data, Tok.Length);
570 unsigned getReg() const {
571 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
575 const SmallVectorImpl<unsigned> &getRegList() const {
576 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
577 Kind == k_SPRRegisterList) && "Invalid access!");
581 const MCExpr *getImm() const {
582 assert(isImm() && "Invalid access!");
586 unsigned getVectorIndex() const {
587 assert(Kind == k_VectorIndex && "Invalid access!");
588 return VectorIndex.Val;
591 ARM_MB::MemBOpt getMemBarrierOpt() const {
592 assert(Kind == k_MemBarrierOpt && "Invalid access!");
596 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
597 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
601 ARM_PROC::IFlags getProcIFlags() const {
602 assert(Kind == k_ProcIFlags && "Invalid access!");
606 unsigned getMSRMask() const {
607 assert(Kind == k_MSRMask && "Invalid access!");
611 bool isCoprocNum() const { return Kind == k_CoprocNum; }
612 bool isCoprocReg() const { return Kind == k_CoprocReg; }
613 bool isCoprocOption() const { return Kind == k_CoprocOption; }
614 bool isCondCode() const { return Kind == k_CondCode; }
615 bool isCCOut() const { return Kind == k_CCOut; }
616 bool isITMask() const { return Kind == k_ITCondMask; }
617 bool isITCondCode() const { return Kind == k_CondCode; }
618 bool isImm() const { return Kind == k_Immediate; }
619 // checks whether this operand is an unsigned offset which fits is a field
620 // of specified width and scaled by a specific number of bits
621 template<unsigned width, unsigned scale>
622 bool isUnsignedOffset() const {
623 if (!isImm()) return false;
624 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
625 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
626 int64_t Val = CE->getValue();
627 int64_t Align = 1LL << scale;
628 int64_t Max = Align * ((1LL << width) - 1);
629 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
633 // checks whether this operand is an signed offset which fits is a field
634 // of specified width and scaled by a specific number of bits
635 template<unsigned width, unsigned scale>
636 bool isSignedOffset() const {
637 if (!isImm()) return false;
638 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
639 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
640 int64_t Val = CE->getValue();
641 int64_t Align = 1LL << scale;
642 int64_t Max = Align * ((1LL << (width-1)) - 1);
643 int64_t Min = -Align * (1LL << (width-1));
644 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
649 // checks whether this operand is a memory operand computed as an offset
650 // applied to PC. the offset may have 8 bits of magnitude and is represented
651 // with two bits of shift. textually it may be either [pc, #imm], #imm or
652 // relocable expression...
653 bool isThumbMemPC() const {
656 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
657 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
658 if (!CE) return false;
659 Val = CE->getValue();
662 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
663 if(Memory.BaseRegNum != ARM::PC) return false;
664 Val = Memory.OffsetImm->getValue();
667 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
669 bool isFPImm() const {
670 if (!isImm()) return false;
671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
672 if (!CE) return false;
673 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
676 bool isFBits16() const {
677 if (!isImm()) return false;
678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
679 if (!CE) return false;
680 int64_t Value = CE->getValue();
681 return Value >= 0 && Value <= 16;
683 bool isFBits32() const {
684 if (!isImm()) return false;
685 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
686 if (!CE) return false;
687 int64_t Value = CE->getValue();
688 return Value >= 1 && Value <= 32;
690 bool isImm8s4() const {
691 if (!isImm()) return false;
692 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
693 if (!CE) return false;
694 int64_t Value = CE->getValue();
695 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
697 bool isImm0_1020s4() const {
698 if (!isImm()) return false;
699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
700 if (!CE) return false;
701 int64_t Value = CE->getValue();
702 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
704 bool isImm0_508s4() const {
705 if (!isImm()) return false;
706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
707 if (!CE) return false;
708 int64_t Value = CE->getValue();
709 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
711 bool isImm0_508s4Neg() const {
712 if (!isImm()) return false;
713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
714 if (!CE) return false;
715 int64_t Value = -CE->getValue();
716 // explicitly exclude zero. we want that to use the normal 0_508 version.
717 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
719 bool isImm0_239() 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 < 240;
726 bool isImm0_255() 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 < 256;
733 bool isImm0_4095() 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 < 4096;
740 bool isImm0_4095Neg() 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 < 4096;
747 bool isImm0_1() 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 < 2;
754 bool isImm0_3() 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 < 4;
761 bool isImm0_7() 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 < 8;
768 bool isImm0_15() const {
769 if (!isImm()) return false;
770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
771 if (!CE) return false;
772 int64_t Value = CE->getValue();
773 return Value >= 0 && Value < 16;
775 bool isImm0_31() const {
776 if (!isImm()) return false;
777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
778 if (!CE) return false;
779 int64_t Value = CE->getValue();
780 return Value >= 0 && Value < 32;
782 bool isImm0_63() const {
783 if (!isImm()) return false;
784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
785 if (!CE) return false;
786 int64_t Value = CE->getValue();
787 return Value >= 0 && Value < 64;
789 bool isImm8() const {
790 if (!isImm()) return false;
791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
792 if (!CE) return false;
793 int64_t Value = CE->getValue();
796 bool isImm16() const {
797 if (!isImm()) return false;
798 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
799 if (!CE) return false;
800 int64_t Value = CE->getValue();
803 bool isImm32() const {
804 if (!isImm()) return false;
805 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
806 if (!CE) return false;
807 int64_t Value = CE->getValue();
810 bool isShrImm8() const {
811 if (!isImm()) return false;
812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
813 if (!CE) return false;
814 int64_t Value = CE->getValue();
815 return Value > 0 && Value <= 8;
817 bool isShrImm16() const {
818 if (!isImm()) return false;
819 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
820 if (!CE) return false;
821 int64_t Value = CE->getValue();
822 return Value > 0 && Value <= 16;
824 bool isShrImm32() const {
825 if (!isImm()) return false;
826 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
827 if (!CE) return false;
828 int64_t Value = CE->getValue();
829 return Value > 0 && Value <= 32;
831 bool isShrImm64() const {
832 if (!isImm()) return false;
833 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
834 if (!CE) return false;
835 int64_t Value = CE->getValue();
836 return Value > 0 && Value <= 64;
838 bool isImm1_7() const {
839 if (!isImm()) return false;
840 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
841 if (!CE) return false;
842 int64_t Value = CE->getValue();
843 return Value > 0 && Value < 8;
845 bool isImm1_15() const {
846 if (!isImm()) return false;
847 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
848 if (!CE) return false;
849 int64_t Value = CE->getValue();
850 return Value > 0 && Value < 16;
852 bool isImm1_31() const {
853 if (!isImm()) return false;
854 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
855 if (!CE) return false;
856 int64_t Value = CE->getValue();
857 return Value > 0 && Value < 32;
859 bool isImm1_16() const {
860 if (!isImm()) return false;
861 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
862 if (!CE) return false;
863 int64_t Value = CE->getValue();
864 return Value > 0 && Value < 17;
866 bool isImm1_32() const {
867 if (!isImm()) return false;
868 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
869 if (!CE) return false;
870 int64_t Value = CE->getValue();
871 return Value > 0 && Value < 33;
873 bool isImm0_32() const {
874 if (!isImm()) return false;
875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
876 if (!CE) return false;
877 int64_t Value = CE->getValue();
878 return Value >= 0 && Value < 33;
880 bool isImm0_65535() const {
881 if (!isImm()) return false;
882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
883 if (!CE) return false;
884 int64_t Value = CE->getValue();
885 return Value >= 0 && Value < 65536;
887 bool isImm256_65535Expr() const {
888 if (!isImm()) return false;
889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
890 // If it's not a constant expression, it'll generate a fixup and be
892 if (!CE) return true;
893 int64_t Value = CE->getValue();
894 return Value >= 256 && Value < 65536;
896 bool isImm0_65535Expr() const {
897 if (!isImm()) return false;
898 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
899 // If it's not a constant expression, it'll generate a fixup and be
901 if (!CE) return true;
902 int64_t Value = CE->getValue();
903 return Value >= 0 && Value < 65536;
905 bool isImm24bit() const {
906 if (!isImm()) return false;
907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
908 if (!CE) return false;
909 int64_t Value = CE->getValue();
910 return Value >= 0 && Value <= 0xffffff;
912 bool isImmThumbSR() const {
913 if (!isImm()) return false;
914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
915 if (!CE) return false;
916 int64_t Value = CE->getValue();
917 return Value > 0 && Value < 33;
919 bool isPKHLSLImm() const {
920 if (!isImm()) return false;
921 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
922 if (!CE) return false;
923 int64_t Value = CE->getValue();
924 return Value >= 0 && Value < 32;
926 bool isPKHASRImm() const {
927 if (!isImm()) return false;
928 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
929 if (!CE) return false;
930 int64_t Value = CE->getValue();
931 return Value > 0 && Value <= 32;
933 bool isAdrLabel() const {
934 // If we have an immediate that's not a constant, treat it as a label
935 // reference needing a fixup. If it is a constant, but it can't fit
936 // into shift immediate encoding, we reject it.
937 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
938 else return (isARMSOImm() || isARMSOImmNeg());
940 bool isARMSOImm() const {
941 if (!isImm()) return false;
942 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
943 if (!CE) return false;
944 int64_t Value = CE->getValue();
945 return ARM_AM::getSOImmVal(Value) != -1;
947 bool isARMSOImmNot() const {
948 if (!isImm()) return false;
949 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
950 if (!CE) return false;
951 int64_t Value = CE->getValue();
952 return ARM_AM::getSOImmVal(~Value) != -1;
954 bool isARMSOImmNeg() const {
955 if (!isImm()) return false;
956 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
957 if (!CE) return false;
958 int64_t Value = CE->getValue();
959 // Only use this when not representable as a plain so_imm.
960 return ARM_AM::getSOImmVal(Value) == -1 &&
961 ARM_AM::getSOImmVal(-Value) != -1;
963 bool isT2SOImm() const {
964 if (!isImm()) return false;
965 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
966 if (!CE) return false;
967 int64_t Value = CE->getValue();
968 return ARM_AM::getT2SOImmVal(Value) != -1;
970 bool isT2SOImmNot() const {
971 if (!isImm()) return false;
972 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
973 if (!CE) return false;
974 int64_t Value = CE->getValue();
975 return ARM_AM::getT2SOImmVal(Value) == -1 &&
976 ARM_AM::getT2SOImmVal(~Value) != -1;
978 bool isT2SOImmNeg() const {
979 if (!isImm()) return false;
980 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
981 if (!CE) return false;
982 int64_t Value = CE->getValue();
983 // Only use this when not representable as a plain so_imm.
984 return ARM_AM::getT2SOImmVal(Value) == -1 &&
985 ARM_AM::getT2SOImmVal(-Value) != -1;
987 bool isSetEndImm() const {
988 if (!isImm()) return false;
989 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
990 if (!CE) return false;
991 int64_t Value = CE->getValue();
992 return Value == 1 || Value == 0;
994 bool isReg() const { return Kind == k_Register; }
995 bool isRegList() const { return Kind == k_RegisterList; }
996 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
997 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
998 bool isToken() const { return Kind == k_Token; }
999 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
1000 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
1001 bool isMem() const { return Kind == k_Memory; }
1002 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1003 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1004 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1005 bool isRotImm() const { return Kind == k_RotateImmediate; }
1006 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1007 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
1008 bool isPostIdxReg() const {
1009 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
1011 bool isMemNoOffset(bool alignOK = false) const {
1014 // No offset of any kind.
1015 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1016 (alignOK || Memory.Alignment == 0);
1018 bool isMemPCRelImm12() const {
1019 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1021 // Base register must be PC.
1022 if (Memory.BaseRegNum != ARM::PC)
1024 // Immediate offset in range [-4095, 4095].
1025 if (!Memory.OffsetImm) return true;
1026 int64_t Val = Memory.OffsetImm->getValue();
1027 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1029 bool isAlignedMemory() const {
1030 return isMemNoOffset(true);
1032 bool isAddrMode2() const {
1033 if (!isMem() || Memory.Alignment != 0) return false;
1034 // Check for register offset.
1035 if (Memory.OffsetRegNum) return true;
1036 // Immediate offset in range [-4095, 4095].
1037 if (!Memory.OffsetImm) return true;
1038 int64_t Val = Memory.OffsetImm->getValue();
1039 return Val > -4096 && Val < 4096;
1041 bool isAM2OffsetImm() const {
1042 if (!isImm()) return false;
1043 // Immediate offset in range [-4095, 4095].
1044 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1045 if (!CE) return false;
1046 int64_t Val = CE->getValue();
1047 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1049 bool isAddrMode3() const {
1050 // If we have an immediate that's not a constant, treat it as a label
1051 // reference needing a fixup. If it is a constant, it's something else
1052 // and we reject it.
1053 if (isImm() && !isa<MCConstantExpr>(getImm()))
1055 if (!isMem() || Memory.Alignment != 0) return false;
1056 // No shifts are legal for AM3.
1057 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1058 // Check for register offset.
1059 if (Memory.OffsetRegNum) return true;
1060 // Immediate offset in range [-255, 255].
1061 if (!Memory.OffsetImm) return true;
1062 int64_t Val = Memory.OffsetImm->getValue();
1063 // The #-0 offset is encoded as INT32_MIN, and we have to check
1065 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1067 bool isAM3Offset() const {
1068 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1070 if (Kind == k_PostIndexRegister)
1071 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1072 // Immediate offset in range [-255, 255].
1073 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1074 if (!CE) return false;
1075 int64_t Val = CE->getValue();
1076 // Special case, #-0 is INT32_MIN.
1077 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1079 bool isAddrMode5() const {
1080 // If we have an immediate that's not a constant, treat it as a label
1081 // reference needing a fixup. If it is a constant, it's something else
1082 // and we reject it.
1083 if (isImm() && !isa<MCConstantExpr>(getImm()))
1085 if (!isMem() || Memory.Alignment != 0) return false;
1086 // Check for register offset.
1087 if (Memory.OffsetRegNum) return false;
1088 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1089 if (!Memory.OffsetImm) return true;
1090 int64_t Val = Memory.OffsetImm->getValue();
1091 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1094 bool isMemTBB() const {
1095 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1096 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1100 bool isMemTBH() const {
1101 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1102 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1103 Memory.Alignment != 0 )
1107 bool isMemRegOffset() const {
1108 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1112 bool isT2MemRegOffset() const {
1113 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1114 Memory.Alignment != 0)
1116 // Only lsl #{0, 1, 2, 3} allowed.
1117 if (Memory.ShiftType == ARM_AM::no_shift)
1119 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1123 bool isMemThumbRR() const {
1124 // Thumb reg+reg addressing is simple. Just two registers, a base and
1125 // an offset. No shifts, negations or any other complicating factors.
1126 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1127 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1129 return isARMLowRegister(Memory.BaseRegNum) &&
1130 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1132 bool isMemThumbRIs4() const {
1133 if (!isMem() || Memory.OffsetRegNum != 0 ||
1134 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1136 // Immediate offset, multiple of 4 in range [0, 124].
1137 if (!Memory.OffsetImm) return true;
1138 int64_t Val = Memory.OffsetImm->getValue();
1139 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1141 bool isMemThumbRIs2() const {
1142 if (!isMem() || Memory.OffsetRegNum != 0 ||
1143 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1145 // Immediate offset, multiple of 4 in range [0, 62].
1146 if (!Memory.OffsetImm) return true;
1147 int64_t Val = Memory.OffsetImm->getValue();
1148 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1150 bool isMemThumbRIs1() const {
1151 if (!isMem() || Memory.OffsetRegNum != 0 ||
1152 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1154 // Immediate offset in range [0, 31].
1155 if (!Memory.OffsetImm) return true;
1156 int64_t Val = Memory.OffsetImm->getValue();
1157 return Val >= 0 && Val <= 31;
1159 bool isMemThumbSPI() const {
1160 if (!isMem() || Memory.OffsetRegNum != 0 ||
1161 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1163 // Immediate offset, multiple of 4 in range [0, 1020].
1164 if (!Memory.OffsetImm) return true;
1165 int64_t Val = Memory.OffsetImm->getValue();
1166 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1168 bool isMemImm8s4Offset() const {
1169 // If we have an immediate that's not a constant, treat it as a label
1170 // reference needing a fixup. If it is a constant, it's something else
1171 // and we reject it.
1172 if (isImm() && !isa<MCConstantExpr>(getImm()))
1174 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1176 // Immediate offset a multiple of 4 in range [-1020, 1020].
1177 if (!Memory.OffsetImm) return true;
1178 int64_t Val = Memory.OffsetImm->getValue();
1179 // Special case, #-0 is INT32_MIN.
1180 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1182 bool isMemImm0_1020s4Offset() const {
1183 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1185 // Immediate offset a multiple of 4 in range [0, 1020].
1186 if (!Memory.OffsetImm) return true;
1187 int64_t Val = Memory.OffsetImm->getValue();
1188 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1190 bool isMemImm8Offset() const {
1191 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1193 // Base reg of PC isn't allowed for these encodings.
1194 if (Memory.BaseRegNum == ARM::PC) return false;
1195 // Immediate offset in range [-255, 255].
1196 if (!Memory.OffsetImm) return true;
1197 int64_t Val = Memory.OffsetImm->getValue();
1198 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1200 bool isMemPosImm8Offset() const {
1201 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1203 // Immediate offset in range [0, 255].
1204 if (!Memory.OffsetImm) return true;
1205 int64_t Val = Memory.OffsetImm->getValue();
1206 return Val >= 0 && Val < 256;
1208 bool isMemNegImm8Offset() const {
1209 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1211 // Base reg of PC isn't allowed for these encodings.
1212 if (Memory.BaseRegNum == ARM::PC) return false;
1213 // Immediate offset in range [-255, -1].
1214 if (!Memory.OffsetImm) return false;
1215 int64_t Val = Memory.OffsetImm->getValue();
1216 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1218 bool isMemUImm12Offset() const {
1219 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1221 // Immediate offset in range [0, 4095].
1222 if (!Memory.OffsetImm) return true;
1223 int64_t Val = Memory.OffsetImm->getValue();
1224 return (Val >= 0 && Val < 4096);
1226 bool isMemImm12Offset() const {
1227 // If we have an immediate that's not a constant, treat it as a label
1228 // reference needing a fixup. If it is a constant, it's something else
1229 // and we reject it.
1230 if (isImm() && !isa<MCConstantExpr>(getImm()))
1233 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1235 // Immediate offset in range [-4095, 4095].
1236 if (!Memory.OffsetImm) return true;
1237 int64_t Val = Memory.OffsetImm->getValue();
1238 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1240 bool isPostIdxImm8() const {
1241 if (!isImm()) return false;
1242 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1243 if (!CE) return false;
1244 int64_t Val = CE->getValue();
1245 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1247 bool isPostIdxImm8s4() const {
1248 if (!isImm()) return false;
1249 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1250 if (!CE) return false;
1251 int64_t Val = CE->getValue();
1252 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1256 bool isMSRMask() const { return Kind == k_MSRMask; }
1257 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1260 bool isSingleSpacedVectorList() const {
1261 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1263 bool isDoubleSpacedVectorList() const {
1264 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1266 bool isVecListOneD() const {
1267 if (!isSingleSpacedVectorList()) return false;
1268 return VectorList.Count == 1;
1271 bool isVecListDPair() const {
1272 if (!isSingleSpacedVectorList()) return false;
1273 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1274 .contains(VectorList.RegNum));
1277 bool isVecListThreeD() const {
1278 if (!isSingleSpacedVectorList()) return false;
1279 return VectorList.Count == 3;
1282 bool isVecListFourD() const {
1283 if (!isSingleSpacedVectorList()) return false;
1284 return VectorList.Count == 4;
1287 bool isVecListDPairSpaced() const {
1288 if (isSingleSpacedVectorList()) return false;
1289 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1290 .contains(VectorList.RegNum));
1293 bool isVecListThreeQ() const {
1294 if (!isDoubleSpacedVectorList()) return false;
1295 return VectorList.Count == 3;
1298 bool isVecListFourQ() const {
1299 if (!isDoubleSpacedVectorList()) return false;
1300 return VectorList.Count == 4;
1303 bool isSingleSpacedVectorAllLanes() const {
1304 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1306 bool isDoubleSpacedVectorAllLanes() const {
1307 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1309 bool isVecListOneDAllLanes() const {
1310 if (!isSingleSpacedVectorAllLanes()) return false;
1311 return VectorList.Count == 1;
1314 bool isVecListDPairAllLanes() const {
1315 if (!isSingleSpacedVectorAllLanes()) return false;
1316 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1317 .contains(VectorList.RegNum));
1320 bool isVecListDPairSpacedAllLanes() const {
1321 if (!isDoubleSpacedVectorAllLanes()) return false;
1322 return VectorList.Count == 2;
1325 bool isVecListThreeDAllLanes() const {
1326 if (!isSingleSpacedVectorAllLanes()) return false;
1327 return VectorList.Count == 3;
1330 bool isVecListThreeQAllLanes() const {
1331 if (!isDoubleSpacedVectorAllLanes()) return false;
1332 return VectorList.Count == 3;
1335 bool isVecListFourDAllLanes() const {
1336 if (!isSingleSpacedVectorAllLanes()) return false;
1337 return VectorList.Count == 4;
1340 bool isVecListFourQAllLanes() const {
1341 if (!isDoubleSpacedVectorAllLanes()) return false;
1342 return VectorList.Count == 4;
1345 bool isSingleSpacedVectorIndexed() const {
1346 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1348 bool isDoubleSpacedVectorIndexed() const {
1349 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1351 bool isVecListOneDByteIndexed() const {
1352 if (!isSingleSpacedVectorIndexed()) return false;
1353 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1356 bool isVecListOneDHWordIndexed() const {
1357 if (!isSingleSpacedVectorIndexed()) return false;
1358 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1361 bool isVecListOneDWordIndexed() const {
1362 if (!isSingleSpacedVectorIndexed()) return false;
1363 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1366 bool isVecListTwoDByteIndexed() const {
1367 if (!isSingleSpacedVectorIndexed()) return false;
1368 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1371 bool isVecListTwoDHWordIndexed() const {
1372 if (!isSingleSpacedVectorIndexed()) return false;
1373 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1376 bool isVecListTwoQWordIndexed() const {
1377 if (!isDoubleSpacedVectorIndexed()) return false;
1378 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1381 bool isVecListTwoQHWordIndexed() const {
1382 if (!isDoubleSpacedVectorIndexed()) return false;
1383 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1386 bool isVecListTwoDWordIndexed() const {
1387 if (!isSingleSpacedVectorIndexed()) return false;
1388 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1391 bool isVecListThreeDByteIndexed() const {
1392 if (!isSingleSpacedVectorIndexed()) return false;
1393 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1396 bool isVecListThreeDHWordIndexed() const {
1397 if (!isSingleSpacedVectorIndexed()) return false;
1398 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1401 bool isVecListThreeQWordIndexed() const {
1402 if (!isDoubleSpacedVectorIndexed()) return false;
1403 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1406 bool isVecListThreeQHWordIndexed() const {
1407 if (!isDoubleSpacedVectorIndexed()) return false;
1408 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1411 bool isVecListThreeDWordIndexed() const {
1412 if (!isSingleSpacedVectorIndexed()) return false;
1413 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1416 bool isVecListFourDByteIndexed() const {
1417 if (!isSingleSpacedVectorIndexed()) return false;
1418 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1421 bool isVecListFourDHWordIndexed() const {
1422 if (!isSingleSpacedVectorIndexed()) return false;
1423 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1426 bool isVecListFourQWordIndexed() const {
1427 if (!isDoubleSpacedVectorIndexed()) return false;
1428 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1431 bool isVecListFourQHWordIndexed() const {
1432 if (!isDoubleSpacedVectorIndexed()) return false;
1433 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1436 bool isVecListFourDWordIndexed() const {
1437 if (!isSingleSpacedVectorIndexed()) return false;
1438 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1441 bool isVectorIndex8() const {
1442 if (Kind != k_VectorIndex) return false;
1443 return VectorIndex.Val < 8;
1445 bool isVectorIndex16() const {
1446 if (Kind != k_VectorIndex) return false;
1447 return VectorIndex.Val < 4;
1449 bool isVectorIndex32() const {
1450 if (Kind != k_VectorIndex) return false;
1451 return VectorIndex.Val < 2;
1454 bool isNEONi8splat() const {
1455 if (!isImm()) return false;
1456 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1457 // Must be a constant.
1458 if (!CE) return false;
1459 int64_t Value = CE->getValue();
1460 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1462 return Value >= 0 && Value < 256;
1465 bool isNEONi16splat() const {
1466 if (!isImm()) return false;
1467 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1468 // Must be a constant.
1469 if (!CE) return false;
1470 int64_t Value = CE->getValue();
1471 // i16 value in the range [0,255] or [0x0100, 0xff00]
1472 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1475 bool isNEONi32splat() const {
1476 if (!isImm()) return false;
1477 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1478 // Must be a constant.
1479 if (!CE) return false;
1480 int64_t Value = CE->getValue();
1481 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1482 return (Value >= 0 && Value < 256) ||
1483 (Value >= 0x0100 && Value <= 0xff00) ||
1484 (Value >= 0x010000 && Value <= 0xff0000) ||
1485 (Value >= 0x01000000 && Value <= 0xff000000);
1488 bool isNEONi32vmov() const {
1489 if (!isImm()) return false;
1490 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1491 // Must be a constant.
1492 if (!CE) return false;
1493 int64_t Value = CE->getValue();
1494 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1495 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1496 return (Value >= 0 && Value < 256) ||
1497 (Value >= 0x0100 && Value <= 0xff00) ||
1498 (Value >= 0x010000 && Value <= 0xff0000) ||
1499 (Value >= 0x01000000 && Value <= 0xff000000) ||
1500 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1501 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1503 bool isNEONi32vmovNeg() const {
1504 if (!isImm()) return false;
1505 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1506 // Must be a constant.
1507 if (!CE) return false;
1508 int64_t Value = ~CE->getValue();
1509 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1510 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1511 return (Value >= 0 && Value < 256) ||
1512 (Value >= 0x0100 && Value <= 0xff00) ||
1513 (Value >= 0x010000 && Value <= 0xff0000) ||
1514 (Value >= 0x01000000 && Value <= 0xff000000) ||
1515 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1516 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1519 bool isNEONi64splat() const {
1520 if (!isImm()) return false;
1521 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1522 // Must be a constant.
1523 if (!CE) return false;
1524 uint64_t Value = CE->getValue();
1525 // i64 value with each byte being either 0 or 0xff.
1526 for (unsigned i = 0; i < 8; ++i)
1527 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1531 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1532 // Add as immediates when possible. Null MCExpr = 0.
1534 Inst.addOperand(MCOperand::CreateImm(0));
1535 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1536 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1538 Inst.addOperand(MCOperand::CreateExpr(Expr));
1541 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1542 assert(N == 2 && "Invalid number of operands!");
1543 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1544 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1545 Inst.addOperand(MCOperand::CreateReg(RegNum));
1548 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1549 assert(N == 1 && "Invalid number of operands!");
1550 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1553 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1558 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1559 assert(N == 1 && "Invalid number of operands!");
1560 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1563 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1564 assert(N == 1 && "Invalid number of operands!");
1565 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1568 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1569 assert(N == 1 && "Invalid number of operands!");
1570 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1573 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1574 assert(N == 1 && "Invalid number of operands!");
1575 Inst.addOperand(MCOperand::CreateReg(getReg()));
1578 void addRegOperands(MCInst &Inst, unsigned N) const {
1579 assert(N == 1 && "Invalid number of operands!");
1580 Inst.addOperand(MCOperand::CreateReg(getReg()));
1583 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1584 assert(N == 3 && "Invalid number of operands!");
1585 assert(isRegShiftedReg() &&
1586 "addRegShiftedRegOperands() on non-RegShiftedReg!");
1587 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1588 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1589 Inst.addOperand(MCOperand::CreateImm(
1590 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1593 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1594 assert(N == 2 && "Invalid number of operands!");
1595 assert(isRegShiftedImm() &&
1596 "addRegShiftedImmOperands() on non-RegShiftedImm!");
1597 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1598 // Shift of #32 is encoded as 0 where permitted
1599 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1600 Inst.addOperand(MCOperand::CreateImm(
1601 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1604 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1605 assert(N == 1 && "Invalid number of operands!");
1606 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1610 void addRegListOperands(MCInst &Inst, unsigned N) const {
1611 assert(N == 1 && "Invalid number of operands!");
1612 const SmallVectorImpl<unsigned> &RegList = getRegList();
1613 for (SmallVectorImpl<unsigned>::const_iterator
1614 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1615 Inst.addOperand(MCOperand::CreateReg(*I));
1618 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1619 addRegListOperands(Inst, N);
1622 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1623 addRegListOperands(Inst, N);
1626 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1627 assert(N == 1 && "Invalid number of operands!");
1628 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1629 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1632 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1633 assert(N == 1 && "Invalid number of operands!");
1634 // Munge the lsb/width into a bitfield mask.
1635 unsigned lsb = Bitfield.LSB;
1636 unsigned width = Bitfield.Width;
1637 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1638 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1639 (32 - (lsb + width)));
1640 Inst.addOperand(MCOperand::CreateImm(Mask));
1643 void addImmOperands(MCInst &Inst, unsigned N) const {
1644 assert(N == 1 && "Invalid number of operands!");
1645 addExpr(Inst, getImm());
1648 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1649 assert(N == 1 && "Invalid number of operands!");
1650 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1651 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1654 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1655 assert(N == 1 && "Invalid number of operands!");
1656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1657 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1660 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1661 assert(N == 1 && "Invalid number of operands!");
1662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1663 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1664 Inst.addOperand(MCOperand::CreateImm(Val));
1667 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1668 assert(N == 1 && "Invalid number of operands!");
1669 // FIXME: We really want to scale the value here, but the LDRD/STRD
1670 // instruction don't encode operands that way yet.
1671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1672 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1675 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1676 assert(N == 1 && "Invalid number of operands!");
1677 // The immediate is scaled by four in the encoding and is stored
1678 // in the MCInst as such. Lop off the low two bits here.
1679 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1680 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1683 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1684 assert(N == 1 && "Invalid number of operands!");
1685 // The immediate is scaled by four in the encoding and is stored
1686 // in the MCInst as such. Lop off the low two bits here.
1687 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1688 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1691 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1692 assert(N == 1 && "Invalid number of operands!");
1693 // The immediate is scaled by four in the encoding and is stored
1694 // in the MCInst as such. Lop off the low two bits here.
1695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1696 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1699 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1700 assert(N == 1 && "Invalid number of operands!");
1701 // The constant encodes as the immediate-1, and we store in the instruction
1702 // the bits as encoded, so subtract off one here.
1703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1704 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1707 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1708 assert(N == 1 && "Invalid number of operands!");
1709 // The constant encodes as the immediate-1, and we store in the instruction
1710 // the bits as encoded, so subtract off one here.
1711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1712 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1715 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1716 assert(N == 1 && "Invalid number of operands!");
1717 // The constant encodes as the immediate, except for 32, which encodes as
1719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1720 unsigned Imm = CE->getValue();
1721 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1724 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1725 assert(N == 1 && "Invalid number of operands!");
1726 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1727 // the instruction as well.
1728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1729 int Val = CE->getValue();
1730 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1733 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1734 assert(N == 1 && "Invalid number of operands!");
1735 // The operand is actually a t2_so_imm, but we have its bitwise
1736 // negation in the assembly source, so twiddle it here.
1737 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1738 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1741 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1742 assert(N == 1 && "Invalid number of operands!");
1743 // The operand is actually a t2_so_imm, but we have its
1744 // negation in the assembly source, so twiddle it here.
1745 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1746 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1749 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1750 assert(N == 1 && "Invalid number of operands!");
1751 // The operand is actually an imm0_4095, but we have its
1752 // negation in the assembly source, so twiddle it here.
1753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1754 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1757 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1758 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1759 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1763 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1764 assert(SR && "Unknown value type!");
1765 Inst.addOperand(MCOperand::CreateExpr(SR));
1768 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1769 assert(N == 1 && "Invalid number of operands!");
1771 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1773 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1777 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1778 assert(SR && "Unknown value type!");
1779 Inst.addOperand(MCOperand::CreateExpr(SR));
1783 assert(isMem() && "Unknown value type!");
1784 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1785 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1788 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1789 assert(N == 1 && "Invalid number of operands!");
1790 // The operand is actually a so_imm, but we have its bitwise
1791 // negation in the assembly source, so twiddle it here.
1792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1793 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1796 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1797 assert(N == 1 && "Invalid number of operands!");
1798 // The operand is actually a so_imm, but we have its
1799 // negation in the assembly source, so twiddle it here.
1800 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1801 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1804 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1805 assert(N == 1 && "Invalid number of operands!");
1806 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1809 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1810 assert(N == 1 && "Invalid number of operands!");
1811 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1814 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1815 assert(N == 1 && "Invalid number of operands!");
1816 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1819 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1820 assert(N == 1 && "Invalid number of operands!");
1821 int32_t Imm = Memory.OffsetImm->getValue();
1822 Inst.addOperand(MCOperand::CreateImm(Imm));
1825 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1826 assert(N == 1 && "Invalid number of operands!");
1827 assert(isImm() && "Not an immediate!");
1829 // If we have an immediate that's not a constant, treat it as a label
1830 // reference needing a fixup.
1831 if (!isa<MCConstantExpr>(getImm())) {
1832 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1836 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1837 int Val = CE->getValue();
1838 Inst.addOperand(MCOperand::CreateImm(Val));
1841 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1842 assert(N == 2 && "Invalid number of operands!");
1843 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1844 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1847 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1848 assert(N == 3 && "Invalid number of operands!");
1849 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1850 if (!Memory.OffsetRegNum) {
1851 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1852 // Special case for #-0
1853 if (Val == INT32_MIN) Val = 0;
1854 if (Val < 0) Val = -Val;
1855 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1857 // For register offset, we encode the shift type and negation flag
1859 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1860 Memory.ShiftImm, Memory.ShiftType);
1862 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1863 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1864 Inst.addOperand(MCOperand::CreateImm(Val));
1867 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1868 assert(N == 2 && "Invalid number of operands!");
1869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1870 assert(CE && "non-constant AM2OffsetImm operand!");
1871 int32_t Val = CE->getValue();
1872 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1873 // Special case for #-0
1874 if (Val == INT32_MIN) Val = 0;
1875 if (Val < 0) Val = -Val;
1876 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1877 Inst.addOperand(MCOperand::CreateReg(0));
1878 Inst.addOperand(MCOperand::CreateImm(Val));
1881 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1882 assert(N == 3 && "Invalid number of operands!");
1883 // If we have an immediate that's not a constant, treat it as a label
1884 // reference needing a fixup. If it is a constant, it's something else
1885 // and we reject it.
1887 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1888 Inst.addOperand(MCOperand::CreateReg(0));
1889 Inst.addOperand(MCOperand::CreateImm(0));
1893 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1894 if (!Memory.OffsetRegNum) {
1895 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1896 // Special case for #-0
1897 if (Val == INT32_MIN) Val = 0;
1898 if (Val < 0) Val = -Val;
1899 Val = ARM_AM::getAM3Opc(AddSub, Val);
1901 // For register offset, we encode the shift type and negation flag
1903 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1905 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1906 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1907 Inst.addOperand(MCOperand::CreateImm(Val));
1910 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1911 assert(N == 2 && "Invalid number of operands!");
1912 if (Kind == k_PostIndexRegister) {
1914 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1915 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1916 Inst.addOperand(MCOperand::CreateImm(Val));
1921 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1922 int32_t Val = CE->getValue();
1923 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1924 // Special case for #-0
1925 if (Val == INT32_MIN) Val = 0;
1926 if (Val < 0) Val = -Val;
1927 Val = ARM_AM::getAM3Opc(AddSub, Val);
1928 Inst.addOperand(MCOperand::CreateReg(0));
1929 Inst.addOperand(MCOperand::CreateImm(Val));
1932 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1933 assert(N == 2 && "Invalid number of operands!");
1934 // If we have an immediate that's not a constant, treat it as a label
1935 // reference needing a fixup. If it is a constant, it's something else
1936 // and we reject it.
1938 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1939 Inst.addOperand(MCOperand::CreateImm(0));
1943 // The lower two bits are always zero and as such are not encoded.
1944 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1945 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1946 // Special case for #-0
1947 if (Val == INT32_MIN) Val = 0;
1948 if (Val < 0) Val = -Val;
1949 Val = ARM_AM::getAM5Opc(AddSub, Val);
1950 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1951 Inst.addOperand(MCOperand::CreateImm(Val));
1954 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1955 assert(N == 2 && "Invalid number of operands!");
1956 // If we have an immediate that's not a constant, treat it as a label
1957 // reference needing a fixup. If it is a constant, it's something else
1958 // and we reject it.
1960 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1961 Inst.addOperand(MCOperand::CreateImm(0));
1965 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1966 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1967 Inst.addOperand(MCOperand::CreateImm(Val));
1970 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1971 assert(N == 2 && "Invalid number of operands!");
1972 // The lower two bits are always zero and as such are not encoded.
1973 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1974 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1975 Inst.addOperand(MCOperand::CreateImm(Val));
1978 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1979 assert(N == 2 && "Invalid number of operands!");
1980 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1981 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1982 Inst.addOperand(MCOperand::CreateImm(Val));
1985 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1986 addMemImm8OffsetOperands(Inst, N);
1989 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1990 addMemImm8OffsetOperands(Inst, N);
1993 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1994 assert(N == 2 && "Invalid number of operands!");
1995 // If this is an immediate, it's a label reference.
1997 addExpr(Inst, getImm());
1998 Inst.addOperand(MCOperand::CreateImm(0));
2002 // Otherwise, it's a normal memory reg+offset.
2003 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2004 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2005 Inst.addOperand(MCOperand::CreateImm(Val));
2008 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2009 assert(N == 2 && "Invalid number of operands!");
2010 // If this is an immediate, it's a label reference.
2012 addExpr(Inst, getImm());
2013 Inst.addOperand(MCOperand::CreateImm(0));
2017 // Otherwise, it's a normal memory reg+offset.
2018 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2019 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2020 Inst.addOperand(MCOperand::CreateImm(Val));
2023 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2024 assert(N == 2 && "Invalid number of operands!");
2025 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2026 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2029 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2030 assert(N == 2 && "Invalid number of operands!");
2031 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2032 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2035 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2036 assert(N == 3 && "Invalid number of operands!");
2038 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2039 Memory.ShiftImm, Memory.ShiftType);
2040 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2041 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2042 Inst.addOperand(MCOperand::CreateImm(Val));
2045 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2046 assert(N == 3 && "Invalid number of operands!");
2047 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2048 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2049 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2052 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2053 assert(N == 2 && "Invalid number of operands!");
2054 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2055 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2058 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2059 assert(N == 2 && "Invalid number of operands!");
2060 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2061 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2062 Inst.addOperand(MCOperand::CreateImm(Val));
2065 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2066 assert(N == 2 && "Invalid number of operands!");
2067 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2068 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2069 Inst.addOperand(MCOperand::CreateImm(Val));
2072 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2073 assert(N == 2 && "Invalid number of operands!");
2074 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2075 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2076 Inst.addOperand(MCOperand::CreateImm(Val));
2079 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2080 assert(N == 2 && "Invalid number of operands!");
2081 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2082 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2083 Inst.addOperand(MCOperand::CreateImm(Val));
2086 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2087 assert(N == 1 && "Invalid number of operands!");
2088 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2089 assert(CE && "non-constant post-idx-imm8 operand!");
2090 int Imm = CE->getValue();
2091 bool isAdd = Imm >= 0;
2092 if (Imm == INT32_MIN) Imm = 0;
2093 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2094 Inst.addOperand(MCOperand::CreateImm(Imm));
2097 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2098 assert(N == 1 && "Invalid number of operands!");
2099 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2100 assert(CE && "non-constant post-idx-imm8s4 operand!");
2101 int Imm = CE->getValue();
2102 bool isAdd = Imm >= 0;
2103 if (Imm == INT32_MIN) Imm = 0;
2104 // Immediate is scaled by 4.
2105 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2106 Inst.addOperand(MCOperand::CreateImm(Imm));
2109 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2110 assert(N == 2 && "Invalid number of operands!");
2111 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2112 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2115 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2116 assert(N == 2 && "Invalid number of operands!");
2117 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2118 // The sign, shift type, and shift amount are encoded in a single operand
2119 // using the AM2 encoding helpers.
2120 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2121 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2122 PostIdxReg.ShiftTy);
2123 Inst.addOperand(MCOperand::CreateImm(Imm));
2126 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2127 assert(N == 1 && "Invalid number of operands!");
2128 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2131 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2132 assert(N == 1 && "Invalid number of operands!");
2133 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2136 void addVecListOperands(MCInst &Inst, unsigned N) const {
2137 assert(N == 1 && "Invalid number of operands!");
2138 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2141 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2142 assert(N == 2 && "Invalid number of operands!");
2143 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2144 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2147 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2148 assert(N == 1 && "Invalid number of operands!");
2149 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2152 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2153 assert(N == 1 && "Invalid number of operands!");
2154 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2157 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2158 assert(N == 1 && "Invalid number of operands!");
2159 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2162 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2163 assert(N == 1 && "Invalid number of operands!");
2164 // The immediate encodes the type of constant as well as the value.
2165 // Mask in that this is an i8 splat.
2166 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2167 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2170 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2171 assert(N == 1 && "Invalid number of operands!");
2172 // The immediate encodes the type of constant as well as the value.
2173 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2174 unsigned Value = CE->getValue();
2176 Value = (Value >> 8) | 0xa00;
2179 Inst.addOperand(MCOperand::CreateImm(Value));
2182 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2183 assert(N == 1 && "Invalid number of operands!");
2184 // The immediate encodes the type of constant as well as the value.
2185 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2186 unsigned Value = CE->getValue();
2187 if (Value >= 256 && Value <= 0xff00)
2188 Value = (Value >> 8) | 0x200;
2189 else if (Value > 0xffff && Value <= 0xff0000)
2190 Value = (Value >> 16) | 0x400;
2191 else if (Value > 0xffffff)
2192 Value = (Value >> 24) | 0x600;
2193 Inst.addOperand(MCOperand::CreateImm(Value));
2196 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2197 assert(N == 1 && "Invalid number of operands!");
2198 // The immediate encodes the type of constant as well as the value.
2199 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2200 unsigned Value = CE->getValue();
2201 if (Value >= 256 && Value <= 0xffff)
2202 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2203 else if (Value > 0xffff && Value <= 0xffffff)
2204 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2205 else if (Value > 0xffffff)
2206 Value = (Value >> 24) | 0x600;
2207 Inst.addOperand(MCOperand::CreateImm(Value));
2210 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2211 assert(N == 1 && "Invalid number of operands!");
2212 // The immediate encodes the type of constant as well as the value.
2213 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2214 unsigned Value = ~CE->getValue();
2215 if (Value >= 256 && Value <= 0xffff)
2216 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2217 else if (Value > 0xffff && Value <= 0xffffff)
2218 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2219 else if (Value > 0xffffff)
2220 Value = (Value >> 24) | 0x600;
2221 Inst.addOperand(MCOperand::CreateImm(Value));
2224 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2225 assert(N == 1 && "Invalid number of operands!");
2226 // The immediate encodes the type of constant as well as the value.
2227 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2228 uint64_t Value = CE->getValue();
2230 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2231 Imm |= (Value & 1) << i;
2233 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2236 virtual void print(raw_ostream &OS) const;
2238 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2239 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2240 Op->ITMask.Mask = Mask;
2246 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2247 ARMOperand *Op = new ARMOperand(k_CondCode);
2254 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2255 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2256 Op->Cop.Val = CopVal;
2262 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2263 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2264 Op->Cop.Val = CopVal;
2270 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2271 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2278 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2279 ARMOperand *Op = new ARMOperand(k_CCOut);
2280 Op->Reg.RegNum = RegNum;
2286 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2287 ARMOperand *Op = new ARMOperand(k_Token);
2288 Op->Tok.Data = Str.data();
2289 Op->Tok.Length = Str.size();
2295 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2296 ARMOperand *Op = new ARMOperand(k_Register);
2297 Op->Reg.RegNum = RegNum;
2303 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2308 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2309 Op->RegShiftedReg.ShiftTy = ShTy;
2310 Op->RegShiftedReg.SrcReg = SrcReg;
2311 Op->RegShiftedReg.ShiftReg = ShiftReg;
2312 Op->RegShiftedReg.ShiftImm = ShiftImm;
2318 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2322 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2323 Op->RegShiftedImm.ShiftTy = ShTy;
2324 Op->RegShiftedImm.SrcReg = SrcReg;
2325 Op->RegShiftedImm.ShiftImm = ShiftImm;
2331 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2333 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2334 Op->ShifterImm.isASR = isASR;
2335 Op->ShifterImm.Imm = Imm;
2341 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2342 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2343 Op->RotImm.Imm = Imm;
2349 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2351 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2352 Op->Bitfield.LSB = LSB;
2353 Op->Bitfield.Width = Width;
2360 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2361 SMLoc StartLoc, SMLoc EndLoc) {
2362 assert (Regs.size() > 0 && "RegList contains no registers?");
2363 KindTy Kind = k_RegisterList;
2365 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2366 Kind = k_DPRRegisterList;
2367 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2368 contains(Regs.front().second))
2369 Kind = k_SPRRegisterList;
2371 // Sort based on the register encoding values.
2372 array_pod_sort(Regs.begin(), Regs.end());
2374 ARMOperand *Op = new ARMOperand(Kind);
2375 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2376 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2377 Op->Registers.push_back(I->second);
2378 Op->StartLoc = StartLoc;
2379 Op->EndLoc = EndLoc;
2383 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2384 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2385 ARMOperand *Op = new ARMOperand(k_VectorList);
2386 Op->VectorList.RegNum = RegNum;
2387 Op->VectorList.Count = Count;
2388 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2394 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2395 bool isDoubleSpaced,
2397 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2398 Op->VectorList.RegNum = RegNum;
2399 Op->VectorList.Count = Count;
2400 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2406 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2408 bool isDoubleSpaced,
2410 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2411 Op->VectorList.RegNum = RegNum;
2412 Op->VectorList.Count = Count;
2413 Op->VectorList.LaneIndex = Index;
2414 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2420 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2422 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2423 Op->VectorIndex.Val = Idx;
2429 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2430 ARMOperand *Op = new ARMOperand(k_Immediate);
2437 static ARMOperand *CreateMem(unsigned BaseRegNum,
2438 const MCConstantExpr *OffsetImm,
2439 unsigned OffsetRegNum,
2440 ARM_AM::ShiftOpc ShiftType,
2445 ARMOperand *Op = new ARMOperand(k_Memory);
2446 Op->Memory.BaseRegNum = BaseRegNum;
2447 Op->Memory.OffsetImm = OffsetImm;
2448 Op->Memory.OffsetRegNum = OffsetRegNum;
2449 Op->Memory.ShiftType = ShiftType;
2450 Op->Memory.ShiftImm = ShiftImm;
2451 Op->Memory.Alignment = Alignment;
2452 Op->Memory.isNegative = isNegative;
2458 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2459 ARM_AM::ShiftOpc ShiftTy,
2462 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2463 Op->PostIdxReg.RegNum = RegNum;
2464 Op->PostIdxReg.isAdd = isAdd;
2465 Op->PostIdxReg.ShiftTy = ShiftTy;
2466 Op->PostIdxReg.ShiftImm = ShiftImm;
2472 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2473 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2474 Op->MBOpt.Val = Opt;
2480 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2482 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2483 Op->ISBOpt.Val = Opt;
2489 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2490 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2491 Op->IFlags.Val = IFlags;
2497 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2498 ARMOperand *Op = new ARMOperand(k_MSRMask);
2499 Op->MMask.Val = MMask;
2506 } // end anonymous namespace.
2508 void ARMOperand::print(raw_ostream &OS) const {
2511 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2514 OS << "<ccout " << getReg() << ">";
2516 case k_ITCondMask: {
2517 static const char *const MaskStr[] = {
2518 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2519 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2521 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2522 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2526 OS << "<coprocessor number: " << getCoproc() << ">";
2529 OS << "<coprocessor register: " << getCoproc() << ">";
2531 case k_CoprocOption:
2532 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2535 OS << "<mask: " << getMSRMask() << ">";
2538 getImm()->print(OS);
2540 case k_MemBarrierOpt:
2541 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2543 case k_InstSyncBarrierOpt:
2544 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2548 << " base:" << Memory.BaseRegNum;
2551 case k_PostIndexRegister:
2552 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2553 << PostIdxReg.RegNum;
2554 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2555 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2556 << PostIdxReg.ShiftImm;
2559 case k_ProcIFlags: {
2560 OS << "<ARM_PROC::";
2561 unsigned IFlags = getProcIFlags();
2562 for (int i=2; i >= 0; --i)
2563 if (IFlags & (1 << i))
2564 OS << ARM_PROC::IFlagsToString(1 << i);
2569 OS << "<register " << getReg() << ">";
2571 case k_ShifterImmediate:
2572 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2573 << " #" << ShifterImm.Imm << ">";
2575 case k_ShiftedRegister:
2576 OS << "<so_reg_reg "
2577 << RegShiftedReg.SrcReg << " "
2578 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2579 << " " << RegShiftedReg.ShiftReg << ">";
2581 case k_ShiftedImmediate:
2582 OS << "<so_reg_imm "
2583 << RegShiftedImm.SrcReg << " "
2584 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2585 << " #" << RegShiftedImm.ShiftImm << ">";
2587 case k_RotateImmediate:
2588 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2590 case k_BitfieldDescriptor:
2591 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2592 << ", width: " << Bitfield.Width << ">";
2594 case k_RegisterList:
2595 case k_DPRRegisterList:
2596 case k_SPRRegisterList: {
2597 OS << "<register_list ";
2599 const SmallVectorImpl<unsigned> &RegList = getRegList();
2600 for (SmallVectorImpl<unsigned>::const_iterator
2601 I = RegList.begin(), E = RegList.end(); I != E; ) {
2603 if (++I < E) OS << ", ";
2610 OS << "<vector_list " << VectorList.Count << " * "
2611 << VectorList.RegNum << ">";
2613 case k_VectorListAllLanes:
2614 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2615 << VectorList.RegNum << ">";
2617 case k_VectorListIndexed:
2618 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2619 << VectorList.Count << " * " << VectorList.RegNum << ">";
2622 OS << "'" << getToken() << "'";
2625 OS << "<vectorindex " << getVectorIndex() << ">";
2630 /// @name Auto-generated Match Functions
2633 static unsigned MatchRegisterName(StringRef Name);
2637 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2638 SMLoc &StartLoc, SMLoc &EndLoc) {
2639 StartLoc = Parser.getTok().getLoc();
2640 EndLoc = Parser.getTok().getEndLoc();
2641 RegNo = tryParseRegister();
2643 return (RegNo == (unsigned)-1);
2646 /// Try to parse a register name. The token must be an Identifier when called,
2647 /// and if it is a register name the token is eaten and the register number is
2648 /// returned. Otherwise return -1.
2650 int ARMAsmParser::tryParseRegister() {
2651 const AsmToken &Tok = Parser.getTok();
2652 if (Tok.isNot(AsmToken::Identifier)) return -1;
2654 std::string lowerCase = Tok.getString().lower();
2655 unsigned RegNum = MatchRegisterName(lowerCase);
2657 RegNum = StringSwitch<unsigned>(lowerCase)
2658 .Case("r13", ARM::SP)
2659 .Case("r14", ARM::LR)
2660 .Case("r15", ARM::PC)
2661 .Case("ip", ARM::R12)
2662 // Additional register name aliases for 'gas' compatibility.
2663 .Case("a1", ARM::R0)
2664 .Case("a2", ARM::R1)
2665 .Case("a3", ARM::R2)
2666 .Case("a4", ARM::R3)
2667 .Case("v1", ARM::R4)
2668 .Case("v2", ARM::R5)
2669 .Case("v3", ARM::R6)
2670 .Case("v4", ARM::R7)
2671 .Case("v5", ARM::R8)
2672 .Case("v6", ARM::R9)
2673 .Case("v7", ARM::R10)
2674 .Case("v8", ARM::R11)
2675 .Case("sb", ARM::R9)
2676 .Case("sl", ARM::R10)
2677 .Case("fp", ARM::R11)
2681 // Check for aliases registered via .req. Canonicalize to lower case.
2682 // That's more consistent since register names are case insensitive, and
2683 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2684 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2685 // If no match, return failure.
2686 if (Entry == RegisterReqs.end())
2688 Parser.Lex(); // Eat identifier token.
2689 return Entry->getValue();
2692 Parser.Lex(); // Eat identifier token.
2697 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2698 // If a recoverable error occurs, return 1. If an irrecoverable error
2699 // occurs, return -1. An irrecoverable error is one where tokens have been
2700 // consumed in the process of trying to parse the shifter (i.e., when it is
2701 // indeed a shifter operand, but malformed).
2702 int ARMAsmParser::tryParseShiftRegister(
2703 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2704 SMLoc S = Parser.getTok().getLoc();
2705 const AsmToken &Tok = Parser.getTok();
2706 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2708 std::string lowerCase = Tok.getString().lower();
2709 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2710 .Case("asl", ARM_AM::lsl)
2711 .Case("lsl", ARM_AM::lsl)
2712 .Case("lsr", ARM_AM::lsr)
2713 .Case("asr", ARM_AM::asr)
2714 .Case("ror", ARM_AM::ror)
2715 .Case("rrx", ARM_AM::rrx)
2716 .Default(ARM_AM::no_shift);
2718 if (ShiftTy == ARM_AM::no_shift)
2721 Parser.Lex(); // Eat the operator.
2723 // The source register for the shift has already been added to the
2724 // operand list, so we need to pop it off and combine it into the shifted
2725 // register operand instead.
2726 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2727 if (!PrevOp->isReg())
2728 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2729 int SrcReg = PrevOp->getReg();
2734 if (ShiftTy == ARM_AM::rrx) {
2735 // RRX Doesn't have an explicit shift amount. The encoder expects
2736 // the shift register to be the same as the source register. Seems odd,
2740 // Figure out if this is shifted by a constant or a register (for non-RRX).
2741 if (Parser.getTok().is(AsmToken::Hash) ||
2742 Parser.getTok().is(AsmToken::Dollar)) {
2743 Parser.Lex(); // Eat hash.
2744 SMLoc ImmLoc = Parser.getTok().getLoc();
2745 const MCExpr *ShiftExpr = 0;
2746 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2747 Error(ImmLoc, "invalid immediate shift value");
2750 // The expression must be evaluatable as an immediate.
2751 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2753 Error(ImmLoc, "invalid immediate shift value");
2756 // Range check the immediate.
2757 // lsl, ror: 0 <= imm <= 31
2758 // lsr, asr: 0 <= imm <= 32
2759 Imm = CE->getValue();
2761 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2762 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2763 Error(ImmLoc, "immediate shift value out of range");
2766 // shift by zero is a nop. Always send it through as lsl.
2767 // ('as' compatibility)
2769 ShiftTy = ARM_AM::lsl;
2770 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2771 SMLoc L = Parser.getTok().getLoc();
2772 EndLoc = Parser.getTok().getEndLoc();
2773 ShiftReg = tryParseRegister();
2774 if (ShiftReg == -1) {
2775 Error (L, "expected immediate or register in shift operand");
2779 Error (Parser.getTok().getLoc(),
2780 "expected immediate or register in shift operand");
2785 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2786 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2790 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2797 /// Try to parse a register name. The token must be an Identifier when called.
2798 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2799 /// if there is a "writeback". 'true' if it's not a register.
2801 /// TODO this is likely to change to allow different register types and or to
2802 /// parse for a specific register type.
2804 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2805 const AsmToken &RegTok = Parser.getTok();
2806 int RegNo = tryParseRegister();
2810 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2811 RegTok.getEndLoc()));
2813 const AsmToken &ExclaimTok = Parser.getTok();
2814 if (ExclaimTok.is(AsmToken::Exclaim)) {
2815 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2816 ExclaimTok.getLoc()));
2817 Parser.Lex(); // Eat exclaim token
2821 // Also check for an index operand. This is only legal for vector registers,
2822 // but that'll get caught OK in operand matching, so we don't need to
2823 // explicitly filter everything else out here.
2824 if (Parser.getTok().is(AsmToken::LBrac)) {
2825 SMLoc SIdx = Parser.getTok().getLoc();
2826 Parser.Lex(); // Eat left bracket token.
2828 const MCExpr *ImmVal;
2829 if (getParser().parseExpression(ImmVal))
2831 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2833 return TokError("immediate value expected for vector index");
2835 if (Parser.getTok().isNot(AsmToken::RBrac))
2836 return Error(Parser.getTok().getLoc(), "']' expected");
2838 SMLoc E = Parser.getTok().getEndLoc();
2839 Parser.Lex(); // Eat right bracket token.
2841 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2849 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2850 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2852 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2853 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2855 switch (Name.size()) {
2858 if (Name[0] != CoprocOp)
2874 if (Name[0] != CoprocOp || Name[1] != '1')
2878 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
2879 case '0': return CoprocOp == 'p'? -1: 10;
2880 case '1': return CoprocOp == 'p'? -1: 11;
2881 case '2': return 12;
2882 case '3': return 13;
2883 case '4': return 14;
2884 case '5': return 15;
2889 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2890 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2891 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2892 SMLoc S = Parser.getTok().getLoc();
2893 const AsmToken &Tok = Parser.getTok();
2894 if (!Tok.is(AsmToken::Identifier))
2895 return MatchOperand_NoMatch;
2896 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2897 .Case("eq", ARMCC::EQ)
2898 .Case("ne", ARMCC::NE)
2899 .Case("hs", ARMCC::HS)
2900 .Case("cs", ARMCC::HS)
2901 .Case("lo", ARMCC::LO)
2902 .Case("cc", ARMCC::LO)
2903 .Case("mi", ARMCC::MI)
2904 .Case("pl", ARMCC::PL)
2905 .Case("vs", ARMCC::VS)
2906 .Case("vc", ARMCC::VC)
2907 .Case("hi", ARMCC::HI)
2908 .Case("ls", ARMCC::LS)
2909 .Case("ge", ARMCC::GE)
2910 .Case("lt", ARMCC::LT)
2911 .Case("gt", ARMCC::GT)
2912 .Case("le", ARMCC::LE)
2913 .Case("al", ARMCC::AL)
2916 return MatchOperand_NoMatch;
2917 Parser.Lex(); // Eat the token.
2919 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2921 return MatchOperand_Success;
2924 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2925 /// token must be an Identifier when called, and if it is a coprocessor
2926 /// number, the token is eaten and the operand is added to the operand list.
2927 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2928 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2929 SMLoc S = Parser.getTok().getLoc();
2930 const AsmToken &Tok = Parser.getTok();
2931 if (Tok.isNot(AsmToken::Identifier))
2932 return MatchOperand_NoMatch;
2934 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2936 return MatchOperand_NoMatch;
2938 Parser.Lex(); // Eat identifier token.
2939 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2940 return MatchOperand_Success;
2943 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2944 /// token must be an Identifier when called, and if it is a coprocessor
2945 /// number, the token is eaten and the operand is added to the operand list.
2946 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2947 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2948 SMLoc S = Parser.getTok().getLoc();
2949 const AsmToken &Tok = Parser.getTok();
2950 if (Tok.isNot(AsmToken::Identifier))
2951 return MatchOperand_NoMatch;
2953 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2955 return MatchOperand_NoMatch;
2957 Parser.Lex(); // Eat identifier token.
2958 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2959 return MatchOperand_Success;
2962 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2963 /// coproc_option : '{' imm0_255 '}'
2964 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2965 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2966 SMLoc S = Parser.getTok().getLoc();
2968 // If this isn't a '{', this isn't a coprocessor immediate operand.
2969 if (Parser.getTok().isNot(AsmToken::LCurly))
2970 return MatchOperand_NoMatch;
2971 Parser.Lex(); // Eat the '{'
2974 SMLoc Loc = Parser.getTok().getLoc();
2975 if (getParser().parseExpression(Expr)) {
2976 Error(Loc, "illegal expression");
2977 return MatchOperand_ParseFail;
2979 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2980 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2981 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2982 return MatchOperand_ParseFail;
2984 int Val = CE->getValue();
2986 // Check for and consume the closing '}'
2987 if (Parser.getTok().isNot(AsmToken::RCurly))
2988 return MatchOperand_ParseFail;
2989 SMLoc E = Parser.getTok().getEndLoc();
2990 Parser.Lex(); // Eat the '}'
2992 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2993 return MatchOperand_Success;
2996 // For register list parsing, we need to map from raw GPR register numbering
2997 // to the enumeration values. The enumeration values aren't sorted by
2998 // register number due to our using "sp", "lr" and "pc" as canonical names.
2999 static unsigned getNextRegister(unsigned Reg) {
3000 // If this is a GPR, we need to do it manually, otherwise we can rely
3001 // on the sort ordering of the enumeration since the other reg-classes
3003 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3006 default: llvm_unreachable("Invalid GPR number!");
3007 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3008 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3009 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3010 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3011 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3012 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3013 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3014 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3018 // Return the low-subreg of a given Q register.
3019 static unsigned getDRegFromQReg(unsigned QReg) {
3021 default: llvm_unreachable("expected a Q register!");
3022 case ARM::Q0: return ARM::D0;
3023 case ARM::Q1: return ARM::D2;
3024 case ARM::Q2: return ARM::D4;
3025 case ARM::Q3: return ARM::D6;
3026 case ARM::Q4: return ARM::D8;
3027 case ARM::Q5: return ARM::D10;
3028 case ARM::Q6: return ARM::D12;
3029 case ARM::Q7: return ARM::D14;
3030 case ARM::Q8: return ARM::D16;
3031 case ARM::Q9: return ARM::D18;
3032 case ARM::Q10: return ARM::D20;
3033 case ARM::Q11: return ARM::D22;
3034 case ARM::Q12: return ARM::D24;
3035 case ARM::Q13: return ARM::D26;
3036 case ARM::Q14: return ARM::D28;
3037 case ARM::Q15: return ARM::D30;
3041 /// Parse a register list.
3043 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3044 assert(Parser.getTok().is(AsmToken::LCurly) &&
3045 "Token is not a Left Curly Brace");
3046 SMLoc S = Parser.getTok().getLoc();
3047 Parser.Lex(); // Eat '{' token.
3048 SMLoc RegLoc = Parser.getTok().getLoc();
3050 // Check the first register in the list to see what register class
3051 // this is a list of.
3052 int Reg = tryParseRegister();
3054 return Error(RegLoc, "register expected");
3056 // The reglist instructions have at most 16 registers, so reserve
3057 // space for that many.
3059 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3061 // Allow Q regs and just interpret them as the two D sub-registers.
3062 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3063 Reg = getDRegFromQReg(Reg);
3064 EReg = MRI->getEncodingValue(Reg);
3065 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3068 const MCRegisterClass *RC;
3069 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3070 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3071 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3072 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3073 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3074 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3076 return Error(RegLoc, "invalid register in register list");
3078 // Store the register.
3079 EReg = MRI->getEncodingValue(Reg);
3080 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3082 // This starts immediately after the first register token in the list,
3083 // so we can see either a comma or a minus (range separator) as a legal
3085 while (Parser.getTok().is(AsmToken::Comma) ||
3086 Parser.getTok().is(AsmToken::Minus)) {
3087 if (Parser.getTok().is(AsmToken::Minus)) {
3088 Parser.Lex(); // Eat the minus.
3089 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3090 int EndReg = tryParseRegister();
3092 return Error(AfterMinusLoc, "register expected");
3093 // Allow Q regs and just interpret them as the two D sub-registers.
3094 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3095 EndReg = getDRegFromQReg(EndReg) + 1;
3096 // If the register is the same as the start reg, there's nothing
3100 // The register must be in the same register class as the first.
3101 if (!RC->contains(EndReg))
3102 return Error(AfterMinusLoc, "invalid register in register list");
3103 // Ranges must go from low to high.
3104 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3105 return Error(AfterMinusLoc, "bad range in register list");
3107 // Add all the registers in the range to the register list.
3108 while (Reg != EndReg) {
3109 Reg = getNextRegister(Reg);
3110 EReg = MRI->getEncodingValue(Reg);
3111 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3115 Parser.Lex(); // Eat the comma.
3116 RegLoc = Parser.getTok().getLoc();
3118 const AsmToken RegTok = Parser.getTok();
3119 Reg = tryParseRegister();
3121 return Error(RegLoc, "register expected");
3122 // Allow Q regs and just interpret them as the two D sub-registers.
3123 bool isQReg = false;
3124 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3125 Reg = getDRegFromQReg(Reg);
3128 // The register must be in the same register class as the first.
3129 if (!RC->contains(Reg))
3130 return Error(RegLoc, "invalid register in register list");
3131 // List must be monotonically increasing.
3132 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3133 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3134 Warning(RegLoc, "register list not in ascending order");
3136 return Error(RegLoc, "register list not in ascending order");
3138 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3139 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3140 ") in register list");
3143 // VFP register lists must also be contiguous.
3144 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3146 return Error(RegLoc, "non-contiguous register range");
3147 EReg = MRI->getEncodingValue(Reg);
3148 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3150 EReg = MRI->getEncodingValue(++Reg);
3151 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3155 if (Parser.getTok().isNot(AsmToken::RCurly))
3156 return Error(Parser.getTok().getLoc(), "'}' expected");
3157 SMLoc E = Parser.getTok().getEndLoc();
3158 Parser.Lex(); // Eat '}' token.
3160 // Push the register list operand.
3161 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3163 // The ARM system instruction variants for LDM/STM have a '^' token here.
3164 if (Parser.getTok().is(AsmToken::Caret)) {
3165 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3166 Parser.Lex(); // Eat '^' token.
3172 // Helper function to parse the lane index for vector lists.
3173 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3174 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3175 Index = 0; // Always return a defined index value.
3176 if (Parser.getTok().is(AsmToken::LBrac)) {
3177 Parser.Lex(); // Eat the '['.
3178 if (Parser.getTok().is(AsmToken::RBrac)) {
3179 // "Dn[]" is the 'all lanes' syntax.
3180 LaneKind = AllLanes;
3181 EndLoc = Parser.getTok().getEndLoc();
3182 Parser.Lex(); // Eat the ']'.
3183 return MatchOperand_Success;
3186 // There's an optional '#' token here. Normally there wouldn't be, but
3187 // inline assemble puts one in, and it's friendly to accept that.
3188 if (Parser.getTok().is(AsmToken::Hash))
3189 Parser.Lex(); // Eat '#' or '$'.
3191 const MCExpr *LaneIndex;
3192 SMLoc Loc = Parser.getTok().getLoc();
3193 if (getParser().parseExpression(LaneIndex)) {
3194 Error(Loc, "illegal expression");
3195 return MatchOperand_ParseFail;
3197 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3199 Error(Loc, "lane index must be empty or an integer");
3200 return MatchOperand_ParseFail;
3202 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3203 Error(Parser.getTok().getLoc(), "']' expected");
3204 return MatchOperand_ParseFail;
3206 EndLoc = Parser.getTok().getEndLoc();
3207 Parser.Lex(); // Eat the ']'.
3208 int64_t Val = CE->getValue();
3210 // FIXME: Make this range check context sensitive for .8, .16, .32.
3211 if (Val < 0 || Val > 7) {
3212 Error(Parser.getTok().getLoc(), "lane index out of range");
3213 return MatchOperand_ParseFail;
3216 LaneKind = IndexedLane;
3217 return MatchOperand_Success;
3220 return MatchOperand_Success;
3223 // parse a vector register list
3224 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3225 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3226 VectorLaneTy LaneKind;
3228 SMLoc S = Parser.getTok().getLoc();
3229 // As an extension (to match gas), support a plain D register or Q register
3230 // (without encosing curly braces) as a single or double entry list,
3232 if (Parser.getTok().is(AsmToken::Identifier)) {
3233 SMLoc E = Parser.getTok().getEndLoc();
3234 int Reg = tryParseRegister();
3236 return MatchOperand_NoMatch;
3237 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3238 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3239 if (Res != MatchOperand_Success)
3243 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3246 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3250 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3255 return MatchOperand_Success;
3257 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3258 Reg = getDRegFromQReg(Reg);
3259 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3260 if (Res != MatchOperand_Success)
3264 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3265 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3266 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3269 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3270 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3271 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3275 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3280 return MatchOperand_Success;
3282 Error(S, "vector register expected");
3283 return MatchOperand_ParseFail;
3286 if (Parser.getTok().isNot(AsmToken::LCurly))
3287 return MatchOperand_NoMatch;
3289 Parser.Lex(); // Eat '{' token.
3290 SMLoc RegLoc = Parser.getTok().getLoc();
3292 int Reg = tryParseRegister();
3294 Error(RegLoc, "register expected");
3295 return MatchOperand_ParseFail;
3299 unsigned FirstReg = Reg;
3300 // The list is of D registers, but we also allow Q regs and just interpret
3301 // them as the two D sub-registers.
3302 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3303 FirstReg = Reg = getDRegFromQReg(Reg);
3304 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3305 // it's ambiguous with four-register single spaced.
3311 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3312 return MatchOperand_ParseFail;
3314 while (Parser.getTok().is(AsmToken::Comma) ||
3315 Parser.getTok().is(AsmToken::Minus)) {
3316 if (Parser.getTok().is(AsmToken::Minus)) {
3318 Spacing = 1; // Register range implies a single spaced list.
3319 else if (Spacing == 2) {
3320 Error(Parser.getTok().getLoc(),
3321 "sequential registers in double spaced list");
3322 return MatchOperand_ParseFail;
3324 Parser.Lex(); // Eat the minus.
3325 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3326 int EndReg = tryParseRegister();
3328 Error(AfterMinusLoc, "register expected");
3329 return MatchOperand_ParseFail;
3331 // Allow Q regs and just interpret them as the two D sub-registers.
3332 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3333 EndReg = getDRegFromQReg(EndReg) + 1;
3334 // If the register is the same as the start reg, there's nothing
3338 // The register must be in the same register class as the first.
3339 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3340 Error(AfterMinusLoc, "invalid register in register list");
3341 return MatchOperand_ParseFail;
3343 // Ranges must go from low to high.
3345 Error(AfterMinusLoc, "bad range in register list");
3346 return MatchOperand_ParseFail;
3348 // Parse the lane specifier if present.
3349 VectorLaneTy NextLaneKind;
3350 unsigned NextLaneIndex;
3351 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3352 MatchOperand_Success)
3353 return MatchOperand_ParseFail;
3354 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3355 Error(AfterMinusLoc, "mismatched lane index in register list");
3356 return MatchOperand_ParseFail;
3359 // Add all the registers in the range to the register list.
3360 Count += EndReg - Reg;
3364 Parser.Lex(); // Eat the comma.
3365 RegLoc = Parser.getTok().getLoc();
3367 Reg = tryParseRegister();
3369 Error(RegLoc, "register expected");
3370 return MatchOperand_ParseFail;
3372 // vector register lists must be contiguous.
3373 // It's OK to use the enumeration values directly here rather, as the
3374 // VFP register classes have the enum sorted properly.
3376 // The list is of D registers, but we also allow Q regs and just interpret
3377 // them as the two D sub-registers.
3378 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3380 Spacing = 1; // Register range implies a single spaced list.
3381 else if (Spacing == 2) {
3383 "invalid register in double-spaced list (must be 'D' register')");
3384 return MatchOperand_ParseFail;
3386 Reg = getDRegFromQReg(Reg);
3387 if (Reg != OldReg + 1) {
3388 Error(RegLoc, "non-contiguous register range");
3389 return MatchOperand_ParseFail;
3393 // Parse the lane specifier if present.
3394 VectorLaneTy NextLaneKind;
3395 unsigned NextLaneIndex;
3396 SMLoc LaneLoc = Parser.getTok().getLoc();
3397 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3398 MatchOperand_Success)
3399 return MatchOperand_ParseFail;
3400 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3401 Error(LaneLoc, "mismatched lane index in register list");
3402 return MatchOperand_ParseFail;
3406 // Normal D register.
3407 // Figure out the register spacing (single or double) of the list if
3408 // we don't know it already.
3410 Spacing = 1 + (Reg == OldReg + 2);
3412 // Just check that it's contiguous and keep going.
3413 if (Reg != OldReg + Spacing) {
3414 Error(RegLoc, "non-contiguous register range");
3415 return MatchOperand_ParseFail;
3418 // Parse the lane specifier if present.
3419 VectorLaneTy NextLaneKind;
3420 unsigned NextLaneIndex;
3421 SMLoc EndLoc = Parser.getTok().getLoc();
3422 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3423 return MatchOperand_ParseFail;
3424 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3425 Error(EndLoc, "mismatched lane index in register list");
3426 return MatchOperand_ParseFail;
3430 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3431 Error(Parser.getTok().getLoc(), "'}' expected");
3432 return MatchOperand_ParseFail;
3434 E = Parser.getTok().getEndLoc();
3435 Parser.Lex(); // Eat '}' token.
3439 // Two-register operands have been converted to the
3440 // composite register classes.
3442 const MCRegisterClass *RC = (Spacing == 1) ?
3443 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3444 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3445 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3448 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3449 (Spacing == 2), S, E));
3452 // Two-register operands have been converted to the
3453 // composite register classes.
3455 const MCRegisterClass *RC = (Spacing == 1) ?
3456 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3457 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3458 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3460 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3465 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3471 return MatchOperand_Success;
3474 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3475 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3476 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3477 SMLoc S = Parser.getTok().getLoc();
3478 const AsmToken &Tok = Parser.getTok();
3481 if (Tok.is(AsmToken::Identifier)) {
3482 StringRef OptStr = Tok.getString();
3484 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3485 .Case("sy", ARM_MB::SY)
3486 .Case("st", ARM_MB::ST)
3487 .Case("ld", ARM_MB::LD)
3488 .Case("sh", ARM_MB::ISH)
3489 .Case("ish", ARM_MB::ISH)
3490 .Case("shst", ARM_MB::ISHST)
3491 .Case("ishst", ARM_MB::ISHST)
3492 .Case("ishld", ARM_MB::ISHLD)
3493 .Case("nsh", ARM_MB::NSH)
3494 .Case("un", ARM_MB::NSH)
3495 .Case("nshst", ARM_MB::NSHST)
3496 .Case("nshld", ARM_MB::NSHLD)
3497 .Case("unst", ARM_MB::NSHST)
3498 .Case("osh", ARM_MB::OSH)
3499 .Case("oshst", ARM_MB::OSHST)
3500 .Case("oshld", ARM_MB::OSHLD)
3503 // ishld, oshld, nshld and ld are only available from ARMv8.
3504 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3505 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3509 return MatchOperand_NoMatch;
3511 Parser.Lex(); // Eat identifier token.
3512 } else if (Tok.is(AsmToken::Hash) ||
3513 Tok.is(AsmToken::Dollar) ||
3514 Tok.is(AsmToken::Integer)) {
3515 if (Parser.getTok().isNot(AsmToken::Integer))
3516 Parser.Lex(); // Eat '#' or '$'.
3517 SMLoc Loc = Parser.getTok().getLoc();
3519 const MCExpr *MemBarrierID;
3520 if (getParser().parseExpression(MemBarrierID)) {
3521 Error(Loc, "illegal expression");
3522 return MatchOperand_ParseFail;
3525 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3527 Error(Loc, "constant expression expected");
3528 return MatchOperand_ParseFail;
3531 int Val = CE->getValue();
3533 Error(Loc, "immediate value out of range");
3534 return MatchOperand_ParseFail;
3537 Opt = ARM_MB::RESERVED_0 + Val;
3539 return MatchOperand_ParseFail;
3541 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3542 return MatchOperand_Success;
3545 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3546 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3547 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3548 SMLoc S = Parser.getTok().getLoc();
3549 const AsmToken &Tok = Parser.getTok();
3552 if (Tok.is(AsmToken::Identifier)) {
3553 StringRef OptStr = Tok.getString();
3555 if (OptStr.equals_lower("sy"))
3558 return MatchOperand_NoMatch;
3560 Parser.Lex(); // Eat identifier token.
3561 } else if (Tok.is(AsmToken::Hash) ||
3562 Tok.is(AsmToken::Dollar) ||
3563 Tok.is(AsmToken::Integer)) {
3564 if (Parser.getTok().isNot(AsmToken::Integer))
3565 Parser.Lex(); // Eat '#' or '$'.
3566 SMLoc Loc = Parser.getTok().getLoc();
3568 const MCExpr *ISBarrierID;
3569 if (getParser().parseExpression(ISBarrierID)) {
3570 Error(Loc, "illegal expression");
3571 return MatchOperand_ParseFail;
3574 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3576 Error(Loc, "constant expression expected");
3577 return MatchOperand_ParseFail;
3580 int Val = CE->getValue();
3582 Error(Loc, "immediate value out of range");
3583 return MatchOperand_ParseFail;
3586 Opt = ARM_ISB::RESERVED_0 + Val;
3588 return MatchOperand_ParseFail;
3590 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3591 (ARM_ISB::InstSyncBOpt)Opt, S));
3592 return MatchOperand_Success;
3596 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3597 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3598 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3599 SMLoc S = Parser.getTok().getLoc();
3600 const AsmToken &Tok = Parser.getTok();
3601 if (!Tok.is(AsmToken::Identifier))
3602 return MatchOperand_NoMatch;
3603 StringRef IFlagsStr = Tok.getString();
3605 // An iflags string of "none" is interpreted to mean that none of the AIF
3606 // bits are set. Not a terribly useful instruction, but a valid encoding.
3607 unsigned IFlags = 0;
3608 if (IFlagsStr != "none") {
3609 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3610 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3611 .Case("a", ARM_PROC::A)
3612 .Case("i", ARM_PROC::I)
3613 .Case("f", ARM_PROC::F)
3616 // If some specific iflag is already set, it means that some letter is
3617 // present more than once, this is not acceptable.
3618 if (Flag == ~0U || (IFlags & Flag))
3619 return MatchOperand_NoMatch;
3625 Parser.Lex(); // Eat identifier token.
3626 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3627 return MatchOperand_Success;
3630 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3631 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3632 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3633 SMLoc S = Parser.getTok().getLoc();
3634 const AsmToken &Tok = Parser.getTok();
3635 if (!Tok.is(AsmToken::Identifier))
3636 return MatchOperand_NoMatch;
3637 StringRef Mask = Tok.getString();
3640 // See ARMv6-M 10.1.1
3641 std::string Name = Mask.lower();
3642 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3643 // Note: in the documentation:
3644 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3645 // for MSR APSR_nzcvq.
3646 // but we do make it an alias here. This is so to get the "mask encoding"
3647 // bits correct on MSR APSR writes.
3649 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3650 // should really only be allowed when writing a special register. Note
3651 // they get dropped in the MRS instruction reading a special register as
3652 // the SYSm field is only 8 bits.
3654 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3655 // includes the DSP extension but that is not checked.
3656 .Case("apsr", 0x800)
3657 .Case("apsr_nzcvq", 0x800)
3658 .Case("apsr_g", 0x400)
3659 .Case("apsr_nzcvqg", 0xc00)
3660 .Case("iapsr", 0x801)
3661 .Case("iapsr_nzcvq", 0x801)
3662 .Case("iapsr_g", 0x401)
3663 .Case("iapsr_nzcvqg", 0xc01)
3664 .Case("eapsr", 0x802)
3665 .Case("eapsr_nzcvq", 0x802)
3666 .Case("eapsr_g", 0x402)
3667 .Case("eapsr_nzcvqg", 0xc02)
3668 .Case("xpsr", 0x803)
3669 .Case("xpsr_nzcvq", 0x803)
3670 .Case("xpsr_g", 0x403)
3671 .Case("xpsr_nzcvqg", 0xc03)
3672 .Case("ipsr", 0x805)
3673 .Case("epsr", 0x806)
3674 .Case("iepsr", 0x807)
3677 .Case("primask", 0x810)
3678 .Case("basepri", 0x811)
3679 .Case("basepri_max", 0x812)
3680 .Case("faultmask", 0x813)
3681 .Case("control", 0x814)
3684 if (FlagsVal == ~0U)
3685 return MatchOperand_NoMatch;
3687 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3688 // basepri, basepri_max and faultmask only valid for V7m.
3689 return MatchOperand_NoMatch;
3691 Parser.Lex(); // Eat identifier token.
3692 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3693 return MatchOperand_Success;
3696 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3697 size_t Start = 0, Next = Mask.find('_');
3698 StringRef Flags = "";
3699 std::string SpecReg = Mask.slice(Start, Next).lower();
3700 if (Next != StringRef::npos)
3701 Flags = Mask.slice(Next+1, Mask.size());
3703 // FlagsVal contains the complete mask:
3705 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3706 unsigned FlagsVal = 0;
3708 if (SpecReg == "apsr") {
3709 FlagsVal = StringSwitch<unsigned>(Flags)
3710 .Case("nzcvq", 0x8) // same as CPSR_f
3711 .Case("g", 0x4) // same as CPSR_s
3712 .Case("nzcvqg", 0xc) // same as CPSR_fs
3715 if (FlagsVal == ~0U) {
3717 return MatchOperand_NoMatch;
3719 FlagsVal = 8; // No flag
3721 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3722 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3723 if (Flags == "all" || Flags == "")
3725 for (int i = 0, e = Flags.size(); i != e; ++i) {
3726 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3733 // If some specific flag is already set, it means that some letter is
3734 // present more than once, this is not acceptable.
3735 if (FlagsVal == ~0U || (FlagsVal & Flag))
3736 return MatchOperand_NoMatch;
3739 } else // No match for special register.
3740 return MatchOperand_NoMatch;
3742 // Special register without flags is NOT equivalent to "fc" flags.
3743 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3744 // two lines would enable gas compatibility at the expense of breaking
3750 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3751 if (SpecReg == "spsr")
3754 Parser.Lex(); // Eat identifier token.
3755 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3756 return MatchOperand_Success;
3759 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3760 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3761 int Low, int High) {
3762 const AsmToken &Tok = Parser.getTok();
3763 if (Tok.isNot(AsmToken::Identifier)) {
3764 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3765 return MatchOperand_ParseFail;
3767 StringRef ShiftName = Tok.getString();
3768 std::string LowerOp = Op.lower();
3769 std::string UpperOp = Op.upper();
3770 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3771 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3772 return MatchOperand_ParseFail;
3774 Parser.Lex(); // Eat shift type token.
3776 // There must be a '#' and a shift amount.
3777 if (Parser.getTok().isNot(AsmToken::Hash) &&
3778 Parser.getTok().isNot(AsmToken::Dollar)) {
3779 Error(Parser.getTok().getLoc(), "'#' expected");
3780 return MatchOperand_ParseFail;
3782 Parser.Lex(); // Eat hash token.
3784 const MCExpr *ShiftAmount;
3785 SMLoc Loc = Parser.getTok().getLoc();
3787 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3788 Error(Loc, "illegal expression");
3789 return MatchOperand_ParseFail;
3791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3793 Error(Loc, "constant expression expected");
3794 return MatchOperand_ParseFail;
3796 int Val = CE->getValue();
3797 if (Val < Low || Val > High) {
3798 Error(Loc, "immediate value out of range");
3799 return MatchOperand_ParseFail;
3802 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3804 return MatchOperand_Success;
3807 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3808 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3809 const AsmToken &Tok = Parser.getTok();
3810 SMLoc S = Tok.getLoc();
3811 if (Tok.isNot(AsmToken::Identifier)) {
3812 Error(S, "'be' or 'le' operand expected");
3813 return MatchOperand_ParseFail;
3815 int Val = StringSwitch<int>(Tok.getString().lower())
3819 Parser.Lex(); // Eat the token.
3822 Error(S, "'be' or 'le' operand expected");
3823 return MatchOperand_ParseFail;
3825 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3827 S, Tok.getEndLoc()));
3828 return MatchOperand_Success;
3831 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3832 /// instructions. Legal values are:
3833 /// lsl #n 'n' in [0,31]
3834 /// asr #n 'n' in [1,32]
3835 /// n == 32 encoded as n == 0.
3836 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3837 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3838 const AsmToken &Tok = Parser.getTok();
3839 SMLoc S = Tok.getLoc();
3840 if (Tok.isNot(AsmToken::Identifier)) {
3841 Error(S, "shift operator 'asr' or 'lsl' expected");
3842 return MatchOperand_ParseFail;
3844 StringRef ShiftName = Tok.getString();
3846 if (ShiftName == "lsl" || ShiftName == "LSL")
3848 else if (ShiftName == "asr" || ShiftName == "ASR")
3851 Error(S, "shift operator 'asr' or 'lsl' expected");
3852 return MatchOperand_ParseFail;
3854 Parser.Lex(); // Eat the operator.
3856 // A '#' and a shift amount.
3857 if (Parser.getTok().isNot(AsmToken::Hash) &&
3858 Parser.getTok().isNot(AsmToken::Dollar)) {
3859 Error(Parser.getTok().getLoc(), "'#' expected");
3860 return MatchOperand_ParseFail;
3862 Parser.Lex(); // Eat hash token.
3863 SMLoc ExLoc = Parser.getTok().getLoc();
3865 const MCExpr *ShiftAmount;
3867 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3868 Error(ExLoc, "malformed shift expression");
3869 return MatchOperand_ParseFail;
3871 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3873 Error(ExLoc, "shift amount must be an immediate");
3874 return MatchOperand_ParseFail;
3877 int64_t Val = CE->getValue();
3879 // Shift amount must be in [1,32]
3880 if (Val < 1 || Val > 32) {
3881 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3882 return MatchOperand_ParseFail;
3884 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3885 if (isThumb() && Val == 32) {
3886 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3887 return MatchOperand_ParseFail;
3889 if (Val == 32) Val = 0;
3891 // Shift amount must be in [1,32]
3892 if (Val < 0 || Val > 31) {
3893 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3894 return MatchOperand_ParseFail;
3898 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3900 return MatchOperand_Success;
3903 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3904 /// of instructions. Legal values are:
3905 /// ror #n 'n' in {0, 8, 16, 24}
3906 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3907 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3908 const AsmToken &Tok = Parser.getTok();
3909 SMLoc S = Tok.getLoc();
3910 if (Tok.isNot(AsmToken::Identifier))
3911 return MatchOperand_NoMatch;
3912 StringRef ShiftName = Tok.getString();
3913 if (ShiftName != "ror" && ShiftName != "ROR")
3914 return MatchOperand_NoMatch;
3915 Parser.Lex(); // Eat the operator.
3917 // A '#' and a rotate amount.
3918 if (Parser.getTok().isNot(AsmToken::Hash) &&
3919 Parser.getTok().isNot(AsmToken::Dollar)) {
3920 Error(Parser.getTok().getLoc(), "'#' expected");
3921 return MatchOperand_ParseFail;
3923 Parser.Lex(); // Eat hash token.
3924 SMLoc ExLoc = Parser.getTok().getLoc();
3926 const MCExpr *ShiftAmount;
3928 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3929 Error(ExLoc, "malformed rotate expression");
3930 return MatchOperand_ParseFail;
3932 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3934 Error(ExLoc, "rotate amount must be an immediate");
3935 return MatchOperand_ParseFail;
3938 int64_t Val = CE->getValue();
3939 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3940 // normally, zero is represented in asm by omitting the rotate operand
3942 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3943 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
3944 return MatchOperand_ParseFail;
3947 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
3949 return MatchOperand_Success;
3952 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3953 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3954 SMLoc S = Parser.getTok().getLoc();
3955 // The bitfield descriptor is really two operands, the LSB and the width.
3956 if (Parser.getTok().isNot(AsmToken::Hash) &&
3957 Parser.getTok().isNot(AsmToken::Dollar)) {
3958 Error(Parser.getTok().getLoc(), "'#' expected");
3959 return MatchOperand_ParseFail;
3961 Parser.Lex(); // Eat hash token.
3963 const MCExpr *LSBExpr;
3964 SMLoc E = Parser.getTok().getLoc();
3965 if (getParser().parseExpression(LSBExpr)) {
3966 Error(E, "malformed immediate expression");
3967 return MatchOperand_ParseFail;
3969 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3971 Error(E, "'lsb' operand must be an immediate");
3972 return MatchOperand_ParseFail;
3975 int64_t LSB = CE->getValue();
3976 // The LSB must be in the range [0,31]
3977 if (LSB < 0 || LSB > 31) {
3978 Error(E, "'lsb' operand must be in the range [0,31]");
3979 return MatchOperand_ParseFail;
3981 E = Parser.getTok().getLoc();
3983 // Expect another immediate operand.
3984 if (Parser.getTok().isNot(AsmToken::Comma)) {
3985 Error(Parser.getTok().getLoc(), "too few operands");
3986 return MatchOperand_ParseFail;
3988 Parser.Lex(); // Eat hash token.
3989 if (Parser.getTok().isNot(AsmToken::Hash) &&
3990 Parser.getTok().isNot(AsmToken::Dollar)) {
3991 Error(Parser.getTok().getLoc(), "'#' expected");
3992 return MatchOperand_ParseFail;
3994 Parser.Lex(); // Eat hash token.
3996 const MCExpr *WidthExpr;
3998 if (getParser().parseExpression(WidthExpr, EndLoc)) {
3999 Error(E, "malformed immediate expression");
4000 return MatchOperand_ParseFail;
4002 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4004 Error(E, "'width' operand must be an immediate");
4005 return MatchOperand_ParseFail;
4008 int64_t Width = CE->getValue();
4009 // The LSB must be in the range [1,32-lsb]
4010 if (Width < 1 || Width > 32 - LSB) {
4011 Error(E, "'width' operand must be in the range [1,32-lsb]");
4012 return MatchOperand_ParseFail;
4015 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
4017 return MatchOperand_Success;
4020 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4021 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4022 // Check for a post-index addressing register operand. Specifically:
4023 // postidx_reg := '+' register {, shift}
4024 // | '-' register {, shift}
4025 // | register {, shift}
4027 // This method must return MatchOperand_NoMatch without consuming any tokens
4028 // in the case where there is no match, as other alternatives take other
4030 AsmToken Tok = Parser.getTok();
4031 SMLoc S = Tok.getLoc();
4032 bool haveEaten = false;
4034 if (Tok.is(AsmToken::Plus)) {
4035 Parser.Lex(); // Eat the '+' token.
4037 } else if (Tok.is(AsmToken::Minus)) {
4038 Parser.Lex(); // Eat the '-' token.
4043 SMLoc E = Parser.getTok().getEndLoc();
4044 int Reg = tryParseRegister();
4047 return MatchOperand_NoMatch;
4048 Error(Parser.getTok().getLoc(), "register expected");
4049 return MatchOperand_ParseFail;
4052 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4053 unsigned ShiftImm = 0;
4054 if (Parser.getTok().is(AsmToken::Comma)) {
4055 Parser.Lex(); // Eat the ','.
4056 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4057 return MatchOperand_ParseFail;
4059 // FIXME: Only approximates end...may include intervening whitespace.
4060 E = Parser.getTok().getLoc();
4063 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4066 return MatchOperand_Success;
4069 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4070 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4071 // Check for a post-index addressing register operand. Specifically:
4072 // am3offset := '+' register
4079 // This method must return MatchOperand_NoMatch without consuming any tokens
4080 // in the case where there is no match, as other alternatives take other
4082 AsmToken Tok = Parser.getTok();
4083 SMLoc S = Tok.getLoc();
4085 // Do immediates first, as we always parse those if we have a '#'.
4086 if (Parser.getTok().is(AsmToken::Hash) ||
4087 Parser.getTok().is(AsmToken::Dollar)) {
4088 Parser.Lex(); // Eat '#' or '$'.
4089 // Explicitly look for a '-', as we need to encode negative zero
4091 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4092 const MCExpr *Offset;
4094 if (getParser().parseExpression(Offset, E))
4095 return MatchOperand_ParseFail;
4096 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4098 Error(S, "constant expression expected");
4099 return MatchOperand_ParseFail;
4101 // Negative zero is encoded as the flag value INT32_MIN.
4102 int32_t Val = CE->getValue();
4103 if (isNegative && Val == 0)
4107 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4109 return MatchOperand_Success;
4113 bool haveEaten = false;
4115 if (Tok.is(AsmToken::Plus)) {
4116 Parser.Lex(); // Eat the '+' token.
4118 } else if (Tok.is(AsmToken::Minus)) {
4119 Parser.Lex(); // Eat the '-' token.
4124 Tok = Parser.getTok();
4125 int Reg = tryParseRegister();
4128 return MatchOperand_NoMatch;
4129 Error(Tok.getLoc(), "register expected");
4130 return MatchOperand_ParseFail;
4133 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4134 0, S, Tok.getEndLoc()));
4136 return MatchOperand_Success;
4139 /// Convert parsed operands to MCInst. Needed here because this instruction
4140 /// only has two register operands, but multiplication is commutative so
4141 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4143 cvtThumbMultiply(MCInst &Inst,
4144 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4145 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4146 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4147 // If we have a three-operand form, make sure to set Rn to be the operand
4148 // that isn't the same as Rd.
4150 if (Operands.size() == 6 &&
4151 ((ARMOperand*)Operands[4])->getReg() ==
4152 ((ARMOperand*)Operands[3])->getReg())
4154 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4155 Inst.addOperand(Inst.getOperand(0));
4156 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4160 cvtThumbBranches(MCInst &Inst,
4161 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4162 int CondOp = -1, ImmOp = -1;
4163 switch(Inst.getOpcode()) {
4165 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4168 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4170 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4172 // first decide whether or not the branch should be conditional
4173 // by looking at it's location relative to an IT block
4175 // inside an IT block we cannot have any conditional branches. any
4176 // such instructions needs to be converted to unconditional form
4177 switch(Inst.getOpcode()) {
4178 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4179 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4182 // outside IT blocks we can only have unconditional branches with AL
4183 // condition code or conditional branches with non-AL condition code
4184 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4185 switch(Inst.getOpcode()) {
4188 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4192 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4197 // now decide on encoding size based on branch target range
4198 switch(Inst.getOpcode()) {
4199 // classify tB as either t2B or t1B based on range of immediate operand
4201 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4202 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4203 Inst.setOpcode(ARM::t2B);
4206 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4208 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4209 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4210 Inst.setOpcode(ARM::t2Bcc);
4214 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4215 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4218 /// Parse an ARM memory expression, return false if successful else return true
4219 /// or an error. The first token must be a '[' when called.
4221 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4223 assert(Parser.getTok().is(AsmToken::LBrac) &&
4224 "Token is not a Left Bracket");
4225 S = Parser.getTok().getLoc();
4226 Parser.Lex(); // Eat left bracket token.
4228 const AsmToken &BaseRegTok = Parser.getTok();
4229 int BaseRegNum = tryParseRegister();
4230 if (BaseRegNum == -1)
4231 return Error(BaseRegTok.getLoc(), "register expected");
4233 // The next token must either be a comma, a colon or a closing bracket.
4234 const AsmToken &Tok = Parser.getTok();
4235 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4236 !Tok.is(AsmToken::RBrac))
4237 return Error(Tok.getLoc(), "malformed memory operand");
4239 if (Tok.is(AsmToken::RBrac)) {
4240 E = Tok.getEndLoc();
4241 Parser.Lex(); // Eat right bracket token.
4243 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4244 0, 0, false, S, E));
4246 // If there's a pre-indexing writeback marker, '!', just add it as a token
4247 // operand. It's rather odd, but syntactically valid.
4248 if (Parser.getTok().is(AsmToken::Exclaim)) {
4249 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4250 Parser.Lex(); // Eat the '!'.
4256 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4257 "Lost colon or comma in memory operand?!");
4258 if (Tok.is(AsmToken::Comma)) {
4259 Parser.Lex(); // Eat the comma.
4262 // If we have a ':', it's an alignment specifier.
4263 if (Parser.getTok().is(AsmToken::Colon)) {
4264 Parser.Lex(); // Eat the ':'.
4265 E = Parser.getTok().getLoc();
4268 if (getParser().parseExpression(Expr))
4271 // The expression has to be a constant. Memory references with relocations
4272 // don't come through here, as they use the <label> forms of the relevant
4274 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4276 return Error (E, "constant expression expected");
4279 switch (CE->getValue()) {
4282 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4283 case 16: Align = 2; break;
4284 case 32: Align = 4; break;
4285 case 64: Align = 8; break;
4286 case 128: Align = 16; break;
4287 case 256: Align = 32; break;
4290 // Now we should have the closing ']'
4291 if (Parser.getTok().isNot(AsmToken::RBrac))
4292 return Error(Parser.getTok().getLoc(), "']' expected");
4293 E = Parser.getTok().getEndLoc();
4294 Parser.Lex(); // Eat right bracket token.
4296 // Don't worry about range checking the value here. That's handled by
4297 // the is*() predicates.
4298 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4299 ARM_AM::no_shift, 0, Align,
4302 // If there's a pre-indexing writeback marker, '!', just add it as a token
4304 if (Parser.getTok().is(AsmToken::Exclaim)) {
4305 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4306 Parser.Lex(); // Eat the '!'.
4312 // If we have a '#', it's an immediate offset, else assume it's a register
4313 // offset. Be friendly and also accept a plain integer (without a leading
4314 // hash) for gas compatibility.
4315 if (Parser.getTok().is(AsmToken::Hash) ||
4316 Parser.getTok().is(AsmToken::Dollar) ||
4317 Parser.getTok().is(AsmToken::Integer)) {
4318 if (Parser.getTok().isNot(AsmToken::Integer))
4319 Parser.Lex(); // Eat '#' or '$'.
4320 E = Parser.getTok().getLoc();
4322 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4323 const MCExpr *Offset;
4324 if (getParser().parseExpression(Offset))
4327 // The expression has to be a constant. Memory references with relocations
4328 // don't come through here, as they use the <label> forms of the relevant
4330 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4332 return Error (E, "constant expression expected");
4334 // If the constant was #-0, represent it as INT32_MIN.
4335 int32_t Val = CE->getValue();
4336 if (isNegative && Val == 0)
4337 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4339 // Now we should have the closing ']'
4340 if (Parser.getTok().isNot(AsmToken::RBrac))
4341 return Error(Parser.getTok().getLoc(), "']' expected");
4342 E = Parser.getTok().getEndLoc();
4343 Parser.Lex(); // Eat right bracket token.
4345 // Don't worry about range checking the value here. That's handled by
4346 // the is*() predicates.
4347 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4348 ARM_AM::no_shift, 0, 0,
4351 // If there's a pre-indexing writeback marker, '!', just add it as a token
4353 if (Parser.getTok().is(AsmToken::Exclaim)) {
4354 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4355 Parser.Lex(); // Eat the '!'.
4361 // The register offset is optionally preceded by a '+' or '-'
4362 bool isNegative = false;
4363 if (Parser.getTok().is(AsmToken::Minus)) {
4365 Parser.Lex(); // Eat the '-'.
4366 } else if (Parser.getTok().is(AsmToken::Plus)) {
4368 Parser.Lex(); // Eat the '+'.
4371 E = Parser.getTok().getLoc();
4372 int OffsetRegNum = tryParseRegister();
4373 if (OffsetRegNum == -1)
4374 return Error(E, "register expected");
4376 // If there's a shift operator, handle it.
4377 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4378 unsigned ShiftImm = 0;
4379 if (Parser.getTok().is(AsmToken::Comma)) {
4380 Parser.Lex(); // Eat the ','.
4381 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4385 // Now we should have the closing ']'
4386 if (Parser.getTok().isNot(AsmToken::RBrac))
4387 return Error(Parser.getTok().getLoc(), "']' expected");
4388 E = Parser.getTok().getEndLoc();
4389 Parser.Lex(); // Eat right bracket token.
4391 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4392 ShiftType, ShiftImm, 0, isNegative,
4395 // If there's a pre-indexing writeback marker, '!', just add it as a token
4397 if (Parser.getTok().is(AsmToken::Exclaim)) {
4398 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4399 Parser.Lex(); // Eat the '!'.
4405 /// parseMemRegOffsetShift - one of these two:
4406 /// ( lsl | lsr | asr | ror ) , # shift_amount
4408 /// return true if it parses a shift otherwise it returns false.
4409 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4411 SMLoc Loc = Parser.getTok().getLoc();
4412 const AsmToken &Tok = Parser.getTok();
4413 if (Tok.isNot(AsmToken::Identifier))
4415 StringRef ShiftName = Tok.getString();
4416 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4417 ShiftName == "asl" || ShiftName == "ASL")
4419 else if (ShiftName == "lsr" || ShiftName == "LSR")
4421 else if (ShiftName == "asr" || ShiftName == "ASR")
4423 else if (ShiftName == "ror" || ShiftName == "ROR")
4425 else if (ShiftName == "rrx" || ShiftName == "RRX")
4428 return Error(Loc, "illegal shift operator");
4429 Parser.Lex(); // Eat shift type token.
4431 // rrx stands alone.
4433 if (St != ARM_AM::rrx) {
4434 Loc = Parser.getTok().getLoc();
4435 // A '#' and a shift amount.
4436 const AsmToken &HashTok = Parser.getTok();
4437 if (HashTok.isNot(AsmToken::Hash) &&
4438 HashTok.isNot(AsmToken::Dollar))
4439 return Error(HashTok.getLoc(), "'#' expected");
4440 Parser.Lex(); // Eat hash token.
4443 if (getParser().parseExpression(Expr))
4445 // Range check the immediate.
4446 // lsl, ror: 0 <= imm <= 31
4447 // lsr, asr: 0 <= imm <= 32
4448 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4450 return Error(Loc, "shift amount must be an immediate");
4451 int64_t Imm = CE->getValue();
4453 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4454 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4455 return Error(Loc, "immediate shift value out of range");
4456 // If <ShiftTy> #0, turn it into a no_shift.
4459 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4468 /// parseFPImm - A floating point immediate expression operand.
4469 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4470 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4471 // Anything that can accept a floating point constant as an operand
4472 // needs to go through here, as the regular parseExpression is
4475 // This routine still creates a generic Immediate operand, containing
4476 // a bitcast of the 64-bit floating point value. The various operands
4477 // that accept floats can check whether the value is valid for them
4478 // via the standard is*() predicates.
4480 SMLoc S = Parser.getTok().getLoc();
4482 if (Parser.getTok().isNot(AsmToken::Hash) &&
4483 Parser.getTok().isNot(AsmToken::Dollar))
4484 return MatchOperand_NoMatch;
4486 // Disambiguate the VMOV forms that can accept an FP immediate.
4487 // vmov.f32 <sreg>, #imm
4488 // vmov.f64 <dreg>, #imm
4489 // vmov.f32 <dreg>, #imm @ vector f32x2
4490 // vmov.f32 <qreg>, #imm @ vector f32x4
4492 // There are also the NEON VMOV instructions which expect an
4493 // integer constant. Make sure we don't try to parse an FPImm
4495 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4496 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4497 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4498 TyOp->getToken() != ".f64"))
4499 return MatchOperand_NoMatch;
4501 Parser.Lex(); // Eat '#' or '$'.
4503 // Handle negation, as that still comes through as a separate token.
4504 bool isNegative = false;
4505 if (Parser.getTok().is(AsmToken::Minus)) {
4509 const AsmToken &Tok = Parser.getTok();
4510 SMLoc Loc = Tok.getLoc();
4511 if (Tok.is(AsmToken::Real)) {
4512 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4513 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4514 // If we had a '-' in front, toggle the sign bit.
4515 IntVal ^= (uint64_t)isNegative << 31;
4516 Parser.Lex(); // Eat the token.
4517 Operands.push_back(ARMOperand::CreateImm(
4518 MCConstantExpr::Create(IntVal, getContext()),
4519 S, Parser.getTok().getLoc()));
4520 return MatchOperand_Success;
4522 // Also handle plain integers. Instructions which allow floating point
4523 // immediates also allow a raw encoded 8-bit value.
4524 if (Tok.is(AsmToken::Integer)) {
4525 int64_t Val = Tok.getIntVal();
4526 Parser.Lex(); // Eat the token.
4527 if (Val > 255 || Val < 0) {
4528 Error(Loc, "encoded floating point value out of range");
4529 return MatchOperand_ParseFail;
4531 double RealVal = ARM_AM::getFPImmFloat(Val);
4532 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4533 Operands.push_back(ARMOperand::CreateImm(
4534 MCConstantExpr::Create(Val, getContext()), S,
4535 Parser.getTok().getLoc()));
4536 return MatchOperand_Success;
4539 Error(Loc, "invalid floating point immediate");
4540 return MatchOperand_ParseFail;
4543 /// Parse a arm instruction operand. For now this parses the operand regardless
4544 /// of the mnemonic.
4545 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4546 StringRef Mnemonic) {
4549 // Check if the current operand has a custom associated parser, if so, try to
4550 // custom parse the operand, or fallback to the general approach.
4551 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4552 if (ResTy == MatchOperand_Success)
4554 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4555 // there was a match, but an error occurred, in which case, just return that
4556 // the operand parsing failed.
4557 if (ResTy == MatchOperand_ParseFail)
4560 switch (getLexer().getKind()) {
4562 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4564 case AsmToken::Identifier: {
4565 // If we've seen a branch mnemonic, the next operand must be a label. This
4566 // is true even if the label is a register name. So "br r1" means branch to
4568 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4570 if (!tryParseRegisterWithWriteBack(Operands))
4572 int Res = tryParseShiftRegister(Operands);
4573 if (Res == 0) // success
4575 else if (Res == -1) // irrecoverable error
4577 // If this is VMRS, check for the apsr_nzcv operand.
4578 if (Mnemonic == "vmrs" &&
4579 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4580 S = Parser.getTok().getLoc();
4582 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4587 // Fall though for the Identifier case that is not a register or a
4590 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4591 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4592 case AsmToken::String: // quoted label names.
4593 case AsmToken::Dot: { // . as a branch target
4594 // This was not a register so parse other operands that start with an
4595 // identifier (like labels) as expressions and create them as immediates.
4596 const MCExpr *IdVal;
4597 S = Parser.getTok().getLoc();
4598 if (getParser().parseExpression(IdVal))
4600 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4601 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4604 case AsmToken::LBrac:
4605 return parseMemory(Operands);
4606 case AsmToken::LCurly:
4607 return parseRegisterList(Operands);
4608 case AsmToken::Dollar:
4609 case AsmToken::Hash: {
4610 // #42 -> immediate.
4611 S = Parser.getTok().getLoc();
4614 if (Parser.getTok().isNot(AsmToken::Colon)) {
4615 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4616 const MCExpr *ImmVal;
4617 if (getParser().parseExpression(ImmVal))
4619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4621 int32_t Val = CE->getValue();
4622 if (isNegative && Val == 0)
4623 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4625 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4626 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4628 // There can be a trailing '!' on operands that we want as a separate
4629 // '!' Token operand. Handle that here. For example, the compatibilty
4630 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4631 if (Parser.getTok().is(AsmToken::Exclaim)) {
4632 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4633 Parser.getTok().getLoc()));
4634 Parser.Lex(); // Eat exclaim token
4638 // w/ a ':' after the '#', it's just like a plain ':'.
4641 case AsmToken::Colon: {
4642 // ":lower16:" and ":upper16:" expression prefixes
4643 // FIXME: Check it's an expression prefix,
4644 // e.g. (FOO - :lower16:BAR) isn't legal.
4645 ARMMCExpr::VariantKind RefKind;
4646 if (parsePrefix(RefKind))
4649 const MCExpr *SubExprVal;
4650 if (getParser().parseExpression(SubExprVal))
4653 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4655 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4656 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4662 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4663 // :lower16: and :upper16:.
4664 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4665 RefKind = ARMMCExpr::VK_ARM_None;
4667 // :lower16: and :upper16: modifiers
4668 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4669 Parser.Lex(); // Eat ':'
4671 if (getLexer().isNot(AsmToken::Identifier)) {
4672 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4676 StringRef IDVal = Parser.getTok().getIdentifier();
4677 if (IDVal == "lower16") {
4678 RefKind = ARMMCExpr::VK_ARM_LO16;
4679 } else if (IDVal == "upper16") {
4680 RefKind = ARMMCExpr::VK_ARM_HI16;
4682 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4687 if (getLexer().isNot(AsmToken::Colon)) {
4688 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4691 Parser.Lex(); // Eat the last ':'
4695 /// \brief Given a mnemonic, split out possible predication code and carry
4696 /// setting letters to form a canonical mnemonic and flags.
4698 // FIXME: Would be nice to autogen this.
4699 // FIXME: This is a bit of a maze of special cases.
4700 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4701 unsigned &PredicationCode,
4703 unsigned &ProcessorIMod,
4704 StringRef &ITMask) {
4705 PredicationCode = ARMCC::AL;
4706 CarrySetting = false;
4709 // Ignore some mnemonics we know aren't predicated forms.
4711 // FIXME: Would be nice to autogen this.
4712 if ((Mnemonic == "movs" && isThumb()) ||
4713 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4714 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4715 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4716 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4717 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
4718 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4719 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4720 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4721 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
4722 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4723 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4724 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
4727 // First, split out any predication code. Ignore mnemonics we know aren't
4728 // predicated but do have a carry-set and so weren't caught above.
4729 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4730 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4731 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4732 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4733 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4734 .Case("eq", ARMCC::EQ)
4735 .Case("ne", ARMCC::NE)
4736 .Case("hs", ARMCC::HS)
4737 .Case("cs", ARMCC::HS)
4738 .Case("lo", ARMCC::LO)
4739 .Case("cc", ARMCC::LO)
4740 .Case("mi", ARMCC::MI)
4741 .Case("pl", ARMCC::PL)
4742 .Case("vs", ARMCC::VS)
4743 .Case("vc", ARMCC::VC)
4744 .Case("hi", ARMCC::HI)
4745 .Case("ls", ARMCC::LS)
4746 .Case("ge", ARMCC::GE)
4747 .Case("lt", ARMCC::LT)
4748 .Case("gt", ARMCC::GT)
4749 .Case("le", ARMCC::LE)
4750 .Case("al", ARMCC::AL)
4753 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4754 PredicationCode = CC;
4758 // Next, determine if we have a carry setting bit. We explicitly ignore all
4759 // the instructions we know end in 's'.
4760 if (Mnemonic.endswith("s") &&
4761 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4762 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4763 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4764 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4765 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4766 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4767 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4768 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4769 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4770 (Mnemonic == "movs" && isThumb()))) {
4771 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4772 CarrySetting = true;
4775 // The "cps" instruction can have a interrupt mode operand which is glued into
4776 // the mnemonic. Check if this is the case, split it and parse the imod op
4777 if (Mnemonic.startswith("cps")) {
4778 // Split out any imod code.
4780 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4781 .Case("ie", ARM_PROC::IE)
4782 .Case("id", ARM_PROC::ID)
4785 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4786 ProcessorIMod = IMod;
4790 // The "it" instruction has the condition mask on the end of the mnemonic.
4791 if (Mnemonic.startswith("it")) {
4792 ITMask = Mnemonic.slice(2, Mnemonic.size());
4793 Mnemonic = Mnemonic.slice(0, 2);
4799 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4800 /// inclusion of carry set or predication code operands.
4802 // FIXME: It would be nice to autogen this.
4804 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4805 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
4806 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4807 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4808 Mnemonic == "add" || Mnemonic == "adc" ||
4809 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4810 Mnemonic == "orr" || Mnemonic == "mvn" ||
4811 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4812 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4813 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4814 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4815 Mnemonic == "mla" || Mnemonic == "smlal" ||
4816 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4817 CanAcceptCarrySet = true;
4819 CanAcceptCarrySet = false;
4821 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4822 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4823 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
4824 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4825 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
4826 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4827 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4828 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4829 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4830 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
4831 // These mnemonics are never predicable
4832 CanAcceptPredicationCode = false;
4833 } else if (!isThumb()) {
4834 // Some instructions are only predicable in Thumb mode
4835 CanAcceptPredicationCode
4836 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4837 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4838 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4839 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4840 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4841 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4842 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4843 } else if (isThumbOne()) {
4845 CanAcceptPredicationCode = Mnemonic != "movs";
4847 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4849 CanAcceptPredicationCode = true;
4852 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4853 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4854 // FIXME: This is all horribly hacky. We really need a better way to deal
4855 // with optional operands like this in the matcher table.
4857 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4858 // another does not. Specifically, the MOVW instruction does not. So we
4859 // special case it here and remove the defaulted (non-setting) cc_out
4860 // operand if that's the instruction we're trying to match.
4862 // We do this as post-processing of the explicit operands rather than just
4863 // conditionally adding the cc_out in the first place because we need
4864 // to check the type of the parsed immediate operand.
4865 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4866 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4867 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4868 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4871 // Register-register 'add' for thumb does not have a cc_out operand
4872 // when there are only two register operands.
4873 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4874 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4875 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4876 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4878 // Register-register 'add' for thumb does not have a cc_out operand
4879 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4880 // have to check the immediate range here since Thumb2 has a variant
4881 // that can handle a different range and has a cc_out operand.
4882 if (((isThumb() && Mnemonic == "add") ||
4883 (isThumbTwo() && Mnemonic == "sub")) &&
4884 Operands.size() == 6 &&
4885 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4886 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4887 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4888 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4889 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4890 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4892 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4893 // imm0_4095 variant. That's the least-preferred variant when
4894 // selecting via the generic "add" mnemonic, so to know that we
4895 // should remove the cc_out operand, we have to explicitly check that
4896 // it's not one of the other variants. Ugh.
4897 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4898 Operands.size() == 6 &&
4899 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4900 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4901 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4902 // Nest conditions rather than one big 'if' statement for readability.
4904 // If both registers are low, we're in an IT block, and the immediate is
4905 // in range, we should use encoding T1 instead, which has a cc_out.
4907 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4908 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4909 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4911 // Check against T3. If the second register is the PC, this is an
4912 // alternate form of ADR, which uses encoding T4, so check for that too.
4913 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4914 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4917 // Otherwise, we use encoding T4, which does not have a cc_out
4922 // The thumb2 multiply instruction doesn't have a CCOut register, so
4923 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4924 // use the 16-bit encoding or not.
4925 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4926 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4927 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4928 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4929 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4930 // If the registers aren't low regs, the destination reg isn't the
4931 // same as one of the source regs, or the cc_out operand is zero
4932 // outside of an IT block, we have to use the 32-bit encoding, so
4933 // remove the cc_out operand.
4934 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4935 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4936 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4938 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4939 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4940 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4941 static_cast<ARMOperand*>(Operands[4])->getReg())))
4944 // Also check the 'mul' syntax variant that doesn't specify an explicit
4945 // destination register.
4946 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4947 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4948 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4949 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4950 // If the registers aren't low regs or the cc_out operand is zero
4951 // outside of an IT block, we have to use the 32-bit encoding, so
4952 // remove the cc_out operand.
4953 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4954 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4960 // Register-register 'add/sub' for thumb does not have a cc_out operand
4961 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4962 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4963 // right, this will result in better diagnostics (which operand is off)
4965 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4966 (Operands.size() == 5 || Operands.size() == 6) &&
4967 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4968 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4969 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4970 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4971 (Operands.size() == 6 &&
4972 static_cast<ARMOperand*>(Operands[5])->isImm())))
4978 bool ARMAsmParser::shouldOmitPredicateOperand(
4979 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4980 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4981 unsigned RegIdx = 3;
4982 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4983 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4984 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4985 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4988 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4989 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4990 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4991 ARMMCRegisterClasses[ARM::QPRRegClassID]
4992 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4998 static bool isDataTypeToken(StringRef Tok) {
4999 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5000 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5001 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5002 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5003 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5004 Tok == ".f" || Tok == ".d";
5007 // FIXME: This bit should probably be handled via an explicit match class
5008 // in the .td files that matches the suffix instead of having it be
5009 // a literal string token the way it is now.
5010 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5011 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5013 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5014 unsigned VariantID);
5015 /// Parse an arm instruction mnemonic followed by its operands.
5016 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5018 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5019 // Apply mnemonic aliases before doing anything else, as the destination
5020 // mnemnonic may include suffices and we want to handle them normally.
5021 // The generic tblgen'erated code does this later, at the start of
5022 // MatchInstructionImpl(), but that's too late for aliases that include
5023 // any sort of suffix.
5024 unsigned AvailableFeatures = getAvailableFeatures();
5025 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5026 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5028 // First check for the ARM-specific .req directive.
5029 if (Parser.getTok().is(AsmToken::Identifier) &&
5030 Parser.getTok().getIdentifier() == ".req") {
5031 parseDirectiveReq(Name, NameLoc);
5032 // We always return 'error' for this, as we're done with this
5033 // statement and don't need to match the 'instruction."
5037 // Create the leading tokens for the mnemonic, split by '.' characters.
5038 size_t Start = 0, Next = Name.find('.');
5039 StringRef Mnemonic = Name.slice(Start, Next);
5041 // Split out the predication code and carry setting flag from the mnemonic.
5042 unsigned PredicationCode;
5043 unsigned ProcessorIMod;
5046 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5047 ProcessorIMod, ITMask);
5049 // In Thumb1, only the branch (B) instruction can be predicated.
5050 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5051 Parser.eatToEndOfStatement();
5052 return Error(NameLoc, "conditional execution not supported in Thumb1");
5055 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5057 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5058 // is the mask as it will be for the IT encoding if the conditional
5059 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5060 // where the conditional bit0 is zero, the instruction post-processing
5061 // will adjust the mask accordingly.
5062 if (Mnemonic == "it") {
5063 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5064 if (ITMask.size() > 3) {
5065 Parser.eatToEndOfStatement();
5066 return Error(Loc, "too many conditions on IT instruction");
5069 for (unsigned i = ITMask.size(); i != 0; --i) {
5070 char pos = ITMask[i - 1];
5071 if (pos != 't' && pos != 'e') {
5072 Parser.eatToEndOfStatement();
5073 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5076 if (ITMask[i - 1] == 't')
5079 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5082 // FIXME: This is all a pretty gross hack. We should automatically handle
5083 // optional operands like this via tblgen.
5085 // Next, add the CCOut and ConditionCode operands, if needed.
5087 // For mnemonics which can ever incorporate a carry setting bit or predication
5088 // code, our matching model involves us always generating CCOut and
5089 // ConditionCode operands to match the mnemonic "as written" and then we let
5090 // the matcher deal with finding the right instruction or generating an
5091 // appropriate error.
5092 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5093 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5095 // If we had a carry-set on an instruction that can't do that, issue an
5097 if (!CanAcceptCarrySet && CarrySetting) {
5098 Parser.eatToEndOfStatement();
5099 return Error(NameLoc, "instruction '" + Mnemonic +
5100 "' can not set flags, but 's' suffix specified");
5102 // If we had a predication code on an instruction that can't do that, issue an
5104 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5105 Parser.eatToEndOfStatement();
5106 return Error(NameLoc, "instruction '" + Mnemonic +
5107 "' is not predicable, but condition code specified");
5110 // Add the carry setting operand, if necessary.
5111 if (CanAcceptCarrySet) {
5112 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5113 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5117 // Add the predication code operand, if necessary.
5118 if (CanAcceptPredicationCode) {
5119 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5121 Operands.push_back(ARMOperand::CreateCondCode(
5122 ARMCC::CondCodes(PredicationCode), Loc));
5125 // Add the processor imod operand, if necessary.
5126 if (ProcessorIMod) {
5127 Operands.push_back(ARMOperand::CreateImm(
5128 MCConstantExpr::Create(ProcessorIMod, getContext()),
5132 // Add the remaining tokens in the mnemonic.
5133 while (Next != StringRef::npos) {
5135 Next = Name.find('.', Start + 1);
5136 StringRef ExtraToken = Name.slice(Start, Next);
5138 // Some NEON instructions have an optional datatype suffix that is
5139 // completely ignored. Check for that.
5140 if (isDataTypeToken(ExtraToken) &&
5141 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5144 // For for ARM mode generate an error if the .n qualifier is used.
5145 if (ExtraToken == ".n" && !isThumb()) {
5146 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5147 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5151 // The .n qualifier is always discarded as that is what the tables
5152 // and matcher expect. In ARM mode the .w qualifier has no effect,
5153 // so discard it to avoid errors that can be caused by the matcher.
5154 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5155 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5156 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5160 // Read the remaining operands.
5161 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5162 // Read the first operand.
5163 if (parseOperand(Operands, Mnemonic)) {
5164 Parser.eatToEndOfStatement();
5168 while (getLexer().is(AsmToken::Comma)) {
5169 Parser.Lex(); // Eat the comma.
5171 // Parse and remember the operand.
5172 if (parseOperand(Operands, Mnemonic)) {
5173 Parser.eatToEndOfStatement();
5179 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5180 SMLoc Loc = getLexer().getLoc();
5181 Parser.eatToEndOfStatement();
5182 return Error(Loc, "unexpected token in argument list");
5185 Parser.Lex(); // Consume the EndOfStatement
5187 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5188 // do and don't have a cc_out optional-def operand. With some spot-checks
5189 // of the operand list, we can figure out which variant we're trying to
5190 // parse and adjust accordingly before actually matching. We shouldn't ever
5191 // try to remove a cc_out operand that was explicitly set on the the
5192 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5193 // table driven matcher doesn't fit well with the ARM instruction set.
5194 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5195 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5196 Operands.erase(Operands.begin() + 1);
5200 // Some instructions have the same mnemonic, but don't always
5201 // have a predicate. Distinguish them here and delete the
5202 // predicate if needed.
5203 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5204 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5205 Operands.erase(Operands.begin() + 1);
5209 // ARM mode 'blx' need special handling, as the register operand version
5210 // is predicable, but the label operand version is not. So, we can't rely
5211 // on the Mnemonic based checking to correctly figure out when to put
5212 // a k_CondCode operand in the list. If we're trying to match the label
5213 // version, remove the k_CondCode operand here.
5214 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5215 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5216 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5217 Operands.erase(Operands.begin() + 1);
5221 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5222 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5223 // a single GPRPair reg operand is used in the .td file to replace the two
5224 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5225 // expressed as a GPRPair, so we have to manually merge them.
5226 // FIXME: We would really like to be able to tablegen'erate this.
5227 if (!isThumb() && Operands.size() > 4 &&
5228 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5229 Mnemonic == "stlexd")) {
5230 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5231 unsigned Idx = isLoad ? 2 : 3;
5232 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5233 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5235 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5236 // Adjust only if Op1 and Op2 are GPRs.
5237 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5238 MRC.contains(Op2->getReg())) {
5239 unsigned Reg1 = Op1->getReg();
5240 unsigned Reg2 = Op2->getReg();
5241 unsigned Rt = MRI->getEncodingValue(Reg1);
5242 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5244 // Rt2 must be Rt + 1 and Rt must be even.
5245 if (Rt + 1 != Rt2 || (Rt & 1)) {
5246 Error(Op2->getStartLoc(), isLoad ?
5247 "destination operands must be sequential" :
5248 "source operands must be sequential");
5251 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5252 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5253 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5254 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5255 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5261 // FIXME: As said above, this is all a pretty gross hack. This instruction
5262 // does not fit with other "subs" and tblgen.
5263 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5264 // so the Mnemonic is the original name "subs" and delete the predicate
5265 // operand so it will match the table entry.
5266 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5267 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5268 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5269 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5270 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5271 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5272 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5273 Operands.erase(Operands.begin());
5275 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5277 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5278 Operands.erase(Operands.begin() + 1);
5284 // Validate context-sensitive operand constraints.
5286 // return 'true' if register list contains non-low GPR registers,
5287 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5288 // 'containsReg' to true.
5289 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5290 unsigned HiReg, bool &containsReg) {
5291 containsReg = false;
5292 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5293 unsigned OpReg = Inst.getOperand(i).getReg();
5296 // Anything other than a low register isn't legal here.
5297 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5303 // Check if the specified regisgter is in the register list of the inst,
5304 // starting at the indicated operand number.
5305 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5306 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5307 unsigned OpReg = Inst.getOperand(i).getReg();
5314 // Return true if instruction has the interesting property of being
5315 // allowed in IT blocks, but not being predicable.
5316 static bool instIsBreakpoint(const MCInst &Inst) {
5317 return Inst.getOpcode() == ARM::tBKPT ||
5318 Inst.getOpcode() == ARM::BKPT ||
5319 Inst.getOpcode() == ARM::tHLT ||
5320 Inst.getOpcode() == ARM::HLT;
5324 // FIXME: We would really like to be able to tablegen'erate this.
5326 validateInstruction(MCInst &Inst,
5327 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5328 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
5329 SMLoc Loc = Operands[0]->getStartLoc();
5331 // Check the IT block state first.
5332 // NOTE: BKPT and HLT instructions have the interesting property of being
5333 // allowed in IT blocks, but not being predicable. They just always execute.
5334 if (inITBlock() && !instIsBreakpoint(Inst)) {
5336 if (ITState.FirstCond)
5337 ITState.FirstCond = false;
5339 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5340 // The instruction must be predicable.
5341 if (!MCID.isPredicable())
5342 return Error(Loc, "instructions in IT block must be predicable");
5343 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5344 unsigned ITCond = Bit ? ITState.Cond :
5345 ARMCC::getOppositeCondition(ITState.Cond);
5346 if (Cond != ITCond) {
5347 // Find the condition code Operand to get its SMLoc information.
5349 for (unsigned I = 1; I < Operands.size(); ++I)
5350 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5351 CondLoc = Operands[I]->getStartLoc();
5352 return Error(CondLoc, "incorrect condition in IT block; got '" +
5353 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5354 "', but expected '" +
5355 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5357 // Check for non-'al' condition codes outside of the IT block.
5358 } else if (isThumbTwo() && MCID.isPredicable() &&
5359 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5360 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5361 Inst.getOpcode() != ARM::t2Bcc)
5362 return Error(Loc, "predicated instructions must be in IT block");
5364 const unsigned Opcode = Inst.getOpcode();
5368 case ARM::LDRD_POST: {
5369 const unsigned RtReg = Inst.getOperand(0).getReg();
5372 if (RtReg == ARM::LR)
5373 return Error(Operands[3]->getStartLoc(),
5376 const unsigned Rt = MRI->getEncodingValue(RtReg);
5377 // Rt must be even-numbered.
5379 return Error(Operands[3]->getStartLoc(),
5380 "Rt must be even-numbered");
5382 // Rt2 must be Rt + 1.
5383 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5385 return Error(Operands[3]->getStartLoc(),
5386 "destination operands must be sequential");
5388 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5389 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5390 // For addressing modes with writeback, the base register needs to be
5391 // different from the destination registers.
5392 if (Rn == Rt || Rn == Rt2)
5393 return Error(Operands[3]->getStartLoc(),
5394 "base register needs to be different from destination "
5401 case ARM::t2LDRD_PRE:
5402 case ARM::t2LDRD_POST: {
5403 // Rt2 must be different from Rt.
5404 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5405 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5407 return Error(Operands[3]->getStartLoc(),
5408 "destination operands can't be identical");
5412 // Rt2 must be Rt + 1.
5413 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5414 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5416 return Error(Operands[3]->getStartLoc(),
5417 "source operands must be sequential");
5421 case ARM::STRD_POST: {
5422 // Rt2 must be Rt + 1.
5423 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5424 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5426 return Error(Operands[3]->getStartLoc(),
5427 "source operands must be sequential");
5432 // Width must be in range [1, 32-lsb].
5433 unsigned LSB = Inst.getOperand(2).getImm();
5434 unsigned Widthm1 = Inst.getOperand(3).getImm();
5435 if (Widthm1 >= 32 - LSB)
5436 return Error(Operands[5]->getStartLoc(),
5437 "bitfield width must be in range [1,32-lsb]");
5440 // Notionally handles ARM::tLDMIA_UPD too.
5442 // If we're parsing Thumb2, the .w variant is available and handles
5443 // most cases that are normally illegal for a Thumb1 LDM instruction.
5444 // We'll make the transformation in processInstruction() if necessary.
5446 // Thumb LDM instructions are writeback iff the base register is not
5447 // in the register list.
5448 unsigned Rn = Inst.getOperand(0).getReg();
5449 bool HasWritebackToken =
5450 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5451 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5452 bool ListContainsBase;
5453 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5454 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
5455 "registers must be in range r0-r7");
5456 // If we should have writeback, then there should be a '!' token.
5457 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
5458 return Error(Operands[2]->getStartLoc(),
5459 "writeback operator '!' expected");
5460 // If we should not have writeback, there must not be a '!'. This is
5461 // true even for the 32-bit wide encodings.
5462 if (ListContainsBase && HasWritebackToken)
5463 return Error(Operands[3]->getStartLoc(),
5464 "writeback operator '!' not allowed when base register "
5465 "in register list");
5469 case ARM::LDMIA_UPD:
5470 case ARM::LDMDB_UPD:
5471 case ARM::LDMIB_UPD:
5472 case ARM::LDMDA_UPD:
5473 // ARM variants loading and updating the same register are only officially
5474 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5478 case ARM::t2LDMIA_UPD:
5479 case ARM::t2LDMDB_UPD:
5480 case ARM::t2STMIA_UPD:
5481 case ARM::t2STMDB_UPD: {
5482 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5483 return Error(Operands.back()->getStartLoc(),
5484 "writeback register not allowed in register list");
5487 case ARM::sysLDMIA_UPD:
5488 case ARM::sysLDMDA_UPD:
5489 case ARM::sysLDMDB_UPD:
5490 case ARM::sysLDMIB_UPD:
5491 if (!listContainsReg(Inst, 3, ARM::PC))
5492 return Error(Operands[4]->getStartLoc(),
5493 "writeback register only allowed on system LDM "
5494 "if PC in register-list");
5496 case ARM::sysSTMIA_UPD:
5497 case ARM::sysSTMDA_UPD:
5498 case ARM::sysSTMDB_UPD:
5499 case ARM::sysSTMIB_UPD:
5500 return Error(Operands[2]->getStartLoc(),
5501 "system STM cannot have writeback register");
5504 // The second source operand must be the same register as the destination
5507 // In this case, we must directly check the parsed operands because the
5508 // cvtThumbMultiply() function is written in such a way that it guarantees
5509 // this first statement is always true for the new Inst. Essentially, the
5510 // destination is unconditionally copied into the second source operand
5511 // without checking to see if it matches what we actually parsed.
5512 if (Operands.size() == 6 &&
5513 (((ARMOperand*)Operands[3])->getReg() !=
5514 ((ARMOperand*)Operands[5])->getReg()) &&
5515 (((ARMOperand*)Operands[3])->getReg() !=
5516 ((ARMOperand*)Operands[4])->getReg())) {
5517 return Error(Operands[3]->getStartLoc(),
5518 "destination register must match source register");
5522 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5523 // so only issue a diagnostic for thumb1. The instructions will be
5524 // switched to the t2 encodings in processInstruction() if necessary.
5526 bool ListContainsBase;
5527 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
5529 return Error(Operands[2]->getStartLoc(),
5530 "registers must be in range r0-r7 or pc");
5534 bool ListContainsBase;
5535 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
5537 return Error(Operands[2]->getStartLoc(),
5538 "registers must be in range r0-r7 or lr");
5541 case ARM::tSTMIA_UPD: {
5542 bool ListContainsBase, InvalidLowList;
5543 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5544 0, ListContainsBase);
5545 if (InvalidLowList && !isThumbTwo())
5546 return Error(Operands[4]->getStartLoc(),
5547 "registers must be in range r0-r7");
5549 // This would be converted to a 32-bit stm, but that's not valid if the
5550 // writeback register is in the list.
5551 if (InvalidLowList && ListContainsBase)
5552 return Error(Operands[4]->getStartLoc(),
5553 "writeback operator '!' not allowed when base register "
5554 "in register list");
5557 case ARM::tADDrSP: {
5558 // If the non-SP source operand and the destination operand are not the
5559 // same, we need thumb2 (for the wide encoding), or we have an error.
5560 if (!isThumbTwo() &&
5561 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5562 return Error(Operands[4]->getStartLoc(),
5563 "source register must be the same as destination");
5567 // Final range checking for Thumb unconditional branch instructions.
5569 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5570 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5573 int op = (Operands[2]->isImm()) ? 2 : 3;
5574 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5575 return Error(Operands[op]->getStartLoc(), "branch target out of range");
5578 // Final range checking for Thumb conditional branch instructions.
5580 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5581 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5584 int Op = (Operands[2]->isImm()) ? 2 : 3;
5585 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5586 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
5594 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5596 default: llvm_unreachable("unexpected opcode!");
5598 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5599 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5600 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5601 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5602 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5603 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5604 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5605 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5606 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5609 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5610 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5611 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5612 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5613 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5615 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5616 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5617 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5618 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5619 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5621 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5622 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5623 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5624 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5625 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5628 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5629 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5630 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5631 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5632 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5633 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5634 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5635 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5636 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5637 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5638 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5639 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5640 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5641 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5642 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5645 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5646 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5647 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5648 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5649 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5650 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5651 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5652 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5653 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5654 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5655 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5656 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5657 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5658 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5659 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5660 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5661 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5662 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5665 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5666 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5667 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5668 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5669 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5670 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5671 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5672 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5673 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5674 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5675 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5676 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5677 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5678 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5679 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5682 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5683 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5684 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5685 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5686 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5687 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5688 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5689 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5690 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5691 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5692 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5693 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5694 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5695 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5696 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5697 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5698 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5699 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5703 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5705 default: llvm_unreachable("unexpected opcode!");
5707 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5708 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5709 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5710 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5711 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5712 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5713 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5714 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5715 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5718 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5719 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5720 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5721 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5722 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5723 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5724 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5725 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5726 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5727 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5728 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5729 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5730 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5731 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5732 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5735 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5736 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5737 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5738 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5739 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5740 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5741 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5742 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5743 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5744 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5745 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5746 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5747 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5748 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5749 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5750 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5751 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5752 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5755 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5756 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5757 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5758 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5759 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5760 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5761 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5762 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5763 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5764 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5765 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5766 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5767 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5768 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5769 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5772 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5773 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5774 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5775 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5776 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5777 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5778 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5779 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5780 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5781 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5782 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5783 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5784 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5785 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5786 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5787 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5788 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5789 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5792 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5793 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5794 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5795 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5796 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5797 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5798 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5799 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5800 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5801 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5802 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5803 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5804 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5805 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5806 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5809 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5810 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5811 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5812 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5813 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5814 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5815 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5816 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5817 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5818 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5819 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5820 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5821 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5822 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5823 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5824 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5825 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5826 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5829 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5830 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5831 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5832 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5833 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5834 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5835 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5836 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5837 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5838 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5839 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5840 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5841 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5842 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5843 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5844 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5845 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5846 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5851 processInstruction(MCInst &Inst,
5852 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5853 switch (Inst.getOpcode()) {
5854 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5856 if (Inst.getOperand(1).getReg() != ARM::PC ||
5857 Inst.getOperand(5).getReg() != 0)
5860 TmpInst.setOpcode(ARM::ADR);
5861 TmpInst.addOperand(Inst.getOperand(0));
5862 TmpInst.addOperand(Inst.getOperand(2));
5863 TmpInst.addOperand(Inst.getOperand(3));
5864 TmpInst.addOperand(Inst.getOperand(4));
5868 // Aliases for alternate PC+imm syntax of LDR instructions.
5869 case ARM::t2LDRpcrel:
5870 // Select the narrow version if the immediate will fit.
5871 if (Inst.getOperand(1).getImm() > 0 &&
5872 Inst.getOperand(1).getImm() <= 0xff &&
5873 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5874 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
5875 Inst.setOpcode(ARM::tLDRpci);
5877 Inst.setOpcode(ARM::t2LDRpci);
5879 case ARM::t2LDRBpcrel:
5880 Inst.setOpcode(ARM::t2LDRBpci);
5882 case ARM::t2LDRHpcrel:
5883 Inst.setOpcode(ARM::t2LDRHpci);
5885 case ARM::t2LDRSBpcrel:
5886 Inst.setOpcode(ARM::t2LDRSBpci);
5888 case ARM::t2LDRSHpcrel:
5889 Inst.setOpcode(ARM::t2LDRSHpci);
5891 // Handle NEON VST complex aliases.
5892 case ARM::VST1LNdWB_register_Asm_8:
5893 case ARM::VST1LNdWB_register_Asm_16:
5894 case ARM::VST1LNdWB_register_Asm_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_wb
5901 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5902 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5903 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5904 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5905 TmpInst.addOperand(Inst.getOperand(1)); // lane
5906 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5907 TmpInst.addOperand(Inst.getOperand(6));
5912 case ARM::VST2LNdWB_register_Asm_8:
5913 case ARM::VST2LNdWB_register_Asm_16:
5914 case ARM::VST2LNdWB_register_Asm_32:
5915 case ARM::VST2LNqWB_register_Asm_16:
5916 case ARM::VST2LNqWB_register_Asm_32: {
5918 // Shuffle the operands around so the lane index operand is in the
5921 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5922 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5923 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5924 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5925 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5926 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5927 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5929 TmpInst.addOperand(Inst.getOperand(1)); // lane
5930 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5931 TmpInst.addOperand(Inst.getOperand(6));
5936 case ARM::VST3LNdWB_register_Asm_8:
5937 case ARM::VST3LNdWB_register_Asm_16:
5938 case ARM::VST3LNdWB_register_Asm_32:
5939 case ARM::VST3LNqWB_register_Asm_16:
5940 case ARM::VST3LNqWB_register_Asm_32: {
5942 // Shuffle the operands around so the lane index operand is in the
5945 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5946 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5947 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5948 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5949 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5950 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5951 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5953 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5955 TmpInst.addOperand(Inst.getOperand(1)); // lane
5956 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5957 TmpInst.addOperand(Inst.getOperand(6));
5962 case ARM::VST4LNdWB_register_Asm_8:
5963 case ARM::VST4LNdWB_register_Asm_16:
5964 case ARM::VST4LNdWB_register_Asm_32:
5965 case ARM::VST4LNqWB_register_Asm_16:
5966 case ARM::VST4LNqWB_register_Asm_32: {
5968 // Shuffle the operands around so the lane index operand is in the
5971 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5972 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5973 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5974 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5975 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5976 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5977 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5979 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5981 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5983 TmpInst.addOperand(Inst.getOperand(1)); // lane
5984 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5985 TmpInst.addOperand(Inst.getOperand(6));
5990 case ARM::VST1LNdWB_fixed_Asm_8:
5991 case ARM::VST1LNdWB_fixed_Asm_16:
5992 case ARM::VST1LNdWB_fixed_Asm_32: {
5994 // Shuffle the operands around so the lane index operand is in the
5997 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5998 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5999 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6000 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6001 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6002 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6003 TmpInst.addOperand(Inst.getOperand(1)); // lane
6004 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6005 TmpInst.addOperand(Inst.getOperand(5));
6010 case ARM::VST2LNdWB_fixed_Asm_8:
6011 case ARM::VST2LNdWB_fixed_Asm_16:
6012 case ARM::VST2LNdWB_fixed_Asm_32:
6013 case ARM::VST2LNqWB_fixed_Asm_16:
6014 case ARM::VST2LNqWB_fixed_Asm_32: {
6016 // Shuffle the operands around so the lane index operand is in the
6019 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6020 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6021 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6022 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6023 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6024 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6025 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6027 TmpInst.addOperand(Inst.getOperand(1)); // lane
6028 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6029 TmpInst.addOperand(Inst.getOperand(5));
6034 case ARM::VST3LNdWB_fixed_Asm_8:
6035 case ARM::VST3LNdWB_fixed_Asm_16:
6036 case ARM::VST3LNdWB_fixed_Asm_32:
6037 case ARM::VST3LNqWB_fixed_Asm_16:
6038 case ARM::VST3LNqWB_fixed_Asm_32: {
6040 // Shuffle the operands around so the lane index operand is in the
6043 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6044 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6045 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6046 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6047 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6048 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6049 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6051 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6053 TmpInst.addOperand(Inst.getOperand(1)); // lane
6054 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6055 TmpInst.addOperand(Inst.getOperand(5));
6060 case ARM::VST4LNdWB_fixed_Asm_8:
6061 case ARM::VST4LNdWB_fixed_Asm_16:
6062 case ARM::VST4LNdWB_fixed_Asm_32:
6063 case ARM::VST4LNqWB_fixed_Asm_16:
6064 case ARM::VST4LNqWB_fixed_Asm_32: {
6066 // Shuffle the operands around so the lane index operand is in the
6069 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6070 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6071 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6072 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6073 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6074 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6075 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6077 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6079 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6081 TmpInst.addOperand(Inst.getOperand(1)); // lane
6082 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6083 TmpInst.addOperand(Inst.getOperand(5));
6088 case ARM::VST1LNdAsm_8:
6089 case ARM::VST1LNdAsm_16:
6090 case ARM::VST1LNdAsm_32: {
6092 // Shuffle the operands around so the lane index operand is in the
6095 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6096 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6097 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6098 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6099 TmpInst.addOperand(Inst.getOperand(1)); // lane
6100 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6101 TmpInst.addOperand(Inst.getOperand(5));
6106 case ARM::VST2LNdAsm_8:
6107 case ARM::VST2LNdAsm_16:
6108 case ARM::VST2LNdAsm_32:
6109 case ARM::VST2LNqAsm_16:
6110 case ARM::VST2LNqAsm_32: {
6112 // Shuffle the operands around so the lane index operand is in the
6115 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6116 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6117 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6118 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6119 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6121 TmpInst.addOperand(Inst.getOperand(1)); // lane
6122 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6123 TmpInst.addOperand(Inst.getOperand(5));
6128 case ARM::VST3LNdAsm_8:
6129 case ARM::VST3LNdAsm_16:
6130 case ARM::VST3LNdAsm_32:
6131 case ARM::VST3LNqAsm_16:
6132 case ARM::VST3LNqAsm_32: {
6134 // Shuffle the operands around so the lane index operand is in the
6137 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6138 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6139 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6140 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6141 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6143 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6145 TmpInst.addOperand(Inst.getOperand(1)); // lane
6146 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6147 TmpInst.addOperand(Inst.getOperand(5));
6152 case ARM::VST4LNdAsm_8:
6153 case ARM::VST4LNdAsm_16:
6154 case ARM::VST4LNdAsm_32:
6155 case ARM::VST4LNqAsm_16:
6156 case ARM::VST4LNqAsm_32: {
6158 // Shuffle the operands around so the lane index operand is in the
6161 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6162 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6163 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6164 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6165 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6167 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6169 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6171 TmpInst.addOperand(Inst.getOperand(1)); // lane
6172 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6173 TmpInst.addOperand(Inst.getOperand(5));
6178 // Handle NEON VLD complex aliases.
6179 case ARM::VLD1LNdWB_register_Asm_8:
6180 case ARM::VLD1LNdWB_register_Asm_16:
6181 case ARM::VLD1LNdWB_register_Asm_32: {
6183 // Shuffle the operands around so the lane index operand is in the
6186 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6187 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6188 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6189 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6190 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6191 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6192 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6193 TmpInst.addOperand(Inst.getOperand(1)); // lane
6194 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6195 TmpInst.addOperand(Inst.getOperand(6));
6200 case ARM::VLD2LNdWB_register_Asm_8:
6201 case ARM::VLD2LNdWB_register_Asm_16:
6202 case ARM::VLD2LNdWB_register_Asm_32:
6203 case ARM::VLD2LNqWB_register_Asm_16:
6204 case ARM::VLD2LNqWB_register_Asm_32: {
6206 // Shuffle the operands around so the lane index operand is in the
6209 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6210 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6211 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6213 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6214 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6215 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6216 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6217 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6218 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6220 TmpInst.addOperand(Inst.getOperand(1)); // lane
6221 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6222 TmpInst.addOperand(Inst.getOperand(6));
6227 case ARM::VLD3LNdWB_register_Asm_8:
6228 case ARM::VLD3LNdWB_register_Asm_16:
6229 case ARM::VLD3LNdWB_register_Asm_32:
6230 case ARM::VLD3LNqWB_register_Asm_16:
6231 case ARM::VLD3LNqWB_register_Asm_32: {
6233 // Shuffle the operands around so the lane index operand is in the
6236 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6237 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6238 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6240 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6242 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6243 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6244 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6245 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6246 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6247 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6249 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6251 TmpInst.addOperand(Inst.getOperand(1)); // lane
6252 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6253 TmpInst.addOperand(Inst.getOperand(6));
6258 case ARM::VLD4LNdWB_register_Asm_8:
6259 case ARM::VLD4LNdWB_register_Asm_16:
6260 case ARM::VLD4LNdWB_register_Asm_32:
6261 case ARM::VLD4LNqWB_register_Asm_16:
6262 case ARM::VLD4LNqWB_register_Asm_32: {
6264 // Shuffle the operands around so the lane index operand is in the
6267 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6268 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6269 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6271 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6273 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6275 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6276 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6277 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6278 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6279 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6280 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6282 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6284 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6286 TmpInst.addOperand(Inst.getOperand(1)); // lane
6287 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6288 TmpInst.addOperand(Inst.getOperand(6));
6293 case ARM::VLD1LNdWB_fixed_Asm_8:
6294 case ARM::VLD1LNdWB_fixed_Asm_16:
6295 case ARM::VLD1LNdWB_fixed_Asm_32: {
6297 // Shuffle the operands around so the lane index operand is in the
6300 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6301 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6302 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6303 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6304 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6305 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6306 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6307 TmpInst.addOperand(Inst.getOperand(1)); // lane
6308 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6309 TmpInst.addOperand(Inst.getOperand(5));
6314 case ARM::VLD2LNdWB_fixed_Asm_8:
6315 case ARM::VLD2LNdWB_fixed_Asm_16:
6316 case ARM::VLD2LNdWB_fixed_Asm_32:
6317 case ARM::VLD2LNqWB_fixed_Asm_16:
6318 case ARM::VLD2LNqWB_fixed_Asm_32: {
6320 // Shuffle the operands around so the lane index operand is in the
6323 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6324 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6325 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6327 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6328 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6329 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6330 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6331 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6332 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6334 TmpInst.addOperand(Inst.getOperand(1)); // lane
6335 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6336 TmpInst.addOperand(Inst.getOperand(5));
6341 case ARM::VLD3LNdWB_fixed_Asm_8:
6342 case ARM::VLD3LNdWB_fixed_Asm_16:
6343 case ARM::VLD3LNdWB_fixed_Asm_32:
6344 case ARM::VLD3LNqWB_fixed_Asm_16:
6345 case ARM::VLD3LNqWB_fixed_Asm_32: {
6347 // Shuffle the operands around so the lane index operand is in the
6350 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6351 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6352 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6354 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6356 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6357 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6358 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6359 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6360 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6361 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6363 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6365 TmpInst.addOperand(Inst.getOperand(1)); // lane
6366 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6367 TmpInst.addOperand(Inst.getOperand(5));
6372 case ARM::VLD4LNdWB_fixed_Asm_8:
6373 case ARM::VLD4LNdWB_fixed_Asm_16:
6374 case ARM::VLD4LNdWB_fixed_Asm_32:
6375 case ARM::VLD4LNqWB_fixed_Asm_16:
6376 case ARM::VLD4LNqWB_fixed_Asm_32: {
6378 // Shuffle the operands around so the lane index operand is in the
6381 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6382 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6383 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6385 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6387 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6389 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6390 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6391 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6392 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6393 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6394 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6396 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6400 TmpInst.addOperand(Inst.getOperand(1)); // lane
6401 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6402 TmpInst.addOperand(Inst.getOperand(5));
6407 case ARM::VLD1LNdAsm_8:
6408 case ARM::VLD1LNdAsm_16:
6409 case ARM::VLD1LNdAsm_32: {
6411 // Shuffle the operands around so the lane index operand is in the
6414 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6415 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6416 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6417 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6418 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6419 TmpInst.addOperand(Inst.getOperand(1)); // lane
6420 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6421 TmpInst.addOperand(Inst.getOperand(5));
6426 case ARM::VLD2LNdAsm_8:
6427 case ARM::VLD2LNdAsm_16:
6428 case ARM::VLD2LNdAsm_32:
6429 case ARM::VLD2LNqAsm_16:
6430 case ARM::VLD2LNqAsm_32: {
6432 // Shuffle the operands around so the lane index operand is in the
6435 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6436 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6437 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6439 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6440 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6441 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6442 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6444 TmpInst.addOperand(Inst.getOperand(1)); // lane
6445 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6446 TmpInst.addOperand(Inst.getOperand(5));
6451 case ARM::VLD3LNdAsm_8:
6452 case ARM::VLD3LNdAsm_16:
6453 case ARM::VLD3LNdAsm_32:
6454 case ARM::VLD3LNqAsm_16:
6455 case ARM::VLD3LNqAsm_32: {
6457 // Shuffle the operands around so the lane index operand is in the
6460 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6461 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6462 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6464 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6466 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6467 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6468 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6469 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6473 TmpInst.addOperand(Inst.getOperand(1)); // lane
6474 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6475 TmpInst.addOperand(Inst.getOperand(5));
6480 case ARM::VLD4LNdAsm_8:
6481 case ARM::VLD4LNdAsm_16:
6482 case ARM::VLD4LNdAsm_32:
6483 case ARM::VLD4LNqAsm_16:
6484 case ARM::VLD4LNqAsm_32: {
6486 // Shuffle the operands around so the lane index operand is in the
6489 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6490 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6491 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6493 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6497 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6498 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6499 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6500 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6502 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6504 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6506 TmpInst.addOperand(Inst.getOperand(1)); // lane
6507 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6508 TmpInst.addOperand(Inst.getOperand(5));
6513 // VLD3DUP single 3-element structure to all lanes instructions.
6514 case ARM::VLD3DUPdAsm_8:
6515 case ARM::VLD3DUPdAsm_16:
6516 case ARM::VLD3DUPdAsm_32:
6517 case ARM::VLD3DUPqAsm_8:
6518 case ARM::VLD3DUPqAsm_16:
6519 case ARM::VLD3DUPqAsm_32: {
6522 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6523 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6524 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6526 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6528 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6529 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6530 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6531 TmpInst.addOperand(Inst.getOperand(4));
6536 case ARM::VLD3DUPdWB_fixed_Asm_8:
6537 case ARM::VLD3DUPdWB_fixed_Asm_16:
6538 case ARM::VLD3DUPdWB_fixed_Asm_32:
6539 case ARM::VLD3DUPqWB_fixed_Asm_8:
6540 case ARM::VLD3DUPqWB_fixed_Asm_16:
6541 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6544 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6545 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6550 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6551 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6552 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6553 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6554 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6555 TmpInst.addOperand(Inst.getOperand(4));
6560 case ARM::VLD3DUPdWB_register_Asm_8:
6561 case ARM::VLD3DUPdWB_register_Asm_16:
6562 case ARM::VLD3DUPdWB_register_Asm_32:
6563 case ARM::VLD3DUPqWB_register_Asm_8:
6564 case ARM::VLD3DUPqWB_register_Asm_16:
6565 case ARM::VLD3DUPqWB_register_Asm_32: {
6568 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6569 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6570 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6574 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6575 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6576 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6577 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6578 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6579 TmpInst.addOperand(Inst.getOperand(5));
6584 // VLD3 multiple 3-element structure instructions.
6585 case ARM::VLD3dAsm_8:
6586 case ARM::VLD3dAsm_16:
6587 case ARM::VLD3dAsm_32:
6588 case ARM::VLD3qAsm_8:
6589 case ARM::VLD3qAsm_16:
6590 case ARM::VLD3qAsm_32: {
6593 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6594 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6599 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6600 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6601 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6602 TmpInst.addOperand(Inst.getOperand(4));
6607 case ARM::VLD3dWB_fixed_Asm_8:
6608 case ARM::VLD3dWB_fixed_Asm_16:
6609 case ARM::VLD3dWB_fixed_Asm_32:
6610 case ARM::VLD3qWB_fixed_Asm_8:
6611 case ARM::VLD3qWB_fixed_Asm_16:
6612 case ARM::VLD3qWB_fixed_Asm_32: {
6615 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6616 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6617 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6621 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6622 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6623 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6624 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6625 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6626 TmpInst.addOperand(Inst.getOperand(4));
6631 case ARM::VLD3dWB_register_Asm_8:
6632 case ARM::VLD3dWB_register_Asm_16:
6633 case ARM::VLD3dWB_register_Asm_32:
6634 case ARM::VLD3qWB_register_Asm_8:
6635 case ARM::VLD3qWB_register_Asm_16:
6636 case ARM::VLD3qWB_register_Asm_32: {
6639 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6640 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6643 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
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(Inst.getOperand(3)); // Rm
6649 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6650 TmpInst.addOperand(Inst.getOperand(5));
6655 // VLD4DUP single 3-element structure to all lanes instructions.
6656 case ARM::VLD4DUPdAsm_8:
6657 case ARM::VLD4DUPdAsm_16:
6658 case ARM::VLD4DUPdAsm_32:
6659 case ARM::VLD4DUPqAsm_8:
6660 case ARM::VLD4DUPqAsm_16:
6661 case ARM::VLD4DUPqAsm_32: {
6664 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6665 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6666 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6668 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6670 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6672 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6673 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6674 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6675 TmpInst.addOperand(Inst.getOperand(4));
6680 case ARM::VLD4DUPdWB_fixed_Asm_8:
6681 case ARM::VLD4DUPdWB_fixed_Asm_16:
6682 case ARM::VLD4DUPdWB_fixed_Asm_32:
6683 case ARM::VLD4DUPqWB_fixed_Asm_8:
6684 case ARM::VLD4DUPqWB_fixed_Asm_16:
6685 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6688 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6689 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6690 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6692 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6694 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6696 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6697 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6698 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6699 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6700 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6701 TmpInst.addOperand(Inst.getOperand(4));
6706 case ARM::VLD4DUPdWB_register_Asm_8:
6707 case ARM::VLD4DUPdWB_register_Asm_16:
6708 case ARM::VLD4DUPdWB_register_Asm_32:
6709 case ARM::VLD4DUPqWB_register_Asm_8:
6710 case ARM::VLD4DUPqWB_register_Asm_16:
6711 case ARM::VLD4DUPqWB_register_Asm_32: {
6714 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6715 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6716 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6718 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6720 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6722 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6723 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6724 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6725 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6726 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6727 TmpInst.addOperand(Inst.getOperand(5));
6732 // VLD4 multiple 4-element structure instructions.
6733 case ARM::VLD4dAsm_8:
6734 case ARM::VLD4dAsm_16:
6735 case ARM::VLD4dAsm_32:
6736 case ARM::VLD4qAsm_8:
6737 case ARM::VLD4qAsm_16:
6738 case ARM::VLD4qAsm_32: {
6741 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6742 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6743 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6745 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6749 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6750 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6751 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6752 TmpInst.addOperand(Inst.getOperand(4));
6757 case ARM::VLD4dWB_fixed_Asm_8:
6758 case ARM::VLD4dWB_fixed_Asm_16:
6759 case ARM::VLD4dWB_fixed_Asm_32:
6760 case ARM::VLD4qWB_fixed_Asm_8:
6761 case ARM::VLD4qWB_fixed_Asm_16:
6762 case ARM::VLD4qWB_fixed_Asm_32: {
6765 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6766 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6767 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6769 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6771 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6773 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6774 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6775 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6776 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6777 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6778 TmpInst.addOperand(Inst.getOperand(4));
6783 case ARM::VLD4dWB_register_Asm_8:
6784 case ARM::VLD4dWB_register_Asm_16:
6785 case ARM::VLD4dWB_register_Asm_32:
6786 case ARM::VLD4qWB_register_Asm_8:
6787 case ARM::VLD4qWB_register_Asm_16:
6788 case ARM::VLD4qWB_register_Asm_32: {
6791 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6792 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6793 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6795 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6797 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6799 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6800 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6801 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6802 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6803 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6804 TmpInst.addOperand(Inst.getOperand(5));
6809 // VST3 multiple 3-element structure instructions.
6810 case ARM::VST3dAsm_8:
6811 case ARM::VST3dAsm_16:
6812 case ARM::VST3dAsm_32:
6813 case ARM::VST3qAsm_8:
6814 case ARM::VST3qAsm_16:
6815 case ARM::VST3qAsm_32: {
6818 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6819 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6820 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6821 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6822 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6824 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6826 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6827 TmpInst.addOperand(Inst.getOperand(4));
6832 case ARM::VST3dWB_fixed_Asm_8:
6833 case ARM::VST3dWB_fixed_Asm_16:
6834 case ARM::VST3dWB_fixed_Asm_32:
6835 case ARM::VST3qWB_fixed_Asm_8:
6836 case ARM::VST3qWB_fixed_Asm_16:
6837 case ARM::VST3qWB_fixed_Asm_32: {
6840 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6841 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6842 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6843 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6844 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6845 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6846 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6848 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6850 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6851 TmpInst.addOperand(Inst.getOperand(4));
6856 case ARM::VST3dWB_register_Asm_8:
6857 case ARM::VST3dWB_register_Asm_16:
6858 case ARM::VST3dWB_register_Asm_32:
6859 case ARM::VST3qWB_register_Asm_8:
6860 case ARM::VST3qWB_register_Asm_16:
6861 case ARM::VST3qWB_register_Asm_32: {
6864 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6865 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6866 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6867 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6868 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6869 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6870 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6872 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6874 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6875 TmpInst.addOperand(Inst.getOperand(5));
6880 // VST4 multiple 3-element structure instructions.
6881 case ARM::VST4dAsm_8:
6882 case ARM::VST4dAsm_16:
6883 case ARM::VST4dAsm_32:
6884 case ARM::VST4qAsm_8:
6885 case ARM::VST4qAsm_16:
6886 case ARM::VST4qAsm_32: {
6889 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6890 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6891 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6892 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6893 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6895 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6897 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6899 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6900 TmpInst.addOperand(Inst.getOperand(4));
6905 case ARM::VST4dWB_fixed_Asm_8:
6906 case ARM::VST4dWB_fixed_Asm_16:
6907 case ARM::VST4dWB_fixed_Asm_32:
6908 case ARM::VST4qWB_fixed_Asm_8:
6909 case ARM::VST4qWB_fixed_Asm_16:
6910 case ARM::VST4qWB_fixed_Asm_32: {
6913 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6914 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6915 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6916 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6917 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6918 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6919 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6921 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6923 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6925 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6926 TmpInst.addOperand(Inst.getOperand(4));
6931 case ARM::VST4dWB_register_Asm_8:
6932 case ARM::VST4dWB_register_Asm_16:
6933 case ARM::VST4dWB_register_Asm_32:
6934 case ARM::VST4qWB_register_Asm_8:
6935 case ARM::VST4qWB_register_Asm_16:
6936 case ARM::VST4qWB_register_Asm_32: {
6939 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6940 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6941 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6942 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6943 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6944 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6945 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6947 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6949 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6951 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6952 TmpInst.addOperand(Inst.getOperand(5));
6957 // Handle encoding choice for the shift-immediate instructions.
6960 case ARM::t2ASRri: {
6961 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6962 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6963 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6964 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6965 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6967 switch (Inst.getOpcode()) {
6968 default: llvm_unreachable("unexpected opcode");
6969 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6970 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6971 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6973 // The Thumb1 operands aren't in the same order. Awesome, eh?
6975 TmpInst.setOpcode(NewOpc);
6976 TmpInst.addOperand(Inst.getOperand(0));
6977 TmpInst.addOperand(Inst.getOperand(5));
6978 TmpInst.addOperand(Inst.getOperand(1));
6979 TmpInst.addOperand(Inst.getOperand(2));
6980 TmpInst.addOperand(Inst.getOperand(3));
6981 TmpInst.addOperand(Inst.getOperand(4));
6988 // Handle the Thumb2 mode MOV complex aliases.
6990 case ARM::t2MOVSsr: {
6991 // Which instruction to expand to depends on the CCOut operand and
6992 // whether we're in an IT block if the register operands are low
6994 bool isNarrow = false;
6995 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6996 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6997 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6998 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6999 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7003 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7004 default: llvm_unreachable("unexpected opcode!");
7005 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7006 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7007 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7008 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7010 TmpInst.setOpcode(newOpc);
7011 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7013 TmpInst.addOperand(MCOperand::CreateReg(
7014 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7015 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7016 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7017 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7018 TmpInst.addOperand(Inst.getOperand(5));
7020 TmpInst.addOperand(MCOperand::CreateReg(
7021 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7026 case ARM::t2MOVSsi: {
7027 // Which instruction to expand to depends on the CCOut operand and
7028 // whether we're in an IT block if the register operands are low
7030 bool isNarrow = false;
7031 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7032 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7033 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7037 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7038 default: llvm_unreachable("unexpected opcode!");
7039 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7040 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7041 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7042 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7043 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7045 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7046 if (Amount == 32) Amount = 0;
7047 TmpInst.setOpcode(newOpc);
7048 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7050 TmpInst.addOperand(MCOperand::CreateReg(
7051 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7052 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7053 if (newOpc != ARM::t2RRX)
7054 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7055 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7056 TmpInst.addOperand(Inst.getOperand(4));
7058 TmpInst.addOperand(MCOperand::CreateReg(
7059 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7063 // Handle the ARM mode MOV complex aliases.
7068 ARM_AM::ShiftOpc ShiftTy;
7069 switch(Inst.getOpcode()) {
7070 default: llvm_unreachable("unexpected opcode!");
7071 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7072 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7073 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7074 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7076 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7078 TmpInst.setOpcode(ARM::MOVsr);
7079 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7080 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7081 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7082 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7083 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7084 TmpInst.addOperand(Inst.getOperand(4));
7085 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7093 ARM_AM::ShiftOpc ShiftTy;
7094 switch(Inst.getOpcode()) {
7095 default: llvm_unreachable("unexpected opcode!");
7096 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7097 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7098 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7099 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7101 // A shift by zero is a plain MOVr, not a MOVsi.
7102 unsigned Amt = Inst.getOperand(2).getImm();
7103 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7104 // A shift by 32 should be encoded as 0 when permitted
7105 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7107 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7109 TmpInst.setOpcode(Opc);
7110 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7111 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7112 if (Opc == ARM::MOVsi)
7113 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7114 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7115 TmpInst.addOperand(Inst.getOperand(4));
7116 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7121 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7123 TmpInst.setOpcode(ARM::MOVsi);
7124 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7125 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7126 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7127 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7128 TmpInst.addOperand(Inst.getOperand(3));
7129 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7133 case ARM::t2LDMIA_UPD: {
7134 // If this is a load of a single register, then we should use
7135 // a post-indexed LDR instruction instead, per the ARM ARM.
7136 if (Inst.getNumOperands() != 5)
7139 TmpInst.setOpcode(ARM::t2LDR_POST);
7140 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7141 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7142 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7143 TmpInst.addOperand(MCOperand::CreateImm(4));
7144 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7145 TmpInst.addOperand(Inst.getOperand(3));
7149 case ARM::t2STMDB_UPD: {
7150 // If this is a store of a single register, then we should use
7151 // a pre-indexed STR instruction instead, per the ARM ARM.
7152 if (Inst.getNumOperands() != 5)
7155 TmpInst.setOpcode(ARM::t2STR_PRE);
7156 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7157 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7158 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7159 TmpInst.addOperand(MCOperand::CreateImm(-4));
7160 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7161 TmpInst.addOperand(Inst.getOperand(3));
7165 case ARM::LDMIA_UPD:
7166 // If this is a load of a single register via a 'pop', then we should use
7167 // a post-indexed LDR instruction instead, per the ARM ARM.
7168 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7169 Inst.getNumOperands() == 5) {
7171 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7172 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7173 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7174 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7175 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7176 TmpInst.addOperand(MCOperand::CreateImm(4));
7177 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7178 TmpInst.addOperand(Inst.getOperand(3));
7183 case ARM::STMDB_UPD:
7184 // If this is a store of a single register via a 'push', then we should use
7185 // a pre-indexed STR instruction instead, per the ARM ARM.
7186 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7187 Inst.getNumOperands() == 5) {
7189 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7190 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7191 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7192 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7193 TmpInst.addOperand(MCOperand::CreateImm(-4));
7194 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7195 TmpInst.addOperand(Inst.getOperand(3));
7199 case ARM::t2ADDri12:
7200 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7201 // mnemonic was used (not "addw"), encoding T3 is preferred.
7202 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7203 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7205 Inst.setOpcode(ARM::t2ADDri);
7206 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7208 case ARM::t2SUBri12:
7209 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7210 // mnemonic was used (not "subw"), encoding T3 is preferred.
7211 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7212 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7214 Inst.setOpcode(ARM::t2SUBri);
7215 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7218 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7219 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7220 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7221 // to encoding T1 if <Rd> is omitted."
7222 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7223 Inst.setOpcode(ARM::tADDi3);
7228 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7229 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7230 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7231 // to encoding T1 if <Rd> is omitted."
7232 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7233 Inst.setOpcode(ARM::tSUBi3);
7238 case ARM::t2SUBri: {
7239 // If the destination and first source operand are the same, and
7240 // the flags are compatible with the current IT status, use encoding T2
7241 // instead of T3. For compatibility with the system 'as'. Make sure the
7242 // wide encoding wasn't explicit.
7243 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7244 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7245 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7246 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7247 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7248 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7249 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7252 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7253 ARM::tADDi8 : ARM::tSUBi8);
7254 TmpInst.addOperand(Inst.getOperand(0));
7255 TmpInst.addOperand(Inst.getOperand(5));
7256 TmpInst.addOperand(Inst.getOperand(0));
7257 TmpInst.addOperand(Inst.getOperand(2));
7258 TmpInst.addOperand(Inst.getOperand(3));
7259 TmpInst.addOperand(Inst.getOperand(4));
7263 case ARM::t2ADDrr: {
7264 // If the destination and first source operand are the same, and
7265 // there's no setting of the flags, use encoding T2 instead of T3.
7266 // Note that this is only for ADD, not SUB. This mirrors the system
7267 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7268 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7269 Inst.getOperand(5).getReg() != 0 ||
7270 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7271 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7274 TmpInst.setOpcode(ARM::tADDhirr);
7275 TmpInst.addOperand(Inst.getOperand(0));
7276 TmpInst.addOperand(Inst.getOperand(0));
7277 TmpInst.addOperand(Inst.getOperand(2));
7278 TmpInst.addOperand(Inst.getOperand(3));
7279 TmpInst.addOperand(Inst.getOperand(4));
7283 case ARM::tADDrSP: {
7284 // If the non-SP source operand and the destination operand are not the
7285 // same, we need to use the 32-bit encoding if it's available.
7286 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7287 Inst.setOpcode(ARM::t2ADDrr);
7288 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7294 // A Thumb conditional branch outside of an IT block is a tBcc.
7295 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7296 Inst.setOpcode(ARM::tBcc);
7301 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7302 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7303 Inst.setOpcode(ARM::t2Bcc);
7308 // If the conditional is AL or we're in an IT block, we really want t2B.
7309 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7310 Inst.setOpcode(ARM::t2B);
7315 // If the conditional is AL, we really want tB.
7316 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7317 Inst.setOpcode(ARM::tB);
7322 // If the register list contains any high registers, or if the writeback
7323 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7324 // instead if we're in Thumb2. Otherwise, this should have generated
7325 // an error in validateInstruction().
7326 unsigned Rn = Inst.getOperand(0).getReg();
7327 bool hasWritebackToken =
7328 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7329 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7330 bool listContainsBase;
7331 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7332 (!listContainsBase && !hasWritebackToken) ||
7333 (listContainsBase && hasWritebackToken)) {
7334 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7335 assert (isThumbTwo());
7336 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7337 // If we're switching to the updating version, we need to insert
7338 // the writeback tied operand.
7339 if (hasWritebackToken)
7340 Inst.insert(Inst.begin(),
7341 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7346 case ARM::tSTMIA_UPD: {
7347 // If the register list contains any high registers, we need to use
7348 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7349 // should have generated an error in validateInstruction().
7350 unsigned Rn = Inst.getOperand(0).getReg();
7351 bool listContainsBase;
7352 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7353 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7354 assert (isThumbTwo());
7355 Inst.setOpcode(ARM::t2STMIA_UPD);
7361 bool listContainsBase;
7362 // If the register list contains any high registers, we need to use
7363 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7364 // should have generated an error in validateInstruction().
7365 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7367 assert (isThumbTwo());
7368 Inst.setOpcode(ARM::t2LDMIA_UPD);
7369 // Add the base register and writeback operands.
7370 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7371 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7375 bool listContainsBase;
7376 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7378 assert (isThumbTwo());
7379 Inst.setOpcode(ARM::t2STMDB_UPD);
7380 // Add the base register and writeback operands.
7381 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7382 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7386 // If we can use the 16-bit encoding and the user didn't explicitly
7387 // request the 32-bit variant, transform it here.
7388 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7389 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7390 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7391 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7392 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7393 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7394 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7395 // The operands aren't in the same order for tMOVi8...
7397 TmpInst.setOpcode(ARM::tMOVi8);
7398 TmpInst.addOperand(Inst.getOperand(0));
7399 TmpInst.addOperand(Inst.getOperand(4));
7400 TmpInst.addOperand(Inst.getOperand(1));
7401 TmpInst.addOperand(Inst.getOperand(2));
7402 TmpInst.addOperand(Inst.getOperand(3));
7409 // If we can use the 16-bit encoding and the user didn't explicitly
7410 // request the 32-bit variant, transform it here.
7411 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7412 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7413 Inst.getOperand(2).getImm() == ARMCC::AL &&
7414 Inst.getOperand(4).getReg() == ARM::CPSR &&
7415 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7416 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7417 // The operands aren't the same for tMOV[S]r... (no cc_out)
7419 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7420 TmpInst.addOperand(Inst.getOperand(0));
7421 TmpInst.addOperand(Inst.getOperand(1));
7422 TmpInst.addOperand(Inst.getOperand(2));
7423 TmpInst.addOperand(Inst.getOperand(3));
7433 // If we can use the 16-bit encoding and the user didn't explicitly
7434 // request the 32-bit variant, transform it here.
7435 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7436 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7437 Inst.getOperand(2).getImm() == 0 &&
7438 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7439 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7441 switch (Inst.getOpcode()) {
7442 default: llvm_unreachable("Illegal opcode!");
7443 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7444 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7445 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7446 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7448 // The operands aren't the same for thumb1 (no rotate operand).
7450 TmpInst.setOpcode(NewOpc);
7451 TmpInst.addOperand(Inst.getOperand(0));
7452 TmpInst.addOperand(Inst.getOperand(1));
7453 TmpInst.addOperand(Inst.getOperand(3));
7454 TmpInst.addOperand(Inst.getOperand(4));
7461 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7462 // rrx shifts and asr/lsr of #32 is encoded as 0
7463 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7465 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7466 // Shifting by zero is accepted as a vanilla 'MOVr'
7468 TmpInst.setOpcode(ARM::MOVr);
7469 TmpInst.addOperand(Inst.getOperand(0));
7470 TmpInst.addOperand(Inst.getOperand(1));
7471 TmpInst.addOperand(Inst.getOperand(3));
7472 TmpInst.addOperand(Inst.getOperand(4));
7473 TmpInst.addOperand(Inst.getOperand(5));
7486 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7487 if (SOpc == ARM_AM::rrx) return false;
7488 switch (Inst.getOpcode()) {
7489 default: llvm_unreachable("unexpected opcode!");
7490 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7491 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7492 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7493 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7494 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7495 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7497 // If the shift is by zero, use the non-shifted instruction definition.
7498 // The exception is for right shifts, where 0 == 32
7499 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7500 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7502 TmpInst.setOpcode(newOpc);
7503 TmpInst.addOperand(Inst.getOperand(0));
7504 TmpInst.addOperand(Inst.getOperand(1));
7505 TmpInst.addOperand(Inst.getOperand(2));
7506 TmpInst.addOperand(Inst.getOperand(4));
7507 TmpInst.addOperand(Inst.getOperand(5));
7508 TmpInst.addOperand(Inst.getOperand(6));
7516 // The mask bits for all but the first condition are represented as
7517 // the low bit of the condition code value implies 't'. We currently
7518 // always have 1 implies 't', so XOR toggle the bits if the low bit
7519 // of the condition code is zero.
7520 MCOperand &MO = Inst.getOperand(1);
7521 unsigned Mask = MO.getImm();
7522 unsigned OrigMask = Mask;
7523 unsigned TZ = countTrailingZeros(Mask);
7524 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7525 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7526 Mask ^= (0xE << TZ) & 0xF;
7530 // Set up the IT block state according to the IT instruction we just
7532 assert(!inITBlock() && "nested IT blocks?!");
7533 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7534 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7535 ITState.CurPosition = 0;
7536 ITState.FirstCond = true;
7546 // Assemblers should use the narrow encodings of these instructions when permissible.
7547 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7548 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7549 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7550 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7551 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7552 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7553 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7555 switch (Inst.getOpcode()) {
7556 default: llvm_unreachable("unexpected opcode");
7557 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7558 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7559 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7560 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7561 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7562 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7565 TmpInst.setOpcode(NewOpc);
7566 TmpInst.addOperand(Inst.getOperand(0));
7567 TmpInst.addOperand(Inst.getOperand(5));
7568 TmpInst.addOperand(Inst.getOperand(1));
7569 TmpInst.addOperand(Inst.getOperand(2));
7570 TmpInst.addOperand(Inst.getOperand(3));
7571 TmpInst.addOperand(Inst.getOperand(4));
7582 // Assemblers should use the narrow encodings of these instructions when permissible.
7583 // These instructions are special in that they are commutable, so shorter encodings
7584 // are available more often.
7585 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7586 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7587 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7588 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7589 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7590 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7591 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7592 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7594 switch (Inst.getOpcode()) {
7595 default: llvm_unreachable("unexpected opcode");
7596 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7597 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7598 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7599 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7602 TmpInst.setOpcode(NewOpc);
7603 TmpInst.addOperand(Inst.getOperand(0));
7604 TmpInst.addOperand(Inst.getOperand(5));
7605 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7606 TmpInst.addOperand(Inst.getOperand(1));
7607 TmpInst.addOperand(Inst.getOperand(2));
7609 TmpInst.addOperand(Inst.getOperand(2));
7610 TmpInst.addOperand(Inst.getOperand(1));
7612 TmpInst.addOperand(Inst.getOperand(3));
7613 TmpInst.addOperand(Inst.getOperand(4));
7623 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7624 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7625 // suffix depending on whether they're in an IT block or not.
7626 unsigned Opc = Inst.getOpcode();
7627 const MCInstrDesc &MCID = MII.get(Opc);
7628 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7629 assert(MCID.hasOptionalDef() &&
7630 "optionally flag setting instruction missing optional def operand");
7631 assert(MCID.NumOperands == Inst.getNumOperands() &&
7632 "operand count mismatch!");
7633 // Find the optional-def operand (cc_out).
7636 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7639 // If we're parsing Thumb1, reject it completely.
7640 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7641 return Match_MnemonicFail;
7642 // If we're parsing Thumb2, which form is legal depends on whether we're
7644 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7646 return Match_RequiresITBlock;
7647 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7649 return Match_RequiresNotITBlock;
7651 // Some high-register supporting Thumb1 encodings only allow both registers
7652 // to be from r0-r7 when in Thumb2.
7653 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7654 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7655 isARMLowRegister(Inst.getOperand(2).getReg()))
7656 return Match_RequiresThumb2;
7657 // Others only require ARMv6 or later.
7658 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7659 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7660 isARMLowRegister(Inst.getOperand(1).getReg()))
7661 return Match_RequiresV6;
7662 return Match_Success;
7665 static const char *getSubtargetFeatureName(unsigned Val);
7667 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7668 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7669 MCStreamer &Out, unsigned &ErrorInfo,
7670 bool MatchingInlineAsm) {
7672 unsigned MatchResult;
7674 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7676 switch (MatchResult) {
7679 // Context sensitive operand constraints aren't handled by the matcher,
7680 // so check them here.
7681 if (validateInstruction(Inst, Operands)) {
7682 // Still progress the IT block, otherwise one wrong condition causes
7683 // nasty cascading errors.
7684 forwardITPosition();
7688 { // processInstruction() updates inITBlock state, we need to save it away
7689 bool wasInITBlock = inITBlock();
7691 // Some instructions need post-processing to, for example, tweak which
7692 // encoding is selected. Loop on it while changes happen so the
7693 // individual transformations can chain off each other. E.g.,
7694 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7695 while (processInstruction(Inst, Operands))
7698 // Only after the instruction is fully processed, we can validate it
7699 if (wasInITBlock && hasV8Ops() && isThumb() &&
7700 !isV8EligibleForIT(&Inst, 2)) {
7701 Warning(IDLoc, "deprecated instruction in IT block");
7705 // Only move forward at the very end so that everything in validate
7706 // and process gets a consistent answer about whether we're in an IT
7708 forwardITPosition();
7710 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7711 // doesn't actually encode.
7712 if (Inst.getOpcode() == ARM::ITasm)
7716 Out.EmitInstruction(Inst);
7718 case Match_MissingFeature: {
7719 assert(ErrorInfo && "Unknown missing feature!");
7720 // Special case the error message for the very common case where only
7721 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7722 std::string Msg = "instruction requires:";
7724 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7725 if (ErrorInfo & Mask) {
7727 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7731 return Error(IDLoc, Msg);
7733 case Match_InvalidOperand: {
7734 SMLoc ErrorLoc = IDLoc;
7735 if (ErrorInfo != ~0U) {
7736 if (ErrorInfo >= Operands.size())
7737 return Error(IDLoc, "too few operands for instruction");
7739 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7740 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7743 return Error(ErrorLoc, "invalid operand for instruction");
7745 case Match_MnemonicFail:
7746 return Error(IDLoc, "invalid instruction",
7747 ((ARMOperand*)Operands[0])->getLocRange());
7748 case Match_RequiresNotITBlock:
7749 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7750 case Match_RequiresITBlock:
7751 return Error(IDLoc, "instruction only valid inside IT block");
7752 case Match_RequiresV6:
7753 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7754 case Match_RequiresThumb2:
7755 return Error(IDLoc, "instruction variant requires Thumb2");
7756 case Match_ImmRange0_15: {
7757 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7758 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7759 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7761 case Match_ImmRange0_239: {
7762 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7763 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7764 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7768 llvm_unreachable("Implement any new match types added!");
7771 /// parseDirective parses the arm specific directives
7772 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7773 StringRef IDVal = DirectiveID.getIdentifier();
7774 if (IDVal == ".word")
7775 return parseDirectiveWord(4, DirectiveID.getLoc());
7776 else if (IDVal == ".thumb")
7777 return parseDirectiveThumb(DirectiveID.getLoc());
7778 else if (IDVal == ".arm")
7779 return parseDirectiveARM(DirectiveID.getLoc());
7780 else if (IDVal == ".thumb_func")
7781 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7782 else if (IDVal == ".code")
7783 return parseDirectiveCode(DirectiveID.getLoc());
7784 else if (IDVal == ".syntax")
7785 return parseDirectiveSyntax(DirectiveID.getLoc());
7786 else if (IDVal == ".unreq")
7787 return parseDirectiveUnreq(DirectiveID.getLoc());
7788 else if (IDVal == ".arch")
7789 return parseDirectiveArch(DirectiveID.getLoc());
7790 else if (IDVal == ".eabi_attribute")
7791 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7792 else if (IDVal == ".cpu")
7793 return parseDirectiveCPU(DirectiveID.getLoc());
7794 else if (IDVal == ".fpu")
7795 return parseDirectiveFPU(DirectiveID.getLoc());
7796 else if (IDVal == ".fnstart")
7797 return parseDirectiveFnStart(DirectiveID.getLoc());
7798 else if (IDVal == ".fnend")
7799 return parseDirectiveFnEnd(DirectiveID.getLoc());
7800 else if (IDVal == ".cantunwind")
7801 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7802 else if (IDVal == ".personality")
7803 return parseDirectivePersonality(DirectiveID.getLoc());
7804 else if (IDVal == ".handlerdata")
7805 return parseDirectiveHandlerData(DirectiveID.getLoc());
7806 else if (IDVal == ".setfp")
7807 return parseDirectiveSetFP(DirectiveID.getLoc());
7808 else if (IDVal == ".pad")
7809 return parseDirectivePad(DirectiveID.getLoc());
7810 else if (IDVal == ".save")
7811 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7812 else if (IDVal == ".vsave")
7813 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7814 else if (IDVal == ".inst")
7815 return parseDirectiveInst(DirectiveID.getLoc());
7816 else if (IDVal == ".inst.n")
7817 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
7818 else if (IDVal == ".inst.w")
7819 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
7823 /// parseDirectiveWord
7824 /// ::= .word [ expression (, expression)* ]
7825 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7826 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7828 const MCExpr *Value;
7829 if (getParser().parseExpression(Value))
7832 getParser().getStreamer().EmitValue(Value, Size);
7834 if (getLexer().is(AsmToken::EndOfStatement))
7837 // FIXME: Improve diagnostic.
7838 if (getLexer().isNot(AsmToken::Comma))
7839 return Error(L, "unexpected token in directive");
7848 /// parseDirectiveThumb
7850 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7851 if (getLexer().isNot(AsmToken::EndOfStatement))
7852 return Error(L, "unexpected token in directive");
7856 return Error(L, "target does not support Thumb mode");
7860 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7864 /// parseDirectiveARM
7866 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7867 if (getLexer().isNot(AsmToken::EndOfStatement))
7868 return Error(L, "unexpected token in directive");
7872 return Error(L, "target does not support ARM mode");
7876 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7880 void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
7881 if (NextSymbolIsThumb) {
7882 getParser().getStreamer().EmitThumbFunc(Symbol);
7883 NextSymbolIsThumb = false;
7887 /// parseDirectiveThumbFunc
7888 /// ::= .thumbfunc symbol_name
7889 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7890 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7891 bool isMachO = MAI->hasSubsectionsViaSymbols();
7893 // Darwin asm has (optionally) function name after .thumb_func direction
7896 const AsmToken &Tok = Parser.getTok();
7897 if (Tok.isNot(AsmToken::EndOfStatement)) {
7898 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7899 return Error(L, "unexpected token in .thumb_func directive");
7901 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
7902 getParser().getStreamer().EmitThumbFunc(Func);
7903 Parser.Lex(); // Consume the identifier token.
7908 if (getLexer().isNot(AsmToken::EndOfStatement))
7909 return Error(L, "unexpected token in directive");
7911 NextSymbolIsThumb = true;
7916 /// parseDirectiveSyntax
7917 /// ::= .syntax unified | divided
7918 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7919 const AsmToken &Tok = Parser.getTok();
7920 if (Tok.isNot(AsmToken::Identifier))
7921 return Error(L, "unexpected token in .syntax directive");
7922 StringRef Mode = Tok.getString();
7923 if (Mode == "unified" || Mode == "UNIFIED")
7925 else if (Mode == "divided" || Mode == "DIVIDED")
7926 return Error(L, "'.syntax divided' arm asssembly not supported");
7928 return Error(L, "unrecognized syntax mode in .syntax directive");
7930 if (getLexer().isNot(AsmToken::EndOfStatement))
7931 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7934 // TODO tell the MC streamer the mode
7935 // getParser().getStreamer().Emit???();
7939 /// parseDirectiveCode
7940 /// ::= .code 16 | 32
7941 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7942 const AsmToken &Tok = Parser.getTok();
7943 if (Tok.isNot(AsmToken::Integer))
7944 return Error(L, "unexpected token in .code directive");
7945 int64_t Val = Parser.getTok().getIntVal();
7951 return Error(L, "invalid operand to .code directive");
7953 if (getLexer().isNot(AsmToken::EndOfStatement))
7954 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7959 return Error(L, "target does not support Thumb mode");
7963 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7966 return Error(L, "target does not support ARM mode");
7970 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7976 /// parseDirectiveReq
7977 /// ::= name .req registername
7978 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7979 Parser.Lex(); // Eat the '.req' token.
7981 SMLoc SRegLoc, ERegLoc;
7982 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7983 Parser.eatToEndOfStatement();
7984 return Error(SRegLoc, "register name expected");
7987 // Shouldn't be anything else.
7988 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7989 Parser.eatToEndOfStatement();
7990 return Error(Parser.getTok().getLoc(),
7991 "unexpected input in .req directive.");
7994 Parser.Lex(); // Consume the EndOfStatement
7996 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7997 return Error(SRegLoc, "redefinition of '" + Name +
7998 "' does not match original.");
8003 /// parseDirectiveUneq
8004 /// ::= .unreq registername
8005 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8006 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8007 Parser.eatToEndOfStatement();
8008 return Error(L, "unexpected input in .unreq directive.");
8010 RegisterReqs.erase(Parser.getTok().getIdentifier());
8011 Parser.Lex(); // Eat the identifier.
8015 /// parseDirectiveArch
8017 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8018 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8020 unsigned ID = StringSwitch<unsigned>(Arch)
8021 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8022 .Case(NAME, ARM::ID)
8023 #include "MCTargetDesc/ARMArchName.def"
8024 .Default(ARM::INVALID_ARCH);
8026 if (ID == ARM::INVALID_ARCH)
8027 return Error(L, "Unknown arch name");
8029 getTargetStreamer().emitArch(ID);
8033 /// parseDirectiveEabiAttr
8034 /// ::= .eabi_attribute int, int
8035 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8036 if (Parser.getTok().isNot(AsmToken::Integer))
8037 return Error(L, "integer expected");
8038 int64_t Tag = Parser.getTok().getIntVal();
8039 Parser.Lex(); // eat tag integer
8041 if (Parser.getTok().isNot(AsmToken::Comma))
8042 return Error(L, "comma expected");
8043 Parser.Lex(); // skip comma
8045 L = Parser.getTok().getLoc();
8046 if (Parser.getTok().isNot(AsmToken::Integer))
8047 return Error(L, "integer expected");
8048 int64_t Value = Parser.getTok().getIntVal();
8049 Parser.Lex(); // eat value integer
8051 getTargetStreamer().emitAttribute(Tag, Value);
8055 /// parseDirectiveCPU
8057 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8058 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8059 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8063 /// parseDirectiveFPU
8065 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8066 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8068 unsigned ID = StringSwitch<unsigned>(FPU)
8069 #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8070 #include "ARMFPUName.def"
8071 .Default(ARM::INVALID_FPU);
8073 if (ID == ARM::INVALID_FPU)
8074 return Error(L, "Unknown FPU name");
8076 getTargetStreamer().emitFPU(ID);
8080 /// parseDirectiveFnStart
8082 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8083 if (FnStartLoc.isValid()) {
8084 Error(L, ".fnstart starts before the end of previous one");
8085 Error(FnStartLoc, "previous .fnstart starts here");
8090 getTargetStreamer().emitFnStart();
8094 /// parseDirectiveFnEnd
8096 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8097 // Check the ordering of unwind directives
8098 if (!FnStartLoc.isValid())
8099 return Error(L, ".fnstart must precede .fnend directive");
8101 // Reset the unwind directives parser state
8102 resetUnwindDirectiveParserState();
8103 getTargetStreamer().emitFnEnd();
8107 /// parseDirectiveCantUnwind
8109 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8110 // Check the ordering of unwind directives
8112 if (!FnStartLoc.isValid())
8113 return Error(L, ".fnstart must precede .cantunwind directive");
8114 if (HandlerDataLoc.isValid()) {
8115 Error(L, ".cantunwind can't be used with .handlerdata directive");
8116 Error(HandlerDataLoc, ".handlerdata was specified here");
8119 if (PersonalityLoc.isValid()) {
8120 Error(L, ".cantunwind can't be used with .personality directive");
8121 Error(PersonalityLoc, ".personality was specified here");
8125 getTargetStreamer().emitCantUnwind();
8129 /// parseDirectivePersonality
8130 /// ::= .personality name
8131 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8132 // Check the ordering of unwind directives
8134 if (!FnStartLoc.isValid())
8135 return Error(L, ".fnstart must precede .personality directive");
8136 if (CantUnwindLoc.isValid()) {
8137 Error(L, ".personality can't be used with .cantunwind directive");
8138 Error(CantUnwindLoc, ".cantunwind was specified here");
8141 if (HandlerDataLoc.isValid()) {
8142 Error(L, ".personality must precede .handlerdata directive");
8143 Error(HandlerDataLoc, ".handlerdata was specified here");
8147 // Parse the name of the personality routine
8148 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8149 Parser.eatToEndOfStatement();
8150 return Error(L, "unexpected input in .personality directive.");
8152 StringRef Name(Parser.getTok().getIdentifier());
8155 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8156 getTargetStreamer().emitPersonality(PR);
8160 /// parseDirectiveHandlerData
8161 /// ::= .handlerdata
8162 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8163 // Check the ordering of unwind directives
8165 if (!FnStartLoc.isValid())
8166 return Error(L, ".fnstart must precede .personality directive");
8167 if (CantUnwindLoc.isValid()) {
8168 Error(L, ".handlerdata can't be used with .cantunwind directive");
8169 Error(CantUnwindLoc, ".cantunwind was specified here");
8173 getTargetStreamer().emitHandlerData();
8177 /// parseDirectiveSetFP
8178 /// ::= .setfp fpreg, spreg [, offset]
8179 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8180 // Check the ordering of unwind directives
8181 if (!FnStartLoc.isValid())
8182 return Error(L, ".fnstart must precede .setfp directive");
8183 if (HandlerDataLoc.isValid())
8184 return Error(L, ".setfp must precede .handlerdata directive");
8187 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8188 int NewFPReg = tryParseRegister();
8190 return Error(NewFPRegLoc, "frame pointer register expected");
8193 if (!Parser.getTok().is(AsmToken::Comma))
8194 return Error(Parser.getTok().getLoc(), "comma expected");
8195 Parser.Lex(); // skip comma
8198 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8199 int NewSPReg = tryParseRegister();
8201 return Error(NewSPRegLoc, "stack pointer register expected");
8203 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8204 return Error(NewSPRegLoc,
8205 "register should be either $sp or the latest fp register");
8207 // Update the frame pointer register
8212 if (Parser.getTok().is(AsmToken::Comma)) {
8213 Parser.Lex(); // skip comma
8215 if (Parser.getTok().isNot(AsmToken::Hash) &&
8216 Parser.getTok().isNot(AsmToken::Dollar)) {
8217 return Error(Parser.getTok().getLoc(), "'#' expected");
8219 Parser.Lex(); // skip hash token.
8221 const MCExpr *OffsetExpr;
8222 SMLoc ExLoc = Parser.getTok().getLoc();
8224 if (getParser().parseExpression(OffsetExpr, EndLoc))
8225 return Error(ExLoc, "malformed setfp offset");
8226 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8228 return Error(ExLoc, "setfp offset must be an immediate");
8230 Offset = CE->getValue();
8233 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8234 static_cast<unsigned>(NewSPReg), Offset);
8240 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8241 // Check the ordering of unwind directives
8242 if (!FnStartLoc.isValid())
8243 return Error(L, ".fnstart must precede .pad directive");
8244 if (HandlerDataLoc.isValid())
8245 return Error(L, ".pad must precede .handlerdata directive");
8248 if (Parser.getTok().isNot(AsmToken::Hash) &&
8249 Parser.getTok().isNot(AsmToken::Dollar)) {
8250 return Error(Parser.getTok().getLoc(), "'#' expected");
8252 Parser.Lex(); // skip hash token.
8254 const MCExpr *OffsetExpr;
8255 SMLoc ExLoc = Parser.getTok().getLoc();
8257 if (getParser().parseExpression(OffsetExpr, EndLoc))
8258 return Error(ExLoc, "malformed pad offset");
8259 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8261 return Error(ExLoc, "pad offset must be an immediate");
8263 getTargetStreamer().emitPad(CE->getValue());
8267 /// parseDirectiveRegSave
8268 /// ::= .save { registers }
8269 /// ::= .vsave { registers }
8270 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8271 // Check the ordering of unwind directives
8272 if (!FnStartLoc.isValid())
8273 return Error(L, ".fnstart must precede .save or .vsave directives");
8274 if (HandlerDataLoc.isValid())
8275 return Error(L, ".save or .vsave must precede .handlerdata directive");
8277 // RAII object to make sure parsed operands are deleted.
8278 struct CleanupObject {
8279 SmallVector<MCParsedAsmOperand *, 1> Operands;
8281 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8286 // Parse the register list
8287 if (parseRegisterList(CO.Operands))
8289 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
8290 if (!IsVector && !Op->isRegList())
8291 return Error(L, ".save expects GPR registers");
8292 if (IsVector && !Op->isDPRRegList())
8293 return Error(L, ".vsave expects DPR registers");
8295 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
8299 /// parseDirectiveInst
8300 /// ::= .inst opcode [, ...]
8301 /// ::= .inst.n opcode [, ...]
8302 /// ::= .inst.w opcode [, ...]
8303 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8315 Parser.eatToEndOfStatement();
8316 return Error(Loc, "cannot determine Thumb instruction size, "
8317 "use inst.n/inst.w instead");
8321 Parser.eatToEndOfStatement();
8322 return Error(Loc, "width suffixes are invalid in ARM mode");
8327 if (getLexer().is(AsmToken::EndOfStatement)) {
8328 Parser.eatToEndOfStatement();
8329 return Error(Loc, "expected expression following directive");
8335 if (getParser().parseExpression(Expr))
8336 return Error(Loc, "expected expression");
8338 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
8340 return Error(Loc, "expected constant expression");
8344 if (Value->getValue() > 0xffff)
8345 return Error(Loc, "inst.n operand is too big, use inst.w instead");
8348 if (Value->getValue() > 0xffffffff)
8350 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8353 llvm_unreachable("only supported widths are 2 and 4");
8356 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8358 if (getLexer().is(AsmToken::EndOfStatement))
8361 if (getLexer().isNot(AsmToken::Comma))
8362 return Error(Loc, "unexpected token in directive");
8371 /// Force static initialization.
8372 extern "C" void LLVMInitializeARMAsmParser() {
8373 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8374 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8377 #define GET_REGISTER_MATCHER
8378 #define GET_SUBTARGET_FEATURE_NAME
8379 #define GET_MATCHER_IMPLEMENTATION
8380 #include "ARMGenAsmMatcher.inc"
8382 // Define this matcher function after the auto-generated include so we
8383 // have the match class enum definitions.
8384 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8386 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8387 // If the kind is a token for a literal immediate, check if our asm
8388 // operand matches. This is for InstAliases which have a fixed-value
8389 // immediate in the syntax.
8390 if (Kind == MCK__35_0 && Op->isImm()) {
8391 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8393 return Match_InvalidOperand;
8394 if (CE->getValue() == 0)
8395 return Match_Success;
8397 return Match_InvalidOperand;