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 "llvm/MC/MCTargetAsmParser.h"
11 #include "MCTargetDesc/ARMAddressingModes.h"
12 #include "MCTargetDesc/ARMBaseInfo.h"
13 #include "MCTargetDesc/ARMMCExpr.h"
14 #include "llvm/ADT/BitVector.h"
15 #include "llvm/ADT/OwningPtr.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringSwitch.h"
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/MC/MCAsmInfo.h"
21 #include "llvm/MC/MCAssembler.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCELFStreamer.h"
24 #include "llvm/MC/MCExpr.h"
25 #include "llvm/MC/MCInst.h"
26 #include "llvm/MC/MCInstrDesc.h"
27 #include "llvm/MC/MCParser/MCAsmLexer.h"
28 #include "llvm/MC/MCParser/MCAsmParser.h"
29 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
30 #include "llvm/MC/MCRegisterInfo.h"
31 #include "llvm/MC/MCStreamer.h"
32 #include "llvm/MC/MCSubtargetInfo.h"
33 #include "llvm/Support/ELF.h"
34 #include "llvm/Support/MathExtras.h"
35 #include "llvm/Support/SourceMgr.h"
36 #include "llvm/Support/TargetRegistry.h"
37 #include "llvm/Support/raw_ostream.h"
45 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
47 class ARMAsmParser : public MCTargetAsmParser {
50 const MCRegisterInfo *MRI;
52 // Unwind directives state
58 void resetUnwindDirectiveParserState() {
60 CantUnwindLoc = SMLoc();
61 PersonalityLoc = SMLoc();
62 HandlerDataLoc = SMLoc();
66 // Map of register aliases registers via the .req directive.
67 StringMap<unsigned> RegisterReqs;
70 ARMCC::CondCodes Cond; // Condition for IT block.
71 unsigned Mask:4; // Condition mask for instructions.
72 // Starting at first 1 (from lsb).
73 // '1' condition as indicated in IT.
74 // '0' inverse of condition (else).
75 // Count of instructions in IT block is
76 // 4 - trailingzeroes(mask)
78 bool FirstCond; // Explicit flag for when we're parsing the
79 // First instruction in the IT block. It's
80 // implied in the mask, so needs special
83 unsigned CurPosition; // Current position in parsing of IT
84 // block. In range [0,3]. Initialized
85 // according to count of instructions in block.
86 // ~0U if no active IT block.
88 bool inITBlock() { return ITState.CurPosition != ~0U;}
89 void forwardITPosition() {
90 if (!inITBlock()) return;
91 // Move to the next instruction in the IT block, if there is one. If not,
92 // mark the block as done.
93 unsigned TZ = countTrailingZeros(ITState.Mask);
94 if (++ITState.CurPosition == 5 - TZ)
95 ITState.CurPosition = ~0U; // Done with the IT block after this.
99 MCAsmParser &getParser() const { return Parser; }
100 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
102 bool Warning(SMLoc L, const Twine &Msg,
103 ArrayRef<SMRange> Ranges = None) {
104 return Parser.Warning(L, Msg, Ranges);
106 bool Error(SMLoc L, const Twine &Msg,
107 ArrayRef<SMRange> Ranges = None) {
108 return Parser.Error(L, Msg, Ranges);
111 int tryParseRegister();
112 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
113 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
114 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
115 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
116 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
117 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
118 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
119 unsigned &ShiftAmount);
120 bool parseDirectiveWord(unsigned Size, SMLoc L);
121 bool parseDirectiveThumb(SMLoc L);
122 bool parseDirectiveARM(SMLoc L);
123 bool parseDirectiveThumbFunc(SMLoc L);
124 bool parseDirectiveCode(SMLoc L);
125 bool parseDirectiveSyntax(SMLoc L);
126 bool parseDirectiveReq(StringRef Name, SMLoc L);
127 bool parseDirectiveUnreq(SMLoc L);
128 bool parseDirectiveArch(SMLoc L);
129 bool parseDirectiveEabiAttr(SMLoc L);
130 bool parseDirectiveFnStart(SMLoc L);
131 bool parseDirectiveFnEnd(SMLoc L);
132 bool parseDirectiveCantUnwind(SMLoc L);
133 bool parseDirectivePersonality(SMLoc L);
134 bool parseDirectiveHandlerData(SMLoc L);
135 bool parseDirectiveSetFP(SMLoc L);
136 bool parseDirectivePad(SMLoc L);
137 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
139 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
140 bool &CarrySetting, unsigned &ProcessorIMod,
142 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
143 bool &CanAcceptPredicationCode);
145 bool isThumb() const {
146 // FIXME: Can tablegen auto-generate this?
147 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
149 bool isThumbOne() const {
150 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
152 bool isThumbTwo() const {
153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
155 bool hasThumb() const {
156 return STI.getFeatureBits() & ARM::HasV4TOps;
158 bool hasV6Ops() const {
159 return STI.getFeatureBits() & ARM::HasV6Ops;
161 bool hasV7Ops() const {
162 return STI.getFeatureBits() & ARM::HasV7Ops;
164 bool hasV8Ops() const {
165 return STI.getFeatureBits() & ARM::HasV8Ops;
167 bool hasARM() const {
168 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
172 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
173 setAvailableFeatures(FB);
175 bool isMClass() const {
176 return STI.getFeatureBits() & ARM::FeatureMClass;
179 /// @name Auto-generated Match Functions
182 #define GET_ASSEMBLER_HEADER
183 #include "ARMGenAsmMatcher.inc"
187 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
188 OperandMatchResultTy parseCoprocNumOperand(
189 SmallVectorImpl<MCParsedAsmOperand*>&);
190 OperandMatchResultTy parseCoprocRegOperand(
191 SmallVectorImpl<MCParsedAsmOperand*>&);
192 OperandMatchResultTy parseCoprocOptionOperand(
193 SmallVectorImpl<MCParsedAsmOperand*>&);
194 OperandMatchResultTy parseMemBarrierOptOperand(
195 SmallVectorImpl<MCParsedAsmOperand*>&);
196 OperandMatchResultTy parseInstSyncBarrierOptOperand(
197 SmallVectorImpl<MCParsedAsmOperand*>&);
198 OperandMatchResultTy parseProcIFlagsOperand(
199 SmallVectorImpl<MCParsedAsmOperand*>&);
200 OperandMatchResultTy parseMSRMaskOperand(
201 SmallVectorImpl<MCParsedAsmOperand*>&);
202 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
203 StringRef Op, int Low, int High);
204 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
205 return parsePKHImm(O, "lsl", 0, 31);
207 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
208 return parsePKHImm(O, "asr", 1, 32);
210 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
211 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
212 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
213 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
214 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
215 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
216 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
217 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
218 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
221 // Asm Match Converter Methods
222 void cvtThumbMultiply(MCInst &Inst,
223 const SmallVectorImpl<MCParsedAsmOperand*> &);
224 bool validateInstruction(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
226 bool processInstruction(MCInst &Inst,
227 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
228 bool shouldOmitCCOutOperand(StringRef Mnemonic,
229 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
230 bool shouldOmitPredicateOperand(StringRef Mnemonic,
231 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
234 enum ARMMatchResultTy {
235 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
236 Match_RequiresNotITBlock,
238 Match_RequiresThumb2,
239 #define GET_OPERAND_DIAGNOSTIC_TYPES
240 #include "ARMGenAsmMatcher.inc"
244 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
245 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
246 MCAsmParserExtension::Initialize(_Parser);
248 // Cache the MCRegisterInfo.
249 MRI = getContext().getRegisterInfo();
251 // Initialize the set of available features.
252 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
254 // Not in an ITBlock to start with.
255 ITState.CurPosition = ~0U;
257 // Set ELF header flags.
258 // FIXME: This should eventually end up somewhere else where more
259 // intelligent flag decisions can be made. For now we are just maintaining
260 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
261 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
262 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
265 // Implementation of the MCTargetAsmParser interface:
266 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
267 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
269 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
270 bool ParseDirective(AsmToken DirectiveID);
272 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
273 unsigned checkTargetMatchPredicate(MCInst &Inst);
275 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
276 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
277 MCStreamer &Out, unsigned &ErrorInfo,
278 bool MatchingInlineAsm);
280 } // end anonymous namespace
284 /// ARMOperand - Instances of this class represent a parsed ARM machine
286 class ARMOperand : public MCParsedAsmOperand {
296 k_InstSyncBarrierOpt,
307 k_VectorListAllLanes,
313 k_BitfieldDescriptor,
317 SMLoc StartLoc, EndLoc;
318 SmallVector<unsigned, 8> Registers;
321 ARMCC::CondCodes Val;
328 struct CoprocOptionOp {
341 ARM_ISB::InstSyncBOpt Val;
345 ARM_PROC::IFlags Val;
361 // A vector register list is a sequential list of 1 to 4 registers.
362 struct VectorListOp {
369 struct VectorIndexOp {
377 /// Combined record for all forms of ARM address expressions.
380 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
382 const MCConstantExpr *OffsetImm; // Offset immediate value
383 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
384 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
385 unsigned ShiftImm; // shift for OffsetReg.
386 unsigned Alignment; // 0 = no alignment specified
387 // n = alignment in bytes (2, 4, 8, 16, or 32)
388 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
391 struct PostIdxRegOp {
394 ARM_AM::ShiftOpc ShiftTy;
398 struct ShifterImmOp {
403 struct RegShiftedRegOp {
404 ARM_AM::ShiftOpc ShiftTy;
410 struct RegShiftedImmOp {
411 ARM_AM::ShiftOpc ShiftTy;
428 struct CoprocOptionOp CoprocOption;
429 struct MBOptOp MBOpt;
430 struct ISBOptOp ISBOpt;
431 struct ITMaskOp ITMask;
432 struct IFlagsOp IFlags;
433 struct MMaskOp MMask;
436 struct VectorListOp VectorList;
437 struct VectorIndexOp VectorIndex;
439 struct MemoryOp Memory;
440 struct PostIdxRegOp PostIdxReg;
441 struct ShifterImmOp ShifterImm;
442 struct RegShiftedRegOp RegShiftedReg;
443 struct RegShiftedImmOp RegShiftedImm;
444 struct RotImmOp RotImm;
445 struct BitfieldOp Bitfield;
448 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
450 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
452 StartLoc = o.StartLoc;
469 case k_DPRRegisterList:
470 case k_SPRRegisterList:
471 Registers = o.Registers;
474 case k_VectorListAllLanes:
475 case k_VectorListIndexed:
476 VectorList = o.VectorList;
483 CoprocOption = o.CoprocOption;
488 case k_MemBarrierOpt:
491 case k_InstSyncBarrierOpt:
496 case k_PostIndexRegister:
497 PostIdxReg = o.PostIdxReg;
505 case k_ShifterImmediate:
506 ShifterImm = o.ShifterImm;
508 case k_ShiftedRegister:
509 RegShiftedReg = o.RegShiftedReg;
511 case k_ShiftedImmediate:
512 RegShiftedImm = o.RegShiftedImm;
514 case k_RotateImmediate:
517 case k_BitfieldDescriptor:
518 Bitfield = o.Bitfield;
521 VectorIndex = o.VectorIndex;
526 /// getStartLoc - Get the location of the first token of this operand.
527 SMLoc getStartLoc() const { return StartLoc; }
528 /// getEndLoc - Get the location of the last token of this operand.
529 SMLoc getEndLoc() const { return EndLoc; }
530 /// getLocRange - Get the range between the first and last token of this
532 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
534 ARMCC::CondCodes getCondCode() const {
535 assert(Kind == k_CondCode && "Invalid access!");
539 unsigned getCoproc() const {
540 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
544 StringRef getToken() const {
545 assert(Kind == k_Token && "Invalid access!");
546 return StringRef(Tok.Data, Tok.Length);
549 unsigned getReg() const {
550 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
554 const SmallVectorImpl<unsigned> &getRegList() const {
555 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
556 Kind == k_SPRRegisterList) && "Invalid access!");
560 const MCExpr *getImm() const {
561 assert(isImm() && "Invalid access!");
565 unsigned getVectorIndex() const {
566 assert(Kind == k_VectorIndex && "Invalid access!");
567 return VectorIndex.Val;
570 ARM_MB::MemBOpt getMemBarrierOpt() const {
571 assert(Kind == k_MemBarrierOpt && "Invalid access!");
575 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
576 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
580 ARM_PROC::IFlags getProcIFlags() const {
581 assert(Kind == k_ProcIFlags && "Invalid access!");
585 unsigned getMSRMask() const {
586 assert(Kind == k_MSRMask && "Invalid access!");
590 bool isCoprocNum() const { return Kind == k_CoprocNum; }
591 bool isCoprocReg() const { return Kind == k_CoprocReg; }
592 bool isCoprocOption() const { return Kind == k_CoprocOption; }
593 bool isCondCode() const { return Kind == k_CondCode; }
594 bool isCCOut() const { return Kind == k_CCOut; }
595 bool isITMask() const { return Kind == k_ITCondMask; }
596 bool isITCondCode() const { return Kind == k_CondCode; }
597 bool isImm() const { return Kind == k_Immediate; }
598 // checks whether this operand is an unsigned offset which fits is a field
599 // of specified width and scaled by a specific number of bits
600 template<unsigned width, unsigned scale>
601 bool isUnsignedOffset() const {
602 if (!isImm()) return false;
603 if (dyn_cast<MCSymbolRefExpr>(Imm.Val)) return true;
604 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
605 int64_t Val = CE->getValue();
606 int64_t Align = 1LL << scale;
607 int64_t Max = Align * ((1LL << width) - 1);
608 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
612 bool isFPImm() const {
613 if (!isImm()) return false;
614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
615 if (!CE) return false;
616 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
619 bool isFBits16() const {
620 if (!isImm()) return false;
621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
622 if (!CE) return false;
623 int64_t Value = CE->getValue();
624 return Value >= 0 && Value <= 16;
626 bool isFBits32() const {
627 if (!isImm()) return false;
628 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
629 if (!CE) return false;
630 int64_t Value = CE->getValue();
631 return Value >= 1 && Value <= 32;
633 bool isImm8s4() const {
634 if (!isImm()) return false;
635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
636 if (!CE) return false;
637 int64_t Value = CE->getValue();
638 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
640 bool isImm0_4() const {
641 if (!isImm()) return false;
642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
643 if (!CE) return false;
644 int64_t Value = CE->getValue();
645 return Value >= 0 && Value < 5;
647 bool isImm0_1020s4() const {
648 if (!isImm()) return false;
649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
650 if (!CE) return false;
651 int64_t Value = CE->getValue();
652 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
654 bool isImm0_508s4() const {
655 if (!isImm()) return false;
656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
657 if (!CE) return false;
658 int64_t Value = CE->getValue();
659 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
661 bool isImm0_508s4Neg() const {
662 if (!isImm()) return false;
663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
664 if (!CE) return false;
665 int64_t Value = -CE->getValue();
666 // explicitly exclude zero. we want that to use the normal 0_508 version.
667 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
669 bool isImm0_255() const {
670 if (!isImm()) return false;
671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
672 if (!CE) return false;
673 int64_t Value = CE->getValue();
674 return Value >= 0 && Value < 256;
676 bool isImm0_4095() 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 < 4096;
683 bool isImm0_4095Neg() 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 > 0 && Value < 4096;
690 bool isImm0_1() 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 >= 0 && Value < 2;
697 bool isImm0_3() 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 >= 0 && Value < 4;
704 bool isImm0_7() 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 >= 0 && Value < 8;
711 bool isImm0_15() 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 return Value >= 0 && Value < 16;
718 bool isImm0_31() const {
719 if (!isImm()) return false;
720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
721 if (!CE) return false;
722 int64_t Value = CE->getValue();
723 return Value >= 0 && Value < 32;
725 bool isImm0_63() const {
726 if (!isImm()) return false;
727 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
728 if (!CE) return false;
729 int64_t Value = CE->getValue();
730 return Value >= 0 && Value < 64;
732 bool isImm8() const {
733 if (!isImm()) return false;
734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
735 if (!CE) return false;
736 int64_t Value = CE->getValue();
739 bool isImm16() const {
740 if (!isImm()) return false;
741 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
742 if (!CE) return false;
743 int64_t Value = CE->getValue();
746 bool isImm32() const {
747 if (!isImm()) return false;
748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
749 if (!CE) return false;
750 int64_t Value = CE->getValue();
753 bool isShrImm8() const {
754 if (!isImm()) return false;
755 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
756 if (!CE) return false;
757 int64_t Value = CE->getValue();
758 return Value > 0 && Value <= 8;
760 bool isShrImm16() const {
761 if (!isImm()) return false;
762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
763 if (!CE) return false;
764 int64_t Value = CE->getValue();
765 return Value > 0 && Value <= 16;
767 bool isShrImm32() const {
768 if (!isImm()) return false;
769 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
770 if (!CE) return false;
771 int64_t Value = CE->getValue();
772 return Value > 0 && Value <= 32;
774 bool isShrImm64() const {
775 if (!isImm()) return false;
776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
777 if (!CE) return false;
778 int64_t Value = CE->getValue();
779 return Value > 0 && Value <= 64;
781 bool isImm1_7() const {
782 if (!isImm()) return false;
783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
784 if (!CE) return false;
785 int64_t Value = CE->getValue();
786 return Value > 0 && Value < 8;
788 bool isImm1_15() const {
789 if (!isImm()) return false;
790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
791 if (!CE) return false;
792 int64_t Value = CE->getValue();
793 return Value > 0 && Value < 16;
795 bool isImm1_31() const {
796 if (!isImm()) return false;
797 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
798 if (!CE) return false;
799 int64_t Value = CE->getValue();
800 return Value > 0 && Value < 32;
802 bool isImm1_16() const {
803 if (!isImm()) return false;
804 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
805 if (!CE) return false;
806 int64_t Value = CE->getValue();
807 return Value > 0 && Value < 17;
809 bool isImm1_32() const {
810 if (!isImm()) return false;
811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
812 if (!CE) return false;
813 int64_t Value = CE->getValue();
814 return Value > 0 && Value < 33;
816 bool isImm0_32() const {
817 if (!isImm()) return false;
818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
819 if (!CE) return false;
820 int64_t Value = CE->getValue();
821 return Value >= 0 && Value < 33;
823 bool isImm0_65535() const {
824 if (!isImm()) return false;
825 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
826 if (!CE) return false;
827 int64_t Value = CE->getValue();
828 return Value >= 0 && Value < 65536;
830 bool isImm0_65535Expr() const {
831 if (!isImm()) return false;
832 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
833 // If it's not a constant expression, it'll generate a fixup and be
835 if (!CE) return true;
836 int64_t Value = CE->getValue();
837 return Value >= 0 && Value < 65536;
839 bool isImm24bit() const {
840 if (!isImm()) return false;
841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = CE->getValue();
844 return Value >= 0 && Value <= 0xffffff;
846 bool isImmThumbSR() const {
847 if (!isImm()) return false;
848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
849 if (!CE) return false;
850 int64_t Value = CE->getValue();
851 return Value > 0 && Value < 33;
853 bool isPKHLSLImm() const {
854 if (!isImm()) return false;
855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
856 if (!CE) return false;
857 int64_t Value = CE->getValue();
858 return Value >= 0 && Value < 32;
860 bool isPKHASRImm() const {
861 if (!isImm()) return false;
862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
863 if (!CE) return false;
864 int64_t Value = CE->getValue();
865 return Value > 0 && Value <= 32;
867 bool isAdrLabel() const {
868 // If we have an immediate that's not a constant, treat it as a label
869 // reference needing a fixup. If it is a constant, but it can't fit
870 // into shift immediate encoding, we reject it.
871 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
872 else return (isARMSOImm() || isARMSOImmNeg());
874 bool isARMSOImm() const {
875 if (!isImm()) return false;
876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
877 if (!CE) return false;
878 int64_t Value = CE->getValue();
879 return ARM_AM::getSOImmVal(Value) != -1;
881 bool isARMSOImmNot() const {
882 if (!isImm()) return false;
883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
884 if (!CE) return false;
885 int64_t Value = CE->getValue();
886 return ARM_AM::getSOImmVal(~Value) != -1;
888 bool isARMSOImmNeg() const {
889 if (!isImm()) return false;
890 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
891 if (!CE) return false;
892 int64_t Value = CE->getValue();
893 // Only use this when not representable as a plain so_imm.
894 return ARM_AM::getSOImmVal(Value) == -1 &&
895 ARM_AM::getSOImmVal(-Value) != -1;
897 bool isT2SOImm() const {
898 if (!isImm()) return false;
899 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
900 if (!CE) return false;
901 int64_t Value = CE->getValue();
902 return ARM_AM::getT2SOImmVal(Value) != -1;
904 bool isT2SOImmNot() const {
905 if (!isImm()) return false;
906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
907 if (!CE) return false;
908 int64_t Value = CE->getValue();
909 return ARM_AM::getT2SOImmVal(~Value) != -1;
911 bool isT2SOImmNeg() const {
912 if (!isImm()) return false;
913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
914 if (!CE) return false;
915 int64_t Value = CE->getValue();
916 // Only use this when not representable as a plain so_imm.
917 return ARM_AM::getT2SOImmVal(Value) == -1 &&
918 ARM_AM::getT2SOImmVal(-Value) != -1;
920 bool isSetEndImm() const {
921 if (!isImm()) return false;
922 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
923 if (!CE) return false;
924 int64_t Value = CE->getValue();
925 return Value == 1 || Value == 0;
927 bool isReg() const { return Kind == k_Register; }
928 bool isRegList() const { return Kind == k_RegisterList; }
929 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
930 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
931 bool isToken() const { return Kind == k_Token; }
932 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
933 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
934 bool isMem() const { return Kind == k_Memory; }
935 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
936 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
937 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
938 bool isRotImm() const { return Kind == k_RotateImmediate; }
939 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
940 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
941 bool isPostIdxReg() const {
942 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
944 bool isMemNoOffset(bool alignOK = false) const {
947 // No offset of any kind.
948 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
949 (alignOK || Memory.Alignment == 0);
951 bool isMemPCRelImm12() const {
952 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
954 // Base register must be PC.
955 if (Memory.BaseRegNum != ARM::PC)
957 // Immediate offset in range [-4095, 4095].
958 if (!Memory.OffsetImm) return true;
959 int64_t Val = Memory.OffsetImm->getValue();
960 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
962 bool isAlignedMemory() const {
963 return isMemNoOffset(true);
965 bool isAddrMode2() const {
966 if (!isMem() || Memory.Alignment != 0) return false;
967 // Check for register offset.
968 if (Memory.OffsetRegNum) return true;
969 // Immediate offset in range [-4095, 4095].
970 if (!Memory.OffsetImm) return true;
971 int64_t Val = Memory.OffsetImm->getValue();
972 return Val > -4096 && Val < 4096;
974 bool isAM2OffsetImm() const {
975 if (!isImm()) return false;
976 // Immediate offset in range [-4095, 4095].
977 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
978 if (!CE) return false;
979 int64_t Val = CE->getValue();
980 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
982 bool isAddrMode3() const {
983 // If we have an immediate that's not a constant, treat it as a label
984 // reference needing a fixup. If it is a constant, it's something else
986 if (isImm() && !isa<MCConstantExpr>(getImm()))
988 if (!isMem() || Memory.Alignment != 0) return false;
989 // No shifts are legal for AM3.
990 if (Memory.ShiftType != ARM_AM::no_shift) return false;
991 // Check for register offset.
992 if (Memory.OffsetRegNum) return true;
993 // Immediate offset in range [-255, 255].
994 if (!Memory.OffsetImm) return true;
995 int64_t Val = Memory.OffsetImm->getValue();
996 // The #-0 offset is encoded as INT32_MIN, and we have to check
998 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1000 bool isAM3Offset() const {
1001 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1003 if (Kind == k_PostIndexRegister)
1004 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1005 // Immediate offset in range [-255, 255].
1006 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1007 if (!CE) return false;
1008 int64_t Val = CE->getValue();
1009 // Special case, #-0 is INT32_MIN.
1010 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1012 bool isAddrMode5() const {
1013 // If we have an immediate that's not a constant, treat it as a label
1014 // reference needing a fixup. If it is a constant, it's something else
1015 // and we reject it.
1016 if (isImm() && !isa<MCConstantExpr>(getImm()))
1018 if (!isMem() || Memory.Alignment != 0) return false;
1019 // Check for register offset.
1020 if (Memory.OffsetRegNum) return false;
1021 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1022 if (!Memory.OffsetImm) return true;
1023 int64_t Val = Memory.OffsetImm->getValue();
1024 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1027 bool isMemTBB() const {
1028 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1029 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1033 bool isMemTBH() const {
1034 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1035 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1036 Memory.Alignment != 0 )
1040 bool isMemRegOffset() const {
1041 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1045 bool isT2MemRegOffset() const {
1046 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1047 Memory.Alignment != 0)
1049 // Only lsl #{0, 1, 2, 3} allowed.
1050 if (Memory.ShiftType == ARM_AM::no_shift)
1052 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1056 bool isMemThumbRR() const {
1057 // Thumb reg+reg addressing is simple. Just two registers, a base and
1058 // an offset. No shifts, negations or any other complicating factors.
1059 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1060 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1062 return isARMLowRegister(Memory.BaseRegNum) &&
1063 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1065 bool isMemThumbRIs4() const {
1066 if (!isMem() || Memory.OffsetRegNum != 0 ||
1067 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1069 // Immediate offset, multiple of 4 in range [0, 124].
1070 if (!Memory.OffsetImm) return true;
1071 int64_t Val = Memory.OffsetImm->getValue();
1072 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1074 bool isMemThumbRIs2() const {
1075 if (!isMem() || Memory.OffsetRegNum != 0 ||
1076 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1078 // Immediate offset, multiple of 4 in range [0, 62].
1079 if (!Memory.OffsetImm) return true;
1080 int64_t Val = Memory.OffsetImm->getValue();
1081 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1083 bool isMemThumbRIs1() const {
1084 if (!isMem() || Memory.OffsetRegNum != 0 ||
1085 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1087 // Immediate offset in range [0, 31].
1088 if (!Memory.OffsetImm) return true;
1089 int64_t Val = Memory.OffsetImm->getValue();
1090 return Val >= 0 && Val <= 31;
1092 bool isMemThumbSPI() const {
1093 if (!isMem() || Memory.OffsetRegNum != 0 ||
1094 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1096 // Immediate offset, multiple of 4 in range [0, 1020].
1097 if (!Memory.OffsetImm) return true;
1098 int64_t Val = Memory.OffsetImm->getValue();
1099 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1101 bool isMemImm8s4Offset() const {
1102 // If we have an immediate that's not a constant, treat it as a label
1103 // reference needing a fixup. If it is a constant, it's something else
1104 // and we reject it.
1105 if (isImm() && !isa<MCConstantExpr>(getImm()))
1107 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1109 // Immediate offset a multiple of 4 in range [-1020, 1020].
1110 if (!Memory.OffsetImm) return true;
1111 int64_t Val = Memory.OffsetImm->getValue();
1112 // Special case, #-0 is INT32_MIN.
1113 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1115 bool isMemImm0_1020s4Offset() const {
1116 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1118 // Immediate offset a multiple of 4 in range [0, 1020].
1119 if (!Memory.OffsetImm) return true;
1120 int64_t Val = Memory.OffsetImm->getValue();
1121 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1123 bool isMemImm8Offset() const {
1124 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1126 // Base reg of PC isn't allowed for these encodings.
1127 if (Memory.BaseRegNum == ARM::PC) return false;
1128 // Immediate offset in range [-255, 255].
1129 if (!Memory.OffsetImm) return true;
1130 int64_t Val = Memory.OffsetImm->getValue();
1131 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1133 bool isMemPosImm8Offset() const {
1134 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1136 // Immediate offset in range [0, 255].
1137 if (!Memory.OffsetImm) return true;
1138 int64_t Val = Memory.OffsetImm->getValue();
1139 return Val >= 0 && Val < 256;
1141 bool isMemNegImm8Offset() const {
1142 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1144 // Base reg of PC isn't allowed for these encodings.
1145 if (Memory.BaseRegNum == ARM::PC) return false;
1146 // Immediate offset in range [-255, -1].
1147 if (!Memory.OffsetImm) return false;
1148 int64_t Val = Memory.OffsetImm->getValue();
1149 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1151 bool isMemUImm12Offset() const {
1152 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1154 // Immediate offset in range [0, 4095].
1155 if (!Memory.OffsetImm) return true;
1156 int64_t Val = Memory.OffsetImm->getValue();
1157 return (Val >= 0 && Val < 4096);
1159 bool isMemImm12Offset() const {
1160 // If we have an immediate that's not a constant, treat it as a label
1161 // reference needing a fixup. If it is a constant, it's something else
1162 // and we reject it.
1163 if (isImm() && !isa<MCConstantExpr>(getImm()))
1166 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1168 // Immediate offset in range [-4095, 4095].
1169 if (!Memory.OffsetImm) return true;
1170 int64_t Val = Memory.OffsetImm->getValue();
1171 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1173 bool isPostIdxImm8() const {
1174 if (!isImm()) return false;
1175 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1176 if (!CE) return false;
1177 int64_t Val = CE->getValue();
1178 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1180 bool isPostIdxImm8s4() const {
1181 if (!isImm()) return false;
1182 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1183 if (!CE) return false;
1184 int64_t Val = CE->getValue();
1185 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1189 bool isMSRMask() const { return Kind == k_MSRMask; }
1190 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1193 bool isSingleSpacedVectorList() const {
1194 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1196 bool isDoubleSpacedVectorList() const {
1197 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1199 bool isVecListOneD() const {
1200 if (!isSingleSpacedVectorList()) return false;
1201 return VectorList.Count == 1;
1204 bool isVecListDPair() const {
1205 if (!isSingleSpacedVectorList()) return false;
1206 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1207 .contains(VectorList.RegNum));
1210 bool isVecListThreeD() const {
1211 if (!isSingleSpacedVectorList()) return false;
1212 return VectorList.Count == 3;
1215 bool isVecListFourD() const {
1216 if (!isSingleSpacedVectorList()) return false;
1217 return VectorList.Count == 4;
1220 bool isVecListDPairSpaced() const {
1221 if (isSingleSpacedVectorList()) return false;
1222 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1223 .contains(VectorList.RegNum));
1226 bool isVecListThreeQ() const {
1227 if (!isDoubleSpacedVectorList()) return false;
1228 return VectorList.Count == 3;
1231 bool isVecListFourQ() const {
1232 if (!isDoubleSpacedVectorList()) return false;
1233 return VectorList.Count == 4;
1236 bool isSingleSpacedVectorAllLanes() const {
1237 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1239 bool isDoubleSpacedVectorAllLanes() const {
1240 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1242 bool isVecListOneDAllLanes() const {
1243 if (!isSingleSpacedVectorAllLanes()) return false;
1244 return VectorList.Count == 1;
1247 bool isVecListDPairAllLanes() const {
1248 if (!isSingleSpacedVectorAllLanes()) return false;
1249 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1250 .contains(VectorList.RegNum));
1253 bool isVecListDPairSpacedAllLanes() const {
1254 if (!isDoubleSpacedVectorAllLanes()) return false;
1255 return VectorList.Count == 2;
1258 bool isVecListThreeDAllLanes() const {
1259 if (!isSingleSpacedVectorAllLanes()) return false;
1260 return VectorList.Count == 3;
1263 bool isVecListThreeQAllLanes() const {
1264 if (!isDoubleSpacedVectorAllLanes()) return false;
1265 return VectorList.Count == 3;
1268 bool isVecListFourDAllLanes() const {
1269 if (!isSingleSpacedVectorAllLanes()) return false;
1270 return VectorList.Count == 4;
1273 bool isVecListFourQAllLanes() const {
1274 if (!isDoubleSpacedVectorAllLanes()) return false;
1275 return VectorList.Count == 4;
1278 bool isSingleSpacedVectorIndexed() const {
1279 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1281 bool isDoubleSpacedVectorIndexed() const {
1282 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1284 bool isVecListOneDByteIndexed() const {
1285 if (!isSingleSpacedVectorIndexed()) return false;
1286 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1289 bool isVecListOneDHWordIndexed() const {
1290 if (!isSingleSpacedVectorIndexed()) return false;
1291 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1294 bool isVecListOneDWordIndexed() const {
1295 if (!isSingleSpacedVectorIndexed()) return false;
1296 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1299 bool isVecListTwoDByteIndexed() const {
1300 if (!isSingleSpacedVectorIndexed()) return false;
1301 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1304 bool isVecListTwoDHWordIndexed() const {
1305 if (!isSingleSpacedVectorIndexed()) return false;
1306 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1309 bool isVecListTwoQWordIndexed() const {
1310 if (!isDoubleSpacedVectorIndexed()) return false;
1311 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1314 bool isVecListTwoQHWordIndexed() const {
1315 if (!isDoubleSpacedVectorIndexed()) return false;
1316 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1319 bool isVecListTwoDWordIndexed() const {
1320 if (!isSingleSpacedVectorIndexed()) return false;
1321 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1324 bool isVecListThreeDByteIndexed() const {
1325 if (!isSingleSpacedVectorIndexed()) return false;
1326 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1329 bool isVecListThreeDHWordIndexed() const {
1330 if (!isSingleSpacedVectorIndexed()) return false;
1331 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1334 bool isVecListThreeQWordIndexed() const {
1335 if (!isDoubleSpacedVectorIndexed()) return false;
1336 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1339 bool isVecListThreeQHWordIndexed() const {
1340 if (!isDoubleSpacedVectorIndexed()) return false;
1341 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1344 bool isVecListThreeDWordIndexed() const {
1345 if (!isSingleSpacedVectorIndexed()) return false;
1346 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1349 bool isVecListFourDByteIndexed() const {
1350 if (!isSingleSpacedVectorIndexed()) return false;
1351 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1354 bool isVecListFourDHWordIndexed() const {
1355 if (!isSingleSpacedVectorIndexed()) return false;
1356 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1359 bool isVecListFourQWordIndexed() const {
1360 if (!isDoubleSpacedVectorIndexed()) return false;
1361 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1364 bool isVecListFourQHWordIndexed() const {
1365 if (!isDoubleSpacedVectorIndexed()) return false;
1366 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1369 bool isVecListFourDWordIndexed() const {
1370 if (!isSingleSpacedVectorIndexed()) return false;
1371 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1374 bool isVectorIndex8() const {
1375 if (Kind != k_VectorIndex) return false;
1376 return VectorIndex.Val < 8;
1378 bool isVectorIndex16() const {
1379 if (Kind != k_VectorIndex) return false;
1380 return VectorIndex.Val < 4;
1382 bool isVectorIndex32() const {
1383 if (Kind != k_VectorIndex) return false;
1384 return VectorIndex.Val < 2;
1387 bool isNEONi8splat() const {
1388 if (!isImm()) return false;
1389 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1390 // Must be a constant.
1391 if (!CE) return false;
1392 int64_t Value = CE->getValue();
1393 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1395 return Value >= 0 && Value < 256;
1398 bool isNEONi16splat() const {
1399 if (!isImm()) return false;
1400 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1401 // Must be a constant.
1402 if (!CE) return false;
1403 int64_t Value = CE->getValue();
1404 // i16 value in the range [0,255] or [0x0100, 0xff00]
1405 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1408 bool isNEONi32splat() const {
1409 if (!isImm()) return false;
1410 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1411 // Must be a constant.
1412 if (!CE) return false;
1413 int64_t Value = CE->getValue();
1414 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1415 return (Value >= 0 && Value < 256) ||
1416 (Value >= 0x0100 && Value <= 0xff00) ||
1417 (Value >= 0x010000 && Value <= 0xff0000) ||
1418 (Value >= 0x01000000 && Value <= 0xff000000);
1421 bool isNEONi32vmov() const {
1422 if (!isImm()) return false;
1423 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1424 // Must be a constant.
1425 if (!CE) return false;
1426 int64_t Value = CE->getValue();
1427 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1428 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1429 return (Value >= 0 && Value < 256) ||
1430 (Value >= 0x0100 && Value <= 0xff00) ||
1431 (Value >= 0x010000 && Value <= 0xff0000) ||
1432 (Value >= 0x01000000 && Value <= 0xff000000) ||
1433 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1434 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1436 bool isNEONi32vmovNeg() const {
1437 if (!isImm()) return false;
1438 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1439 // Must be a constant.
1440 if (!CE) return false;
1441 int64_t Value = ~CE->getValue();
1442 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1443 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1444 return (Value >= 0 && Value < 256) ||
1445 (Value >= 0x0100 && Value <= 0xff00) ||
1446 (Value >= 0x010000 && Value <= 0xff0000) ||
1447 (Value >= 0x01000000 && Value <= 0xff000000) ||
1448 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1449 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1452 bool isNEONi64splat() const {
1453 if (!isImm()) return false;
1454 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1455 // Must be a constant.
1456 if (!CE) return false;
1457 uint64_t Value = CE->getValue();
1458 // i64 value with each byte being either 0 or 0xff.
1459 for (unsigned i = 0; i < 8; ++i)
1460 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1464 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1465 // Add as immediates when possible. Null MCExpr = 0.
1467 Inst.addOperand(MCOperand::CreateImm(0));
1468 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1469 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1471 Inst.addOperand(MCOperand::CreateExpr(Expr));
1474 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1475 assert(N == 2 && "Invalid number of operands!");
1476 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1477 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1478 Inst.addOperand(MCOperand::CreateReg(RegNum));
1481 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1482 assert(N == 1 && "Invalid number of operands!");
1483 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1486 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1487 assert(N == 1 && "Invalid number of operands!");
1488 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1491 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1492 assert(N == 1 && "Invalid number of operands!");
1493 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1496 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1497 assert(N == 1 && "Invalid number of operands!");
1498 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1501 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1502 assert(N == 1 && "Invalid number of operands!");
1503 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1506 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1507 assert(N == 1 && "Invalid number of operands!");
1508 Inst.addOperand(MCOperand::CreateReg(getReg()));
1511 void addRegOperands(MCInst &Inst, unsigned N) const {
1512 assert(N == 1 && "Invalid number of operands!");
1513 Inst.addOperand(MCOperand::CreateReg(getReg()));
1516 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1517 assert(N == 3 && "Invalid number of operands!");
1518 assert(isRegShiftedReg() &&
1519 "addRegShiftedRegOperands() on non RegShiftedReg!");
1520 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1521 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1522 Inst.addOperand(MCOperand::CreateImm(
1523 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1526 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1527 assert(N == 2 && "Invalid number of operands!");
1528 assert(isRegShiftedImm() &&
1529 "addRegShiftedImmOperands() on non RegShiftedImm!");
1530 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1531 // Shift of #32 is encoded as 0 where permitted
1532 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1533 Inst.addOperand(MCOperand::CreateImm(
1534 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1537 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1538 assert(N == 1 && "Invalid number of operands!");
1539 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1543 void addRegListOperands(MCInst &Inst, unsigned N) const {
1544 assert(N == 1 && "Invalid number of operands!");
1545 const SmallVectorImpl<unsigned> &RegList = getRegList();
1546 for (SmallVectorImpl<unsigned>::const_iterator
1547 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1548 Inst.addOperand(MCOperand::CreateReg(*I));
1551 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1552 addRegListOperands(Inst, N);
1555 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1556 addRegListOperands(Inst, N);
1559 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1560 assert(N == 1 && "Invalid number of operands!");
1561 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1562 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1565 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1566 assert(N == 1 && "Invalid number of operands!");
1567 // Munge the lsb/width into a bitfield mask.
1568 unsigned lsb = Bitfield.LSB;
1569 unsigned width = Bitfield.Width;
1570 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1571 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1572 (32 - (lsb + width)));
1573 Inst.addOperand(MCOperand::CreateImm(Mask));
1576 void addImmOperands(MCInst &Inst, unsigned N) const {
1577 assert(N == 1 && "Invalid number of operands!");
1578 addExpr(Inst, getImm());
1581 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1582 assert(N == 1 && "Invalid number of operands!");
1583 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1584 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1587 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1588 assert(N == 1 && "Invalid number of operands!");
1589 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1590 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1593 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1594 assert(N == 1 && "Invalid number of operands!");
1595 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1596 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1597 Inst.addOperand(MCOperand::CreateImm(Val));
1600 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1601 assert(N == 1 && "Invalid number of operands!");
1602 // FIXME: We really want to scale the value here, but the LDRD/STRD
1603 // instruction don't encode operands that way yet.
1604 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1605 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1608 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1609 assert(N == 1 && "Invalid number of operands!");
1610 // The immediate is scaled by four in the encoding and is stored
1611 // in the MCInst as such. Lop off the low two bits here.
1612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1613 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1616 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1617 assert(N == 1 && "Invalid number of operands!");
1618 // The immediate is scaled by four in the encoding and is stored
1619 // in the MCInst as such. Lop off the low two bits here.
1620 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1621 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1624 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1625 assert(N == 1 && "Invalid number of operands!");
1626 // The immediate is scaled by four in the encoding and is stored
1627 // in the MCInst as such. Lop off the low two bits here.
1628 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1629 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1632 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1633 assert(N == 1 && "Invalid number of operands!");
1634 // The constant encodes as the immediate-1, and we store in the instruction
1635 // the bits as encoded, so subtract off one here.
1636 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1637 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1640 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1641 assert(N == 1 && "Invalid number of operands!");
1642 // The constant encodes as the immediate-1, and we store in the instruction
1643 // the bits as encoded, so subtract off one here.
1644 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1645 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1648 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1649 assert(N == 1 && "Invalid number of operands!");
1650 // The constant encodes as the immediate, except for 32, which encodes as
1652 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1653 unsigned Imm = CE->getValue();
1654 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1657 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1658 assert(N == 1 && "Invalid number of operands!");
1659 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1660 // the instruction as well.
1661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1662 int Val = CE->getValue();
1663 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1666 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1667 assert(N == 1 && "Invalid number of operands!");
1668 // The operand is actually a t2_so_imm, but we have its bitwise
1669 // negation in the assembly source, so twiddle it here.
1670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1671 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1674 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1675 assert(N == 1 && "Invalid number of operands!");
1676 // The operand is actually a t2_so_imm, but we have its
1677 // negation in the assembly source, so twiddle it here.
1678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1679 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1682 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1683 assert(N == 1 && "Invalid number of operands!");
1684 // The operand is actually an imm0_4095, but we have its
1685 // negation in the assembly source, so twiddle it here.
1686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1687 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1690 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1691 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1692 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1696 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1697 assert(SR && "Unknown value type!");
1698 Inst.addOperand(MCOperand::CreateExpr(SR));
1701 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1702 assert(N == 1 && "Invalid number of operands!");
1703 // The operand is actually a so_imm, but we have its bitwise
1704 // negation in the assembly source, so twiddle it here.
1705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1706 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1709 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1710 assert(N == 1 && "Invalid number of operands!");
1711 // The operand is actually a so_imm, but we have its
1712 // negation in the assembly source, so twiddle it here.
1713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1714 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1717 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1718 assert(N == 1 && "Invalid number of operands!");
1719 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1722 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1723 assert(N == 1 && "Invalid number of operands!");
1724 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1727 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1728 assert(N == 1 && "Invalid number of operands!");
1729 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1732 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1733 assert(N == 1 && "Invalid number of operands!");
1734 int32_t Imm = Memory.OffsetImm->getValue();
1735 // FIXME: Handle #-0
1736 if (Imm == INT32_MIN) Imm = 0;
1737 Inst.addOperand(MCOperand::CreateImm(Imm));
1740 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1741 assert(N == 1 && "Invalid number of operands!");
1742 assert(isImm() && "Not an immediate!");
1744 // If we have an immediate that's not a constant, treat it as a label
1745 // reference needing a fixup.
1746 if (!isa<MCConstantExpr>(getImm())) {
1747 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1751 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1752 int Val = CE->getValue();
1753 Inst.addOperand(MCOperand::CreateImm(Val));
1756 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1757 assert(N == 2 && "Invalid number of operands!");
1758 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1759 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1762 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1763 assert(N == 3 && "Invalid number of operands!");
1764 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1765 if (!Memory.OffsetRegNum) {
1766 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1767 // Special case for #-0
1768 if (Val == INT32_MIN) Val = 0;
1769 if (Val < 0) Val = -Val;
1770 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1772 // For register offset, we encode the shift type and negation flag
1774 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1775 Memory.ShiftImm, Memory.ShiftType);
1777 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1778 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1779 Inst.addOperand(MCOperand::CreateImm(Val));
1782 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1783 assert(N == 2 && "Invalid number of operands!");
1784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1785 assert(CE && "non-constant AM2OffsetImm operand!");
1786 int32_t Val = CE->getValue();
1787 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1788 // Special case for #-0
1789 if (Val == INT32_MIN) Val = 0;
1790 if (Val < 0) Val = -Val;
1791 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1792 Inst.addOperand(MCOperand::CreateReg(0));
1793 Inst.addOperand(MCOperand::CreateImm(Val));
1796 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1797 assert(N == 3 && "Invalid number of operands!");
1798 // If we have an immediate that's not a constant, treat it as a label
1799 // reference needing a fixup. If it is a constant, it's something else
1800 // and we reject it.
1802 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1803 Inst.addOperand(MCOperand::CreateReg(0));
1804 Inst.addOperand(MCOperand::CreateImm(0));
1808 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1809 if (!Memory.OffsetRegNum) {
1810 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1811 // Special case for #-0
1812 if (Val == INT32_MIN) Val = 0;
1813 if (Val < 0) Val = -Val;
1814 Val = ARM_AM::getAM3Opc(AddSub, Val);
1816 // For register offset, we encode the shift type and negation flag
1818 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1820 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1821 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1822 Inst.addOperand(MCOperand::CreateImm(Val));
1825 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1826 assert(N == 2 && "Invalid number of operands!");
1827 if (Kind == k_PostIndexRegister) {
1829 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1830 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1831 Inst.addOperand(MCOperand::CreateImm(Val));
1836 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1837 int32_t Val = CE->getValue();
1838 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1839 // Special case for #-0
1840 if (Val == INT32_MIN) Val = 0;
1841 if (Val < 0) Val = -Val;
1842 Val = ARM_AM::getAM3Opc(AddSub, Val);
1843 Inst.addOperand(MCOperand::CreateReg(0));
1844 Inst.addOperand(MCOperand::CreateImm(Val));
1847 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1848 assert(N == 2 && "Invalid number of operands!");
1849 // If we have an immediate that's not a constant, treat it as a label
1850 // reference needing a fixup. If it is a constant, it's something else
1851 // and we reject it.
1853 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1854 Inst.addOperand(MCOperand::CreateImm(0));
1858 // The lower two bits are always zero and as such are not encoded.
1859 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1860 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1861 // Special case for #-0
1862 if (Val == INT32_MIN) Val = 0;
1863 if (Val < 0) Val = -Val;
1864 Val = ARM_AM::getAM5Opc(AddSub, Val);
1865 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1866 Inst.addOperand(MCOperand::CreateImm(Val));
1869 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1870 assert(N == 2 && "Invalid number of operands!");
1871 // If we have an immediate that's not a constant, treat it as a label
1872 // reference needing a fixup. If it is a constant, it's something else
1873 // and we reject it.
1875 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1876 Inst.addOperand(MCOperand::CreateImm(0));
1880 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1881 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1882 Inst.addOperand(MCOperand::CreateImm(Val));
1885 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1886 assert(N == 2 && "Invalid number of operands!");
1887 // The lower two bits are always zero and as such are not encoded.
1888 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1889 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1890 Inst.addOperand(MCOperand::CreateImm(Val));
1893 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1894 assert(N == 2 && "Invalid number of operands!");
1895 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1896 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1897 Inst.addOperand(MCOperand::CreateImm(Val));
1900 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1901 addMemImm8OffsetOperands(Inst, N);
1904 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1905 addMemImm8OffsetOperands(Inst, N);
1908 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1909 assert(N == 2 && "Invalid number of operands!");
1910 // If this is an immediate, it's a label reference.
1912 addExpr(Inst, getImm());
1913 Inst.addOperand(MCOperand::CreateImm(0));
1917 // Otherwise, it's a normal memory reg+offset.
1918 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1919 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1920 Inst.addOperand(MCOperand::CreateImm(Val));
1923 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1924 assert(N == 2 && "Invalid number of operands!");
1925 // If this is an immediate, it's a label reference.
1927 addExpr(Inst, getImm());
1928 Inst.addOperand(MCOperand::CreateImm(0));
1932 // Otherwise, it's a normal memory reg+offset.
1933 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1934 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1935 Inst.addOperand(MCOperand::CreateImm(Val));
1938 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1939 assert(N == 2 && "Invalid number of operands!");
1940 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1941 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1944 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1945 assert(N == 2 && "Invalid number of operands!");
1946 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1947 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1950 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1951 assert(N == 3 && "Invalid number of operands!");
1953 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1954 Memory.ShiftImm, Memory.ShiftType);
1955 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1956 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1957 Inst.addOperand(MCOperand::CreateImm(Val));
1960 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1961 assert(N == 3 && "Invalid number of operands!");
1962 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1963 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1964 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
1967 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1968 assert(N == 2 && "Invalid number of operands!");
1969 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1970 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1973 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1974 assert(N == 2 && "Invalid number of operands!");
1975 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1976 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1977 Inst.addOperand(MCOperand::CreateImm(Val));
1980 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1981 assert(N == 2 && "Invalid number of operands!");
1982 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1983 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1984 Inst.addOperand(MCOperand::CreateImm(Val));
1987 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1988 assert(N == 2 && "Invalid number of operands!");
1989 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1990 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1991 Inst.addOperand(MCOperand::CreateImm(Val));
1994 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1995 assert(N == 2 && "Invalid number of operands!");
1996 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1997 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1998 Inst.addOperand(MCOperand::CreateImm(Val));
2001 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2002 assert(N == 1 && "Invalid number of operands!");
2003 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2004 assert(CE && "non-constant post-idx-imm8 operand!");
2005 int Imm = CE->getValue();
2006 bool isAdd = Imm >= 0;
2007 if (Imm == INT32_MIN) Imm = 0;
2008 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2009 Inst.addOperand(MCOperand::CreateImm(Imm));
2012 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2013 assert(N == 1 && "Invalid number of operands!");
2014 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2015 assert(CE && "non-constant post-idx-imm8s4 operand!");
2016 int Imm = CE->getValue();
2017 bool isAdd = Imm >= 0;
2018 if (Imm == INT32_MIN) Imm = 0;
2019 // Immediate is scaled by 4.
2020 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2021 Inst.addOperand(MCOperand::CreateImm(Imm));
2024 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2025 assert(N == 2 && "Invalid number of operands!");
2026 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2027 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2030 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2031 assert(N == 2 && "Invalid number of operands!");
2032 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2033 // The sign, shift type, and shift amount are encoded in a single operand
2034 // using the AM2 encoding helpers.
2035 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2036 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2037 PostIdxReg.ShiftTy);
2038 Inst.addOperand(MCOperand::CreateImm(Imm));
2041 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2042 assert(N == 1 && "Invalid number of operands!");
2043 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2046 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2047 assert(N == 1 && "Invalid number of operands!");
2048 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2051 void addVecListOperands(MCInst &Inst, unsigned N) const {
2052 assert(N == 1 && "Invalid number of operands!");
2053 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2056 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2057 assert(N == 2 && "Invalid number of operands!");
2058 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2059 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2062 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2063 assert(N == 1 && "Invalid number of operands!");
2064 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2067 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2068 assert(N == 1 && "Invalid number of operands!");
2069 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2072 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2073 assert(N == 1 && "Invalid number of operands!");
2074 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2077 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2078 assert(N == 1 && "Invalid number of operands!");
2079 // The immediate encodes the type of constant as well as the value.
2080 // Mask in that this is an i8 splat.
2081 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2082 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2085 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2086 assert(N == 1 && "Invalid number of operands!");
2087 // The immediate encodes the type of constant as well as the value.
2088 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2089 unsigned Value = CE->getValue();
2091 Value = (Value >> 8) | 0xa00;
2094 Inst.addOperand(MCOperand::CreateImm(Value));
2097 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2098 assert(N == 1 && "Invalid number of operands!");
2099 // The immediate encodes the type of constant as well as the value.
2100 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2101 unsigned Value = CE->getValue();
2102 if (Value >= 256 && Value <= 0xff00)
2103 Value = (Value >> 8) | 0x200;
2104 else if (Value > 0xffff && Value <= 0xff0000)
2105 Value = (Value >> 16) | 0x400;
2106 else if (Value > 0xffffff)
2107 Value = (Value >> 24) | 0x600;
2108 Inst.addOperand(MCOperand::CreateImm(Value));
2111 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2112 assert(N == 1 && "Invalid number of operands!");
2113 // The immediate encodes the type of constant as well as the value.
2114 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2115 unsigned Value = CE->getValue();
2116 if (Value >= 256 && Value <= 0xffff)
2117 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2118 else if (Value > 0xffff && Value <= 0xffffff)
2119 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2120 else if (Value > 0xffffff)
2121 Value = (Value >> 24) | 0x600;
2122 Inst.addOperand(MCOperand::CreateImm(Value));
2125 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2126 assert(N == 1 && "Invalid number of operands!");
2127 // The immediate encodes the type of constant as well as the value.
2128 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2129 unsigned Value = ~CE->getValue();
2130 if (Value >= 256 && Value <= 0xffff)
2131 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2132 else if (Value > 0xffff && Value <= 0xffffff)
2133 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2134 else if (Value > 0xffffff)
2135 Value = (Value >> 24) | 0x600;
2136 Inst.addOperand(MCOperand::CreateImm(Value));
2139 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2140 assert(N == 1 && "Invalid number of operands!");
2141 // The immediate encodes the type of constant as well as the value.
2142 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2143 uint64_t Value = CE->getValue();
2145 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2146 Imm |= (Value & 1) << i;
2148 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2151 virtual void print(raw_ostream &OS) const;
2153 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2154 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2155 Op->ITMask.Mask = Mask;
2161 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2162 ARMOperand *Op = new ARMOperand(k_CondCode);
2169 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2170 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2171 Op->Cop.Val = CopVal;
2177 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2178 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2179 Op->Cop.Val = CopVal;
2185 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2186 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2193 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2194 ARMOperand *Op = new ARMOperand(k_CCOut);
2195 Op->Reg.RegNum = RegNum;
2201 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2202 ARMOperand *Op = new ARMOperand(k_Token);
2203 Op->Tok.Data = Str.data();
2204 Op->Tok.Length = Str.size();
2210 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2211 ARMOperand *Op = new ARMOperand(k_Register);
2212 Op->Reg.RegNum = RegNum;
2218 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2223 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2224 Op->RegShiftedReg.ShiftTy = ShTy;
2225 Op->RegShiftedReg.SrcReg = SrcReg;
2226 Op->RegShiftedReg.ShiftReg = ShiftReg;
2227 Op->RegShiftedReg.ShiftImm = ShiftImm;
2233 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2237 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2238 Op->RegShiftedImm.ShiftTy = ShTy;
2239 Op->RegShiftedImm.SrcReg = SrcReg;
2240 Op->RegShiftedImm.ShiftImm = ShiftImm;
2246 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2248 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2249 Op->ShifterImm.isASR = isASR;
2250 Op->ShifterImm.Imm = Imm;
2256 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2257 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2258 Op->RotImm.Imm = Imm;
2264 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2266 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2267 Op->Bitfield.LSB = LSB;
2268 Op->Bitfield.Width = Width;
2275 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2276 SMLoc StartLoc, SMLoc EndLoc) {
2277 assert (Regs.size() > 0 && "RegList contains no registers?");
2278 KindTy Kind = k_RegisterList;
2280 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2281 Kind = k_DPRRegisterList;
2282 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2283 contains(Regs.front().second))
2284 Kind = k_SPRRegisterList;
2286 // Sort based on the register encoding values.
2287 array_pod_sort(Regs.begin(), Regs.end());
2289 ARMOperand *Op = new ARMOperand(Kind);
2290 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2291 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2292 Op->Registers.push_back(I->second);
2293 Op->StartLoc = StartLoc;
2294 Op->EndLoc = EndLoc;
2298 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2299 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2300 ARMOperand *Op = new ARMOperand(k_VectorList);
2301 Op->VectorList.RegNum = RegNum;
2302 Op->VectorList.Count = Count;
2303 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2309 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2310 bool isDoubleSpaced,
2312 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2313 Op->VectorList.RegNum = RegNum;
2314 Op->VectorList.Count = Count;
2315 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2321 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2323 bool isDoubleSpaced,
2325 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2326 Op->VectorList.RegNum = RegNum;
2327 Op->VectorList.Count = Count;
2328 Op->VectorList.LaneIndex = Index;
2329 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2335 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2337 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2338 Op->VectorIndex.Val = Idx;
2344 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2345 ARMOperand *Op = new ARMOperand(k_Immediate);
2352 static ARMOperand *CreateMem(unsigned BaseRegNum,
2353 const MCConstantExpr *OffsetImm,
2354 unsigned OffsetRegNum,
2355 ARM_AM::ShiftOpc ShiftType,
2360 ARMOperand *Op = new ARMOperand(k_Memory);
2361 Op->Memory.BaseRegNum = BaseRegNum;
2362 Op->Memory.OffsetImm = OffsetImm;
2363 Op->Memory.OffsetRegNum = OffsetRegNum;
2364 Op->Memory.ShiftType = ShiftType;
2365 Op->Memory.ShiftImm = ShiftImm;
2366 Op->Memory.Alignment = Alignment;
2367 Op->Memory.isNegative = isNegative;
2373 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2374 ARM_AM::ShiftOpc ShiftTy,
2377 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2378 Op->PostIdxReg.RegNum = RegNum;
2379 Op->PostIdxReg.isAdd = isAdd;
2380 Op->PostIdxReg.ShiftTy = ShiftTy;
2381 Op->PostIdxReg.ShiftImm = ShiftImm;
2387 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2388 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2389 Op->MBOpt.Val = Opt;
2395 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2397 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2398 Op->ISBOpt.Val = Opt;
2404 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2405 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2406 Op->IFlags.Val = IFlags;
2412 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2413 ARMOperand *Op = new ARMOperand(k_MSRMask);
2414 Op->MMask.Val = MMask;
2421 } // end anonymous namespace.
2423 void ARMOperand::print(raw_ostream &OS) const {
2426 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2429 OS << "<ccout " << getReg() << ">";
2431 case k_ITCondMask: {
2432 static const char *const MaskStr[] = {
2433 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2434 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2436 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2437 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2441 OS << "<coprocessor number: " << getCoproc() << ">";
2444 OS << "<coprocessor register: " << getCoproc() << ">";
2446 case k_CoprocOption:
2447 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2450 OS << "<mask: " << getMSRMask() << ">";
2453 getImm()->print(OS);
2455 case k_MemBarrierOpt:
2456 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2458 case k_InstSyncBarrierOpt:
2459 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2463 << " base:" << Memory.BaseRegNum;
2466 case k_PostIndexRegister:
2467 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2468 << PostIdxReg.RegNum;
2469 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2470 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2471 << PostIdxReg.ShiftImm;
2474 case k_ProcIFlags: {
2475 OS << "<ARM_PROC::";
2476 unsigned IFlags = getProcIFlags();
2477 for (int i=2; i >= 0; --i)
2478 if (IFlags & (1 << i))
2479 OS << ARM_PROC::IFlagsToString(1 << i);
2484 OS << "<register " << getReg() << ">";
2486 case k_ShifterImmediate:
2487 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2488 << " #" << ShifterImm.Imm << ">";
2490 case k_ShiftedRegister:
2491 OS << "<so_reg_reg "
2492 << RegShiftedReg.SrcReg << " "
2493 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2494 << " " << RegShiftedReg.ShiftReg << ">";
2496 case k_ShiftedImmediate:
2497 OS << "<so_reg_imm "
2498 << RegShiftedImm.SrcReg << " "
2499 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2500 << " #" << RegShiftedImm.ShiftImm << ">";
2502 case k_RotateImmediate:
2503 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2505 case k_BitfieldDescriptor:
2506 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2507 << ", width: " << Bitfield.Width << ">";
2509 case k_RegisterList:
2510 case k_DPRRegisterList:
2511 case k_SPRRegisterList: {
2512 OS << "<register_list ";
2514 const SmallVectorImpl<unsigned> &RegList = getRegList();
2515 for (SmallVectorImpl<unsigned>::const_iterator
2516 I = RegList.begin(), E = RegList.end(); I != E; ) {
2518 if (++I < E) OS << ", ";
2525 OS << "<vector_list " << VectorList.Count << " * "
2526 << VectorList.RegNum << ">";
2528 case k_VectorListAllLanes:
2529 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2530 << VectorList.RegNum << ">";
2532 case k_VectorListIndexed:
2533 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2534 << VectorList.Count << " * " << VectorList.RegNum << ">";
2537 OS << "'" << getToken() << "'";
2540 OS << "<vectorindex " << getVectorIndex() << ">";
2545 /// @name Auto-generated Match Functions
2548 static unsigned MatchRegisterName(StringRef Name);
2552 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2553 SMLoc &StartLoc, SMLoc &EndLoc) {
2554 StartLoc = Parser.getTok().getLoc();
2555 EndLoc = Parser.getTok().getEndLoc();
2556 RegNo = tryParseRegister();
2558 return (RegNo == (unsigned)-1);
2561 /// Try to parse a register name. The token must be an Identifier when called,
2562 /// and if it is a register name the token is eaten and the register number is
2563 /// returned. Otherwise return -1.
2565 int ARMAsmParser::tryParseRegister() {
2566 const AsmToken &Tok = Parser.getTok();
2567 if (Tok.isNot(AsmToken::Identifier)) return -1;
2569 std::string lowerCase = Tok.getString().lower();
2570 unsigned RegNum = MatchRegisterName(lowerCase);
2572 RegNum = StringSwitch<unsigned>(lowerCase)
2573 .Case("r13", ARM::SP)
2574 .Case("r14", ARM::LR)
2575 .Case("r15", ARM::PC)
2576 .Case("ip", ARM::R12)
2577 // Additional register name aliases for 'gas' compatibility.
2578 .Case("a1", ARM::R0)
2579 .Case("a2", ARM::R1)
2580 .Case("a3", ARM::R2)
2581 .Case("a4", ARM::R3)
2582 .Case("v1", ARM::R4)
2583 .Case("v2", ARM::R5)
2584 .Case("v3", ARM::R6)
2585 .Case("v4", ARM::R7)
2586 .Case("v5", ARM::R8)
2587 .Case("v6", ARM::R9)
2588 .Case("v7", ARM::R10)
2589 .Case("v8", ARM::R11)
2590 .Case("sb", ARM::R9)
2591 .Case("sl", ARM::R10)
2592 .Case("fp", ARM::R11)
2596 // Check for aliases registered via .req. Canonicalize to lower case.
2597 // That's more consistent since register names are case insensitive, and
2598 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2599 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2600 // If no match, return failure.
2601 if (Entry == RegisterReqs.end())
2603 Parser.Lex(); // Eat identifier token.
2604 return Entry->getValue();
2607 Parser.Lex(); // Eat identifier token.
2612 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2613 // If a recoverable error occurs, return 1. If an irrecoverable error
2614 // occurs, return -1. An irrecoverable error is one where tokens have been
2615 // consumed in the process of trying to parse the shifter (i.e., when it is
2616 // indeed a shifter operand, but malformed).
2617 int ARMAsmParser::tryParseShiftRegister(
2618 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2619 SMLoc S = Parser.getTok().getLoc();
2620 const AsmToken &Tok = Parser.getTok();
2621 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2623 std::string lowerCase = Tok.getString().lower();
2624 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2625 .Case("asl", ARM_AM::lsl)
2626 .Case("lsl", ARM_AM::lsl)
2627 .Case("lsr", ARM_AM::lsr)
2628 .Case("asr", ARM_AM::asr)
2629 .Case("ror", ARM_AM::ror)
2630 .Case("rrx", ARM_AM::rrx)
2631 .Default(ARM_AM::no_shift);
2633 if (ShiftTy == ARM_AM::no_shift)
2636 Parser.Lex(); // Eat the operator.
2638 // The source register for the shift has already been added to the
2639 // operand list, so we need to pop it off and combine it into the shifted
2640 // register operand instead.
2641 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2642 if (!PrevOp->isReg())
2643 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2644 int SrcReg = PrevOp->getReg();
2649 if (ShiftTy == ARM_AM::rrx) {
2650 // RRX Doesn't have an explicit shift amount. The encoder expects
2651 // the shift register to be the same as the source register. Seems odd,
2655 // Figure out if this is shifted by a constant or a register (for non-RRX).
2656 if (Parser.getTok().is(AsmToken::Hash) ||
2657 Parser.getTok().is(AsmToken::Dollar)) {
2658 Parser.Lex(); // Eat hash.
2659 SMLoc ImmLoc = Parser.getTok().getLoc();
2660 const MCExpr *ShiftExpr = 0;
2661 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2662 Error(ImmLoc, "invalid immediate shift value");
2665 // The expression must be evaluatable as an immediate.
2666 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2668 Error(ImmLoc, "invalid immediate shift value");
2671 // Range check the immediate.
2672 // lsl, ror: 0 <= imm <= 31
2673 // lsr, asr: 0 <= imm <= 32
2674 Imm = CE->getValue();
2676 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2677 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2678 Error(ImmLoc, "immediate shift value out of range");
2681 // shift by zero is a nop. Always send it through as lsl.
2682 // ('as' compatibility)
2684 ShiftTy = ARM_AM::lsl;
2685 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2686 SMLoc L = Parser.getTok().getLoc();
2687 EndLoc = Parser.getTok().getEndLoc();
2688 ShiftReg = tryParseRegister();
2689 if (ShiftReg == -1) {
2690 Error (L, "expected immediate or register in shift operand");
2694 Error (Parser.getTok().getLoc(),
2695 "expected immediate or register in shift operand");
2700 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2701 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2705 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2712 /// Try to parse a register name. The token must be an Identifier when called.
2713 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2714 /// if there is a "writeback". 'true' if it's not a register.
2716 /// TODO this is likely to change to allow different register types and or to
2717 /// parse for a specific register type.
2719 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2720 const AsmToken &RegTok = Parser.getTok();
2721 int RegNo = tryParseRegister();
2725 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2726 RegTok.getEndLoc()));
2728 const AsmToken &ExclaimTok = Parser.getTok();
2729 if (ExclaimTok.is(AsmToken::Exclaim)) {
2730 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2731 ExclaimTok.getLoc()));
2732 Parser.Lex(); // Eat exclaim token
2736 // Also check for an index operand. This is only legal for vector registers,
2737 // but that'll get caught OK in operand matching, so we don't need to
2738 // explicitly filter everything else out here.
2739 if (Parser.getTok().is(AsmToken::LBrac)) {
2740 SMLoc SIdx = Parser.getTok().getLoc();
2741 Parser.Lex(); // Eat left bracket token.
2743 const MCExpr *ImmVal;
2744 if (getParser().parseExpression(ImmVal))
2746 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2748 return TokError("immediate value expected for vector index");
2750 if (Parser.getTok().isNot(AsmToken::RBrac))
2751 return Error(Parser.getTok().getLoc(), "']' expected");
2753 SMLoc E = Parser.getTok().getEndLoc();
2754 Parser.Lex(); // Eat right bracket token.
2756 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2764 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2765 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2767 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2768 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2770 switch (Name.size()) {
2773 if (Name[0] != CoprocOp)
2789 if (Name[0] != CoprocOp || Name[1] != '1')
2793 case '0': return 10;
2794 case '1': return 11;
2795 case '2': return 12;
2796 case '3': return 13;
2797 case '4': return 14;
2798 case '5': return 15;
2803 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2804 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2805 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2806 SMLoc S = Parser.getTok().getLoc();
2807 const AsmToken &Tok = Parser.getTok();
2808 if (!Tok.is(AsmToken::Identifier))
2809 return MatchOperand_NoMatch;
2810 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2811 .Case("eq", ARMCC::EQ)
2812 .Case("ne", ARMCC::NE)
2813 .Case("hs", ARMCC::HS)
2814 .Case("cs", ARMCC::HS)
2815 .Case("lo", ARMCC::LO)
2816 .Case("cc", ARMCC::LO)
2817 .Case("mi", ARMCC::MI)
2818 .Case("pl", ARMCC::PL)
2819 .Case("vs", ARMCC::VS)
2820 .Case("vc", ARMCC::VC)
2821 .Case("hi", ARMCC::HI)
2822 .Case("ls", ARMCC::LS)
2823 .Case("ge", ARMCC::GE)
2824 .Case("lt", ARMCC::LT)
2825 .Case("gt", ARMCC::GT)
2826 .Case("le", ARMCC::LE)
2827 .Case("al", ARMCC::AL)
2830 return MatchOperand_NoMatch;
2831 Parser.Lex(); // Eat the token.
2833 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2835 return MatchOperand_Success;
2838 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2839 /// token must be an Identifier when called, and if it is a coprocessor
2840 /// number, the token is eaten and the operand is added to the operand list.
2841 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2842 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2843 SMLoc S = Parser.getTok().getLoc();
2844 const AsmToken &Tok = Parser.getTok();
2845 if (Tok.isNot(AsmToken::Identifier))
2846 return MatchOperand_NoMatch;
2848 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2850 return MatchOperand_NoMatch;
2852 Parser.Lex(); // Eat identifier token.
2853 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2854 return MatchOperand_Success;
2857 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2858 /// token must be an Identifier when called, and if it is a coprocessor
2859 /// number, the token is eaten and the operand is added to the operand list.
2860 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2861 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2862 SMLoc S = Parser.getTok().getLoc();
2863 const AsmToken &Tok = Parser.getTok();
2864 if (Tok.isNot(AsmToken::Identifier))
2865 return MatchOperand_NoMatch;
2867 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2869 return MatchOperand_NoMatch;
2871 Parser.Lex(); // Eat identifier token.
2872 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2873 return MatchOperand_Success;
2876 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2877 /// coproc_option : '{' imm0_255 '}'
2878 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2879 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2880 SMLoc S = Parser.getTok().getLoc();
2882 // If this isn't a '{', this isn't a coprocessor immediate operand.
2883 if (Parser.getTok().isNot(AsmToken::LCurly))
2884 return MatchOperand_NoMatch;
2885 Parser.Lex(); // Eat the '{'
2888 SMLoc Loc = Parser.getTok().getLoc();
2889 if (getParser().parseExpression(Expr)) {
2890 Error(Loc, "illegal expression");
2891 return MatchOperand_ParseFail;
2893 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2894 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2895 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2896 return MatchOperand_ParseFail;
2898 int Val = CE->getValue();
2900 // Check for and consume the closing '}'
2901 if (Parser.getTok().isNot(AsmToken::RCurly))
2902 return MatchOperand_ParseFail;
2903 SMLoc E = Parser.getTok().getEndLoc();
2904 Parser.Lex(); // Eat the '}'
2906 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2907 return MatchOperand_Success;
2910 // For register list parsing, we need to map from raw GPR register numbering
2911 // to the enumeration values. The enumeration values aren't sorted by
2912 // register number due to our using "sp", "lr" and "pc" as canonical names.
2913 static unsigned getNextRegister(unsigned Reg) {
2914 // If this is a GPR, we need to do it manually, otherwise we can rely
2915 // on the sort ordering of the enumeration since the other reg-classes
2917 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2920 default: llvm_unreachable("Invalid GPR number!");
2921 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2922 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2923 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2924 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2925 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2926 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2927 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2928 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2932 // Return the low-subreg of a given Q register.
2933 static unsigned getDRegFromQReg(unsigned QReg) {
2935 default: llvm_unreachable("expected a Q register!");
2936 case ARM::Q0: return ARM::D0;
2937 case ARM::Q1: return ARM::D2;
2938 case ARM::Q2: return ARM::D4;
2939 case ARM::Q3: return ARM::D6;
2940 case ARM::Q4: return ARM::D8;
2941 case ARM::Q5: return ARM::D10;
2942 case ARM::Q6: return ARM::D12;
2943 case ARM::Q7: return ARM::D14;
2944 case ARM::Q8: return ARM::D16;
2945 case ARM::Q9: return ARM::D18;
2946 case ARM::Q10: return ARM::D20;
2947 case ARM::Q11: return ARM::D22;
2948 case ARM::Q12: return ARM::D24;
2949 case ARM::Q13: return ARM::D26;
2950 case ARM::Q14: return ARM::D28;
2951 case ARM::Q15: return ARM::D30;
2955 /// Parse a register list.
2957 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2958 assert(Parser.getTok().is(AsmToken::LCurly) &&
2959 "Token is not a Left Curly Brace");
2960 SMLoc S = Parser.getTok().getLoc();
2961 Parser.Lex(); // Eat '{' token.
2962 SMLoc RegLoc = Parser.getTok().getLoc();
2964 // Check the first register in the list to see what register class
2965 // this is a list of.
2966 int Reg = tryParseRegister();
2968 return Error(RegLoc, "register expected");
2970 // The reglist instructions have at most 16 registers, so reserve
2971 // space for that many.
2973 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
2975 // Allow Q regs and just interpret them as the two D sub-registers.
2976 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2977 Reg = getDRegFromQReg(Reg);
2978 EReg = MRI->getEncodingValue(Reg);
2979 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
2982 const MCRegisterClass *RC;
2983 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2984 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2985 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2986 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2987 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2988 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2990 return Error(RegLoc, "invalid register in register list");
2992 // Store the register.
2993 EReg = MRI->getEncodingValue(Reg);
2994 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
2996 // This starts immediately after the first register token in the list,
2997 // so we can see either a comma or a minus (range separator) as a legal
2999 while (Parser.getTok().is(AsmToken::Comma) ||
3000 Parser.getTok().is(AsmToken::Minus)) {
3001 if (Parser.getTok().is(AsmToken::Minus)) {
3002 Parser.Lex(); // Eat the minus.
3003 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3004 int EndReg = tryParseRegister();
3006 return Error(AfterMinusLoc, "register expected");
3007 // Allow Q regs and just interpret them as the two D sub-registers.
3008 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3009 EndReg = getDRegFromQReg(EndReg) + 1;
3010 // If the register is the same as the start reg, there's nothing
3014 // The register must be in the same register class as the first.
3015 if (!RC->contains(EndReg))
3016 return Error(AfterMinusLoc, "invalid register in register list");
3017 // Ranges must go from low to high.
3018 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3019 return Error(AfterMinusLoc, "bad range in register list");
3021 // Add all the registers in the range to the register list.
3022 while (Reg != EndReg) {
3023 Reg = getNextRegister(Reg);
3024 EReg = MRI->getEncodingValue(Reg);
3025 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3029 Parser.Lex(); // Eat the comma.
3030 RegLoc = Parser.getTok().getLoc();
3032 const AsmToken RegTok = Parser.getTok();
3033 Reg = tryParseRegister();
3035 return Error(RegLoc, "register expected");
3036 // Allow Q regs and just interpret them as the two D sub-registers.
3037 bool isQReg = false;
3038 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3039 Reg = getDRegFromQReg(Reg);
3042 // The register must be in the same register class as the first.
3043 if (!RC->contains(Reg))
3044 return Error(RegLoc, "invalid register in register list");
3045 // List must be monotonically increasing.
3046 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3047 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3048 Warning(RegLoc, "register list not in ascending order");
3050 return Error(RegLoc, "register list not in ascending order");
3052 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3053 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3054 ") in register list");
3057 // VFP register lists must also be contiguous.
3058 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3060 return Error(RegLoc, "non-contiguous register range");
3061 EReg = MRI->getEncodingValue(Reg);
3062 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3064 EReg = MRI->getEncodingValue(++Reg);
3065 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3069 if (Parser.getTok().isNot(AsmToken::RCurly))
3070 return Error(Parser.getTok().getLoc(), "'}' expected");
3071 SMLoc E = Parser.getTok().getEndLoc();
3072 Parser.Lex(); // Eat '}' token.
3074 // Push the register list operand.
3075 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3077 // The ARM system instruction variants for LDM/STM have a '^' token here.
3078 if (Parser.getTok().is(AsmToken::Caret)) {
3079 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3080 Parser.Lex(); // Eat '^' token.
3086 // Helper function to parse the lane index for vector lists.
3087 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3088 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3089 Index = 0; // Always return a defined index value.
3090 if (Parser.getTok().is(AsmToken::LBrac)) {
3091 Parser.Lex(); // Eat the '['.
3092 if (Parser.getTok().is(AsmToken::RBrac)) {
3093 // "Dn[]" is the 'all lanes' syntax.
3094 LaneKind = AllLanes;
3095 EndLoc = Parser.getTok().getEndLoc();
3096 Parser.Lex(); // Eat the ']'.
3097 return MatchOperand_Success;
3100 // There's an optional '#' token here. Normally there wouldn't be, but
3101 // inline assemble puts one in, and it's friendly to accept that.
3102 if (Parser.getTok().is(AsmToken::Hash))
3103 Parser.Lex(); // Eat '#' or '$'.
3105 const MCExpr *LaneIndex;
3106 SMLoc Loc = Parser.getTok().getLoc();
3107 if (getParser().parseExpression(LaneIndex)) {
3108 Error(Loc, "illegal expression");
3109 return MatchOperand_ParseFail;
3111 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3113 Error(Loc, "lane index must be empty or an integer");
3114 return MatchOperand_ParseFail;
3116 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3117 Error(Parser.getTok().getLoc(), "']' expected");
3118 return MatchOperand_ParseFail;
3120 EndLoc = Parser.getTok().getEndLoc();
3121 Parser.Lex(); // Eat the ']'.
3122 int64_t Val = CE->getValue();
3124 // FIXME: Make this range check context sensitive for .8, .16, .32.
3125 if (Val < 0 || Val > 7) {
3126 Error(Parser.getTok().getLoc(), "lane index out of range");
3127 return MatchOperand_ParseFail;
3130 LaneKind = IndexedLane;
3131 return MatchOperand_Success;
3134 return MatchOperand_Success;
3137 // parse a vector register list
3138 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3139 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3140 VectorLaneTy LaneKind;
3142 SMLoc S = Parser.getTok().getLoc();
3143 // As an extension (to match gas), support a plain D register or Q register
3144 // (without encosing curly braces) as a single or double entry list,
3146 if (Parser.getTok().is(AsmToken::Identifier)) {
3147 SMLoc E = Parser.getTok().getEndLoc();
3148 int Reg = tryParseRegister();
3150 return MatchOperand_NoMatch;
3151 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3152 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3153 if (Res != MatchOperand_Success)
3157 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3160 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3164 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3169 return MatchOperand_Success;
3171 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3172 Reg = getDRegFromQReg(Reg);
3173 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3174 if (Res != MatchOperand_Success)
3178 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3179 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3180 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3183 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3184 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3185 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3189 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3194 return MatchOperand_Success;
3196 Error(S, "vector register expected");
3197 return MatchOperand_ParseFail;
3200 if (Parser.getTok().isNot(AsmToken::LCurly))
3201 return MatchOperand_NoMatch;
3203 Parser.Lex(); // Eat '{' token.
3204 SMLoc RegLoc = Parser.getTok().getLoc();
3206 int Reg = tryParseRegister();
3208 Error(RegLoc, "register expected");
3209 return MatchOperand_ParseFail;
3213 unsigned FirstReg = Reg;
3214 // The list is of D registers, but we also allow Q regs and just interpret
3215 // them as the two D sub-registers.
3216 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3217 FirstReg = Reg = getDRegFromQReg(Reg);
3218 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3219 // it's ambiguous with four-register single spaced.
3225 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3226 return MatchOperand_ParseFail;
3228 while (Parser.getTok().is(AsmToken::Comma) ||
3229 Parser.getTok().is(AsmToken::Minus)) {
3230 if (Parser.getTok().is(AsmToken::Minus)) {
3232 Spacing = 1; // Register range implies a single spaced list.
3233 else if (Spacing == 2) {
3234 Error(Parser.getTok().getLoc(),
3235 "sequential registers in double spaced list");
3236 return MatchOperand_ParseFail;
3238 Parser.Lex(); // Eat the minus.
3239 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3240 int EndReg = tryParseRegister();
3242 Error(AfterMinusLoc, "register expected");
3243 return MatchOperand_ParseFail;
3245 // Allow Q regs and just interpret them as the two D sub-registers.
3246 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3247 EndReg = getDRegFromQReg(EndReg) + 1;
3248 // If the register is the same as the start reg, there's nothing
3252 // The register must be in the same register class as the first.
3253 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3254 Error(AfterMinusLoc, "invalid register in register list");
3255 return MatchOperand_ParseFail;
3257 // Ranges must go from low to high.
3259 Error(AfterMinusLoc, "bad range in register list");
3260 return MatchOperand_ParseFail;
3262 // Parse the lane specifier if present.
3263 VectorLaneTy NextLaneKind;
3264 unsigned NextLaneIndex;
3265 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3266 MatchOperand_Success)
3267 return MatchOperand_ParseFail;
3268 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3269 Error(AfterMinusLoc, "mismatched lane index in register list");
3270 return MatchOperand_ParseFail;
3273 // Add all the registers in the range to the register list.
3274 Count += EndReg - Reg;
3278 Parser.Lex(); // Eat the comma.
3279 RegLoc = Parser.getTok().getLoc();
3281 Reg = tryParseRegister();
3283 Error(RegLoc, "register expected");
3284 return MatchOperand_ParseFail;
3286 // vector register lists must be contiguous.
3287 // It's OK to use the enumeration values directly here rather, as the
3288 // VFP register classes have the enum sorted properly.
3290 // The list is of D registers, but we also allow Q regs and just interpret
3291 // them as the two D sub-registers.
3292 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3294 Spacing = 1; // Register range implies a single spaced list.
3295 else if (Spacing == 2) {
3297 "invalid register in double-spaced list (must be 'D' register')");
3298 return MatchOperand_ParseFail;
3300 Reg = getDRegFromQReg(Reg);
3301 if (Reg != OldReg + 1) {
3302 Error(RegLoc, "non-contiguous register range");
3303 return MatchOperand_ParseFail;
3307 // Parse the lane specifier if present.
3308 VectorLaneTy NextLaneKind;
3309 unsigned NextLaneIndex;
3310 SMLoc LaneLoc = Parser.getTok().getLoc();
3311 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3312 MatchOperand_Success)
3313 return MatchOperand_ParseFail;
3314 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3315 Error(LaneLoc, "mismatched lane index in register list");
3316 return MatchOperand_ParseFail;
3320 // Normal D register.
3321 // Figure out the register spacing (single or double) of the list if
3322 // we don't know it already.
3324 Spacing = 1 + (Reg == OldReg + 2);
3326 // Just check that it's contiguous and keep going.
3327 if (Reg != OldReg + Spacing) {
3328 Error(RegLoc, "non-contiguous register range");
3329 return MatchOperand_ParseFail;
3332 // Parse the lane specifier if present.
3333 VectorLaneTy NextLaneKind;
3334 unsigned NextLaneIndex;
3335 SMLoc EndLoc = Parser.getTok().getLoc();
3336 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3337 return MatchOperand_ParseFail;
3338 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3339 Error(EndLoc, "mismatched lane index in register list");
3340 return MatchOperand_ParseFail;
3344 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3345 Error(Parser.getTok().getLoc(), "'}' expected");
3346 return MatchOperand_ParseFail;
3348 E = Parser.getTok().getEndLoc();
3349 Parser.Lex(); // Eat '}' token.
3353 // Two-register operands have been converted to the
3354 // composite register classes.
3356 const MCRegisterClass *RC = (Spacing == 1) ?
3357 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3358 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3359 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3362 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3363 (Spacing == 2), S, E));
3366 // Two-register operands have been converted to the
3367 // composite register classes.
3369 const MCRegisterClass *RC = (Spacing == 1) ?
3370 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3371 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3372 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3374 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3379 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3385 return MatchOperand_Success;
3388 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3389 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3390 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3391 SMLoc S = Parser.getTok().getLoc();
3392 const AsmToken &Tok = Parser.getTok();
3395 if (Tok.is(AsmToken::Identifier)) {
3396 StringRef OptStr = Tok.getString();
3398 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3399 .Case("sy", ARM_MB::SY)
3400 .Case("st", ARM_MB::ST)
3401 .Case("sh", ARM_MB::ISH)
3402 .Case("ish", ARM_MB::ISH)
3403 .Case("shst", ARM_MB::ISHST)
3404 .Case("ishst", ARM_MB::ISHST)
3405 .Case("nsh", ARM_MB::NSH)
3406 .Case("un", ARM_MB::NSH)
3407 .Case("nshst", ARM_MB::NSHST)
3408 .Case("unst", ARM_MB::NSHST)
3409 .Case("osh", ARM_MB::OSH)
3410 .Case("oshst", ARM_MB::OSHST)
3414 return MatchOperand_NoMatch;
3416 Parser.Lex(); // Eat identifier token.
3417 } else if (Tok.is(AsmToken::Hash) ||
3418 Tok.is(AsmToken::Dollar) ||
3419 Tok.is(AsmToken::Integer)) {
3420 if (Parser.getTok().isNot(AsmToken::Integer))
3421 Parser.Lex(); // Eat '#' or '$'.
3422 SMLoc Loc = Parser.getTok().getLoc();
3424 const MCExpr *MemBarrierID;
3425 if (getParser().parseExpression(MemBarrierID)) {
3426 Error(Loc, "illegal expression");
3427 return MatchOperand_ParseFail;
3430 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3432 Error(Loc, "constant expression expected");
3433 return MatchOperand_ParseFail;
3436 int Val = CE->getValue();
3438 Error(Loc, "immediate value out of range");
3439 return MatchOperand_ParseFail;
3442 Opt = ARM_MB::RESERVED_0 + Val;
3444 return MatchOperand_ParseFail;
3446 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3447 return MatchOperand_Success;
3450 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3451 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3452 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3453 SMLoc S = Parser.getTok().getLoc();
3454 const AsmToken &Tok = Parser.getTok();
3457 if (Tok.is(AsmToken::Identifier)) {
3458 StringRef OptStr = Tok.getString();
3460 if (OptStr.lower() == "sy")
3463 return MatchOperand_NoMatch;
3465 Parser.Lex(); // Eat identifier token.
3466 } else if (Tok.is(AsmToken::Hash) ||
3467 Tok.is(AsmToken::Dollar) ||
3468 Tok.is(AsmToken::Integer)) {
3469 if (Parser.getTok().isNot(AsmToken::Integer))
3470 Parser.Lex(); // Eat '#' or '$'.
3471 SMLoc Loc = Parser.getTok().getLoc();
3473 const MCExpr *ISBarrierID;
3474 if (getParser().parseExpression(ISBarrierID)) {
3475 Error(Loc, "illegal expression");
3476 return MatchOperand_ParseFail;
3479 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3481 Error(Loc, "constant expression expected");
3482 return MatchOperand_ParseFail;
3485 int Val = CE->getValue();
3487 Error(Loc, "immediate value out of range");
3488 return MatchOperand_ParseFail;
3491 Opt = ARM_ISB::RESERVED_0 + Val;
3493 return MatchOperand_ParseFail;
3495 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3496 (ARM_ISB::InstSyncBOpt)Opt, S));
3497 return MatchOperand_Success;
3501 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3502 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3503 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3504 SMLoc S = Parser.getTok().getLoc();
3505 const AsmToken &Tok = Parser.getTok();
3506 if (!Tok.is(AsmToken::Identifier))
3507 return MatchOperand_NoMatch;
3508 StringRef IFlagsStr = Tok.getString();
3510 // An iflags string of "none" is interpreted to mean that none of the AIF
3511 // bits are set. Not a terribly useful instruction, but a valid encoding.
3512 unsigned IFlags = 0;
3513 if (IFlagsStr != "none") {
3514 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3515 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3516 .Case("a", ARM_PROC::A)
3517 .Case("i", ARM_PROC::I)
3518 .Case("f", ARM_PROC::F)
3521 // If some specific iflag is already set, it means that some letter is
3522 // present more than once, this is not acceptable.
3523 if (Flag == ~0U || (IFlags & Flag))
3524 return MatchOperand_NoMatch;
3530 Parser.Lex(); // Eat identifier token.
3531 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3532 return MatchOperand_Success;
3535 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3536 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3537 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3538 SMLoc S = Parser.getTok().getLoc();
3539 const AsmToken &Tok = Parser.getTok();
3540 if (!Tok.is(AsmToken::Identifier))
3541 return MatchOperand_NoMatch;
3542 StringRef Mask = Tok.getString();
3545 // See ARMv6-M 10.1.1
3546 std::string Name = Mask.lower();
3547 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3548 // Note: in the documentation:
3549 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3550 // for MSR APSR_nzcvq.
3551 // but we do make it an alias here. This is so to get the "mask encoding"
3552 // bits correct on MSR APSR writes.
3554 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3555 // should really only be allowed when writing a special register. Note
3556 // they get dropped in the MRS instruction reading a special register as
3557 // the SYSm field is only 8 bits.
3559 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3560 // includes the DSP extension but that is not checked.
3561 .Case("apsr", 0x800)
3562 .Case("apsr_nzcvq", 0x800)
3563 .Case("apsr_g", 0x400)
3564 .Case("apsr_nzcvqg", 0xc00)
3565 .Case("iapsr", 0x801)
3566 .Case("iapsr_nzcvq", 0x801)
3567 .Case("iapsr_g", 0x401)
3568 .Case("iapsr_nzcvqg", 0xc01)
3569 .Case("eapsr", 0x802)
3570 .Case("eapsr_nzcvq", 0x802)
3571 .Case("eapsr_g", 0x402)
3572 .Case("eapsr_nzcvqg", 0xc02)
3573 .Case("xpsr", 0x803)
3574 .Case("xpsr_nzcvq", 0x803)
3575 .Case("xpsr_g", 0x403)
3576 .Case("xpsr_nzcvqg", 0xc03)
3577 .Case("ipsr", 0x805)
3578 .Case("epsr", 0x806)
3579 .Case("iepsr", 0x807)
3582 .Case("primask", 0x810)
3583 .Case("basepri", 0x811)
3584 .Case("basepri_max", 0x812)
3585 .Case("faultmask", 0x813)
3586 .Case("control", 0x814)
3589 if (FlagsVal == ~0U)
3590 return MatchOperand_NoMatch;
3592 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3593 // basepri, basepri_max and faultmask only valid for V7m.
3594 return MatchOperand_NoMatch;
3596 Parser.Lex(); // Eat identifier token.
3597 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3598 return MatchOperand_Success;
3601 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3602 size_t Start = 0, Next = Mask.find('_');
3603 StringRef Flags = "";
3604 std::string SpecReg = Mask.slice(Start, Next).lower();
3605 if (Next != StringRef::npos)
3606 Flags = Mask.slice(Next+1, Mask.size());
3608 // FlagsVal contains the complete mask:
3610 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3611 unsigned FlagsVal = 0;
3613 if (SpecReg == "apsr") {
3614 FlagsVal = StringSwitch<unsigned>(Flags)
3615 .Case("nzcvq", 0x8) // same as CPSR_f
3616 .Case("g", 0x4) // same as CPSR_s
3617 .Case("nzcvqg", 0xc) // same as CPSR_fs
3620 if (FlagsVal == ~0U) {
3622 return MatchOperand_NoMatch;
3624 FlagsVal = 8; // No flag
3626 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3627 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3628 if (Flags == "all" || Flags == "")
3630 for (int i = 0, e = Flags.size(); i != e; ++i) {
3631 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3638 // If some specific flag is already set, it means that some letter is
3639 // present more than once, this is not acceptable.
3640 if (FlagsVal == ~0U || (FlagsVal & Flag))
3641 return MatchOperand_NoMatch;
3644 } else // No match for special register.
3645 return MatchOperand_NoMatch;
3647 // Special register without flags is NOT equivalent to "fc" flags.
3648 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3649 // two lines would enable gas compatibility at the expense of breaking
3655 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3656 if (SpecReg == "spsr")
3659 Parser.Lex(); // Eat identifier token.
3660 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3661 return MatchOperand_Success;
3664 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3665 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3666 int Low, int High) {
3667 const AsmToken &Tok = Parser.getTok();
3668 if (Tok.isNot(AsmToken::Identifier)) {
3669 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3670 return MatchOperand_ParseFail;
3672 StringRef ShiftName = Tok.getString();
3673 std::string LowerOp = Op.lower();
3674 std::string UpperOp = Op.upper();
3675 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3676 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3677 return MatchOperand_ParseFail;
3679 Parser.Lex(); // Eat shift type token.
3681 // There must be a '#' and a shift amount.
3682 if (Parser.getTok().isNot(AsmToken::Hash) &&
3683 Parser.getTok().isNot(AsmToken::Dollar)) {
3684 Error(Parser.getTok().getLoc(), "'#' expected");
3685 return MatchOperand_ParseFail;
3687 Parser.Lex(); // Eat hash token.
3689 const MCExpr *ShiftAmount;
3690 SMLoc Loc = Parser.getTok().getLoc();
3692 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3693 Error(Loc, "illegal expression");
3694 return MatchOperand_ParseFail;
3696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3698 Error(Loc, "constant expression expected");
3699 return MatchOperand_ParseFail;
3701 int Val = CE->getValue();
3702 if (Val < Low || Val > High) {
3703 Error(Loc, "immediate value out of range");
3704 return MatchOperand_ParseFail;
3707 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3709 return MatchOperand_Success;
3712 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3713 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3714 const AsmToken &Tok = Parser.getTok();
3715 SMLoc S = Tok.getLoc();
3716 if (Tok.isNot(AsmToken::Identifier)) {
3717 Error(S, "'be' or 'le' operand expected");
3718 return MatchOperand_ParseFail;
3720 int Val = StringSwitch<int>(Tok.getString().lower())
3724 Parser.Lex(); // Eat the token.
3727 Error(S, "'be' or 'le' operand expected");
3728 return MatchOperand_ParseFail;
3730 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3732 S, Tok.getEndLoc()));
3733 return MatchOperand_Success;
3736 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3737 /// instructions. Legal values are:
3738 /// lsl #n 'n' in [0,31]
3739 /// asr #n 'n' in [1,32]
3740 /// n == 32 encoded as n == 0.
3741 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3742 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3743 const AsmToken &Tok = Parser.getTok();
3744 SMLoc S = Tok.getLoc();
3745 if (Tok.isNot(AsmToken::Identifier)) {
3746 Error(S, "shift operator 'asr' or 'lsl' expected");
3747 return MatchOperand_ParseFail;
3749 StringRef ShiftName = Tok.getString();
3751 if (ShiftName == "lsl" || ShiftName == "LSL")
3753 else if (ShiftName == "asr" || ShiftName == "ASR")
3756 Error(S, "shift operator 'asr' or 'lsl' expected");
3757 return MatchOperand_ParseFail;
3759 Parser.Lex(); // Eat the operator.
3761 // A '#' and a shift amount.
3762 if (Parser.getTok().isNot(AsmToken::Hash) &&
3763 Parser.getTok().isNot(AsmToken::Dollar)) {
3764 Error(Parser.getTok().getLoc(), "'#' expected");
3765 return MatchOperand_ParseFail;
3767 Parser.Lex(); // Eat hash token.
3768 SMLoc ExLoc = Parser.getTok().getLoc();
3770 const MCExpr *ShiftAmount;
3772 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3773 Error(ExLoc, "malformed shift expression");
3774 return MatchOperand_ParseFail;
3776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3778 Error(ExLoc, "shift amount must be an immediate");
3779 return MatchOperand_ParseFail;
3782 int64_t Val = CE->getValue();
3784 // Shift amount must be in [1,32]
3785 if (Val < 1 || Val > 32) {
3786 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3787 return MatchOperand_ParseFail;
3789 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3790 if (isThumb() && Val == 32) {
3791 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3792 return MatchOperand_ParseFail;
3794 if (Val == 32) Val = 0;
3796 // Shift amount must be in [1,32]
3797 if (Val < 0 || Val > 31) {
3798 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3799 return MatchOperand_ParseFail;
3803 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3805 return MatchOperand_Success;
3808 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3809 /// of instructions. Legal values are:
3810 /// ror #n 'n' in {0, 8, 16, 24}
3811 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3812 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3813 const AsmToken &Tok = Parser.getTok();
3814 SMLoc S = Tok.getLoc();
3815 if (Tok.isNot(AsmToken::Identifier))
3816 return MatchOperand_NoMatch;
3817 StringRef ShiftName = Tok.getString();
3818 if (ShiftName != "ror" && ShiftName != "ROR")
3819 return MatchOperand_NoMatch;
3820 Parser.Lex(); // Eat the operator.
3822 // A '#' and a rotate amount.
3823 if (Parser.getTok().isNot(AsmToken::Hash) &&
3824 Parser.getTok().isNot(AsmToken::Dollar)) {
3825 Error(Parser.getTok().getLoc(), "'#' expected");
3826 return MatchOperand_ParseFail;
3828 Parser.Lex(); // Eat hash token.
3829 SMLoc ExLoc = Parser.getTok().getLoc();
3831 const MCExpr *ShiftAmount;
3833 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3834 Error(ExLoc, "malformed rotate expression");
3835 return MatchOperand_ParseFail;
3837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3839 Error(ExLoc, "rotate amount must be an immediate");
3840 return MatchOperand_ParseFail;
3843 int64_t Val = CE->getValue();
3844 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3845 // normally, zero is represented in asm by omitting the rotate operand
3847 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3848 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
3849 return MatchOperand_ParseFail;
3852 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
3854 return MatchOperand_Success;
3857 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3858 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3859 SMLoc S = Parser.getTok().getLoc();
3860 // The bitfield descriptor is really two operands, the LSB and the width.
3861 if (Parser.getTok().isNot(AsmToken::Hash) &&
3862 Parser.getTok().isNot(AsmToken::Dollar)) {
3863 Error(Parser.getTok().getLoc(), "'#' expected");
3864 return MatchOperand_ParseFail;
3866 Parser.Lex(); // Eat hash token.
3868 const MCExpr *LSBExpr;
3869 SMLoc E = Parser.getTok().getLoc();
3870 if (getParser().parseExpression(LSBExpr)) {
3871 Error(E, "malformed immediate expression");
3872 return MatchOperand_ParseFail;
3874 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3876 Error(E, "'lsb' operand must be an immediate");
3877 return MatchOperand_ParseFail;
3880 int64_t LSB = CE->getValue();
3881 // The LSB must be in the range [0,31]
3882 if (LSB < 0 || LSB > 31) {
3883 Error(E, "'lsb' operand must be in the range [0,31]");
3884 return MatchOperand_ParseFail;
3886 E = Parser.getTok().getLoc();
3888 // Expect another immediate operand.
3889 if (Parser.getTok().isNot(AsmToken::Comma)) {
3890 Error(Parser.getTok().getLoc(), "too few operands");
3891 return MatchOperand_ParseFail;
3893 Parser.Lex(); // Eat hash token.
3894 if (Parser.getTok().isNot(AsmToken::Hash) &&
3895 Parser.getTok().isNot(AsmToken::Dollar)) {
3896 Error(Parser.getTok().getLoc(), "'#' expected");
3897 return MatchOperand_ParseFail;
3899 Parser.Lex(); // Eat hash token.
3901 const MCExpr *WidthExpr;
3903 if (getParser().parseExpression(WidthExpr, EndLoc)) {
3904 Error(E, "malformed immediate expression");
3905 return MatchOperand_ParseFail;
3907 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3909 Error(E, "'width' operand must be an immediate");
3910 return MatchOperand_ParseFail;
3913 int64_t Width = CE->getValue();
3914 // The LSB must be in the range [1,32-lsb]
3915 if (Width < 1 || Width > 32 - LSB) {
3916 Error(E, "'width' operand must be in the range [1,32-lsb]");
3917 return MatchOperand_ParseFail;
3920 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
3922 return MatchOperand_Success;
3925 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3926 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3927 // Check for a post-index addressing register operand. Specifically:
3928 // postidx_reg := '+' register {, shift}
3929 // | '-' register {, shift}
3930 // | register {, shift}
3932 // This method must return MatchOperand_NoMatch without consuming any tokens
3933 // in the case where there is no match, as other alternatives take other
3935 AsmToken Tok = Parser.getTok();
3936 SMLoc S = Tok.getLoc();
3937 bool haveEaten = false;
3939 if (Tok.is(AsmToken::Plus)) {
3940 Parser.Lex(); // Eat the '+' token.
3942 } else if (Tok.is(AsmToken::Minus)) {
3943 Parser.Lex(); // Eat the '-' token.
3948 SMLoc E = Parser.getTok().getEndLoc();
3949 int Reg = tryParseRegister();
3952 return MatchOperand_NoMatch;
3953 Error(Parser.getTok().getLoc(), "register expected");
3954 return MatchOperand_ParseFail;
3957 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3958 unsigned ShiftImm = 0;
3959 if (Parser.getTok().is(AsmToken::Comma)) {
3960 Parser.Lex(); // Eat the ','.
3961 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3962 return MatchOperand_ParseFail;
3964 // FIXME: Only approximates end...may include intervening whitespace.
3965 E = Parser.getTok().getLoc();
3968 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3971 return MatchOperand_Success;
3974 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3975 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3976 // Check for a post-index addressing register operand. Specifically:
3977 // am3offset := '+' register
3984 // This method must return MatchOperand_NoMatch without consuming any tokens
3985 // in the case where there is no match, as other alternatives take other
3987 AsmToken Tok = Parser.getTok();
3988 SMLoc S = Tok.getLoc();
3990 // Do immediates first, as we always parse those if we have a '#'.
3991 if (Parser.getTok().is(AsmToken::Hash) ||
3992 Parser.getTok().is(AsmToken::Dollar)) {
3993 Parser.Lex(); // Eat '#' or '$'.
3994 // Explicitly look for a '-', as we need to encode negative zero
3996 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3997 const MCExpr *Offset;
3999 if (getParser().parseExpression(Offset, E))
4000 return MatchOperand_ParseFail;
4001 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4003 Error(S, "constant expression expected");
4004 return MatchOperand_ParseFail;
4006 // Negative zero is encoded as the flag value INT32_MIN.
4007 int32_t Val = CE->getValue();
4008 if (isNegative && Val == 0)
4012 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4014 return MatchOperand_Success;
4018 bool haveEaten = false;
4020 if (Tok.is(AsmToken::Plus)) {
4021 Parser.Lex(); // Eat the '+' token.
4023 } else if (Tok.is(AsmToken::Minus)) {
4024 Parser.Lex(); // Eat the '-' token.
4029 Tok = Parser.getTok();
4030 int Reg = tryParseRegister();
4033 return MatchOperand_NoMatch;
4034 Error(Tok.getLoc(), "register expected");
4035 return MatchOperand_ParseFail;
4038 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4039 0, S, Tok.getEndLoc()));
4041 return MatchOperand_Success;
4044 /// Convert parsed operands to MCInst. Needed here because this instruction
4045 /// only has two register operands, but multiplication is commutative so
4046 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4048 cvtThumbMultiply(MCInst &Inst,
4049 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4050 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4051 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4052 // If we have a three-operand form, make sure to set Rn to be the operand
4053 // that isn't the same as Rd.
4055 if (Operands.size() == 6 &&
4056 ((ARMOperand*)Operands[4])->getReg() ==
4057 ((ARMOperand*)Operands[3])->getReg())
4059 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4060 Inst.addOperand(Inst.getOperand(0));
4061 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4064 /// Parse an ARM memory expression, return false if successful else return true
4065 /// or an error. The first token must be a '[' when called.
4067 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4069 assert(Parser.getTok().is(AsmToken::LBrac) &&
4070 "Token is not a Left Bracket");
4071 S = Parser.getTok().getLoc();
4072 Parser.Lex(); // Eat left bracket token.
4074 const AsmToken &BaseRegTok = Parser.getTok();
4075 int BaseRegNum = tryParseRegister();
4076 if (BaseRegNum == -1)
4077 return Error(BaseRegTok.getLoc(), "register expected");
4079 // The next token must either be a comma, a colon or a closing bracket.
4080 const AsmToken &Tok = Parser.getTok();
4081 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4082 !Tok.is(AsmToken::RBrac))
4083 return Error(Tok.getLoc(), "malformed memory operand");
4085 if (Tok.is(AsmToken::RBrac)) {
4086 E = Tok.getEndLoc();
4087 Parser.Lex(); // Eat right bracket token.
4089 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4090 0, 0, false, S, E));
4092 // If there's a pre-indexing writeback marker, '!', just add it as a token
4093 // operand. It's rather odd, but syntactically valid.
4094 if (Parser.getTok().is(AsmToken::Exclaim)) {
4095 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4096 Parser.Lex(); // Eat the '!'.
4102 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4103 "Lost colon or comma in memory operand?!");
4104 if (Tok.is(AsmToken::Comma)) {
4105 Parser.Lex(); // Eat the comma.
4108 // If we have a ':', it's an alignment specifier.
4109 if (Parser.getTok().is(AsmToken::Colon)) {
4110 Parser.Lex(); // Eat the ':'.
4111 E = Parser.getTok().getLoc();
4114 if (getParser().parseExpression(Expr))
4117 // The expression has to be a constant. Memory references with relocations
4118 // don't come through here, as they use the <label> forms of the relevant
4120 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4122 return Error (E, "constant expression expected");
4125 switch (CE->getValue()) {
4128 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4129 case 16: Align = 2; break;
4130 case 32: Align = 4; break;
4131 case 64: Align = 8; break;
4132 case 128: Align = 16; break;
4133 case 256: Align = 32; break;
4136 // Now we should have the closing ']'
4137 if (Parser.getTok().isNot(AsmToken::RBrac))
4138 return Error(Parser.getTok().getLoc(), "']' expected");
4139 E = Parser.getTok().getEndLoc();
4140 Parser.Lex(); // Eat right bracket token.
4142 // Don't worry about range checking the value here. That's handled by
4143 // the is*() predicates.
4144 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4145 ARM_AM::no_shift, 0, Align,
4148 // If there's a pre-indexing writeback marker, '!', just add it as a token
4150 if (Parser.getTok().is(AsmToken::Exclaim)) {
4151 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4152 Parser.Lex(); // Eat the '!'.
4158 // If we have a '#', it's an immediate offset, else assume it's a register
4159 // offset. Be friendly and also accept a plain integer (without a leading
4160 // hash) for gas compatibility.
4161 if (Parser.getTok().is(AsmToken::Hash) ||
4162 Parser.getTok().is(AsmToken::Dollar) ||
4163 Parser.getTok().is(AsmToken::Integer)) {
4164 if (Parser.getTok().isNot(AsmToken::Integer))
4165 Parser.Lex(); // Eat '#' or '$'.
4166 E = Parser.getTok().getLoc();
4168 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4169 const MCExpr *Offset;
4170 if (getParser().parseExpression(Offset))
4173 // The expression has to be a constant. Memory references with relocations
4174 // don't come through here, as they use the <label> forms of the relevant
4176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4178 return Error (E, "constant expression expected");
4180 // If the constant was #-0, represent it as INT32_MIN.
4181 int32_t Val = CE->getValue();
4182 if (isNegative && Val == 0)
4183 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4185 // Now we should have the closing ']'
4186 if (Parser.getTok().isNot(AsmToken::RBrac))
4187 return Error(Parser.getTok().getLoc(), "']' expected");
4188 E = Parser.getTok().getEndLoc();
4189 Parser.Lex(); // Eat right bracket token.
4191 // Don't worry about range checking the value here. That's handled by
4192 // the is*() predicates.
4193 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4194 ARM_AM::no_shift, 0, 0,
4197 // If there's a pre-indexing writeback marker, '!', just add it as a token
4199 if (Parser.getTok().is(AsmToken::Exclaim)) {
4200 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4201 Parser.Lex(); // Eat the '!'.
4207 // The register offset is optionally preceded by a '+' or '-'
4208 bool isNegative = false;
4209 if (Parser.getTok().is(AsmToken::Minus)) {
4211 Parser.Lex(); // Eat the '-'.
4212 } else if (Parser.getTok().is(AsmToken::Plus)) {
4214 Parser.Lex(); // Eat the '+'.
4217 E = Parser.getTok().getLoc();
4218 int OffsetRegNum = tryParseRegister();
4219 if (OffsetRegNum == -1)
4220 return Error(E, "register expected");
4222 // If there's a shift operator, handle it.
4223 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4224 unsigned ShiftImm = 0;
4225 if (Parser.getTok().is(AsmToken::Comma)) {
4226 Parser.Lex(); // Eat the ','.
4227 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4231 // Now we should have the closing ']'
4232 if (Parser.getTok().isNot(AsmToken::RBrac))
4233 return Error(Parser.getTok().getLoc(), "']' expected");
4234 E = Parser.getTok().getEndLoc();
4235 Parser.Lex(); // Eat right bracket token.
4237 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4238 ShiftType, ShiftImm, 0, isNegative,
4241 // If there's a pre-indexing writeback marker, '!', just add it as a token
4243 if (Parser.getTok().is(AsmToken::Exclaim)) {
4244 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4245 Parser.Lex(); // Eat the '!'.
4251 /// parseMemRegOffsetShift - one of these two:
4252 /// ( lsl | lsr | asr | ror ) , # shift_amount
4254 /// return true if it parses a shift otherwise it returns false.
4255 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4257 SMLoc Loc = Parser.getTok().getLoc();
4258 const AsmToken &Tok = Parser.getTok();
4259 if (Tok.isNot(AsmToken::Identifier))
4261 StringRef ShiftName = Tok.getString();
4262 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4263 ShiftName == "asl" || ShiftName == "ASL")
4265 else if (ShiftName == "lsr" || ShiftName == "LSR")
4267 else if (ShiftName == "asr" || ShiftName == "ASR")
4269 else if (ShiftName == "ror" || ShiftName == "ROR")
4271 else if (ShiftName == "rrx" || ShiftName == "RRX")
4274 return Error(Loc, "illegal shift operator");
4275 Parser.Lex(); // Eat shift type token.
4277 // rrx stands alone.
4279 if (St != ARM_AM::rrx) {
4280 Loc = Parser.getTok().getLoc();
4281 // A '#' and a shift amount.
4282 const AsmToken &HashTok = Parser.getTok();
4283 if (HashTok.isNot(AsmToken::Hash) &&
4284 HashTok.isNot(AsmToken::Dollar))
4285 return Error(HashTok.getLoc(), "'#' expected");
4286 Parser.Lex(); // Eat hash token.
4289 if (getParser().parseExpression(Expr))
4291 // Range check the immediate.
4292 // lsl, ror: 0 <= imm <= 31
4293 // lsr, asr: 0 <= imm <= 32
4294 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4296 return Error(Loc, "shift amount must be an immediate");
4297 int64_t Imm = CE->getValue();
4299 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4300 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4301 return Error(Loc, "immediate shift value out of range");
4302 // If <ShiftTy> #0, turn it into a no_shift.
4305 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4314 /// parseFPImm - A floating point immediate expression operand.
4315 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4316 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4317 // Anything that can accept a floating point constant as an operand
4318 // needs to go through here, as the regular parseExpression is
4321 // This routine still creates a generic Immediate operand, containing
4322 // a bitcast of the 64-bit floating point value. The various operands
4323 // that accept floats can check whether the value is valid for them
4324 // via the standard is*() predicates.
4326 SMLoc S = Parser.getTok().getLoc();
4328 if (Parser.getTok().isNot(AsmToken::Hash) &&
4329 Parser.getTok().isNot(AsmToken::Dollar))
4330 return MatchOperand_NoMatch;
4332 // Disambiguate the VMOV forms that can accept an FP immediate.
4333 // vmov.f32 <sreg>, #imm
4334 // vmov.f64 <dreg>, #imm
4335 // vmov.f32 <dreg>, #imm @ vector f32x2
4336 // vmov.f32 <qreg>, #imm @ vector f32x4
4338 // There are also the NEON VMOV instructions which expect an
4339 // integer constant. Make sure we don't try to parse an FPImm
4341 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4342 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4343 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4344 TyOp->getToken() != ".f64"))
4345 return MatchOperand_NoMatch;
4347 Parser.Lex(); // Eat '#' or '$'.
4349 // Handle negation, as that still comes through as a separate token.
4350 bool isNegative = false;
4351 if (Parser.getTok().is(AsmToken::Minus)) {
4355 const AsmToken &Tok = Parser.getTok();
4356 SMLoc Loc = Tok.getLoc();
4357 if (Tok.is(AsmToken::Real)) {
4358 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4359 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4360 // If we had a '-' in front, toggle the sign bit.
4361 IntVal ^= (uint64_t)isNegative << 31;
4362 Parser.Lex(); // Eat the token.
4363 Operands.push_back(ARMOperand::CreateImm(
4364 MCConstantExpr::Create(IntVal, getContext()),
4365 S, Parser.getTok().getLoc()));
4366 return MatchOperand_Success;
4368 // Also handle plain integers. Instructions which allow floating point
4369 // immediates also allow a raw encoded 8-bit value.
4370 if (Tok.is(AsmToken::Integer)) {
4371 int64_t Val = Tok.getIntVal();
4372 Parser.Lex(); // Eat the token.
4373 if (Val > 255 || Val < 0) {
4374 Error(Loc, "encoded floating point value out of range");
4375 return MatchOperand_ParseFail;
4377 double RealVal = ARM_AM::getFPImmFloat(Val);
4378 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4379 Operands.push_back(ARMOperand::CreateImm(
4380 MCConstantExpr::Create(Val, getContext()), S,
4381 Parser.getTok().getLoc()));
4382 return MatchOperand_Success;
4385 Error(Loc, "invalid floating point immediate");
4386 return MatchOperand_ParseFail;
4389 /// Parse a arm instruction operand. For now this parses the operand regardless
4390 /// of the mnemonic.
4391 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4392 StringRef Mnemonic) {
4395 // Check if the current operand has a custom associated parser, if so, try to
4396 // custom parse the operand, or fallback to the general approach.
4397 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4398 if (ResTy == MatchOperand_Success)
4400 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4401 // there was a match, but an error occurred, in which case, just return that
4402 // the operand parsing failed.
4403 if (ResTy == MatchOperand_ParseFail)
4406 switch (getLexer().getKind()) {
4408 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4410 case AsmToken::Identifier: {
4411 // If we've seen a branch mnemonic, the next operand must be a label. This
4412 // is true even if the label is a register name. So "br r1" means branch to
4414 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4416 if (!tryParseRegisterWithWriteBack(Operands))
4418 int Res = tryParseShiftRegister(Operands);
4419 if (Res == 0) // success
4421 else if (Res == -1) // irrecoverable error
4423 // If this is VMRS, check for the apsr_nzcv operand.
4424 if (Mnemonic == "vmrs" &&
4425 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4426 S = Parser.getTok().getLoc();
4428 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4433 // Fall though for the Identifier case that is not a register or a
4436 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4437 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4438 case AsmToken::String: // quoted label names.
4439 case AsmToken::Dot: { // . as a branch target
4440 // This was not a register so parse other operands that start with an
4441 // identifier (like labels) as expressions and create them as immediates.
4442 const MCExpr *IdVal;
4443 S = Parser.getTok().getLoc();
4444 if (getParser().parseExpression(IdVal))
4446 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4447 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4450 case AsmToken::LBrac:
4451 return parseMemory(Operands);
4452 case AsmToken::LCurly:
4453 return parseRegisterList(Operands);
4454 case AsmToken::Dollar:
4455 case AsmToken::Hash: {
4456 // #42 -> immediate.
4457 S = Parser.getTok().getLoc();
4460 if (Parser.getTok().isNot(AsmToken::Colon)) {
4461 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4462 const MCExpr *ImmVal;
4463 if (getParser().parseExpression(ImmVal))
4465 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4467 int32_t Val = CE->getValue();
4468 if (isNegative && Val == 0)
4469 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4471 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4472 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4474 // There can be a trailing '!' on operands that we want as a separate
4475 // '!' Token operand. Handle that here. For example, the compatibilty
4476 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4477 if (Parser.getTok().is(AsmToken::Exclaim)) {
4478 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4479 Parser.getTok().getLoc()));
4480 Parser.Lex(); // Eat exclaim token
4484 // w/ a ':' after the '#', it's just like a plain ':'.
4487 case AsmToken::Colon: {
4488 // ":lower16:" and ":upper16:" expression prefixes
4489 // FIXME: Check it's an expression prefix,
4490 // e.g. (FOO - :lower16:BAR) isn't legal.
4491 ARMMCExpr::VariantKind RefKind;
4492 if (parsePrefix(RefKind))
4495 const MCExpr *SubExprVal;
4496 if (getParser().parseExpression(SubExprVal))
4499 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4501 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4502 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4508 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4509 // :lower16: and :upper16:.
4510 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4511 RefKind = ARMMCExpr::VK_ARM_None;
4513 // :lower16: and :upper16: modifiers
4514 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4515 Parser.Lex(); // Eat ':'
4517 if (getLexer().isNot(AsmToken::Identifier)) {
4518 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4522 StringRef IDVal = Parser.getTok().getIdentifier();
4523 if (IDVal == "lower16") {
4524 RefKind = ARMMCExpr::VK_ARM_LO16;
4525 } else if (IDVal == "upper16") {
4526 RefKind = ARMMCExpr::VK_ARM_HI16;
4528 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4533 if (getLexer().isNot(AsmToken::Colon)) {
4534 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4537 Parser.Lex(); // Eat the last ':'
4541 /// \brief Given a mnemonic, split out possible predication code and carry
4542 /// setting letters to form a canonical mnemonic and flags.
4544 // FIXME: Would be nice to autogen this.
4545 // FIXME: This is a bit of a maze of special cases.
4546 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4547 unsigned &PredicationCode,
4549 unsigned &ProcessorIMod,
4550 StringRef &ITMask) {
4551 PredicationCode = ARMCC::AL;
4552 CarrySetting = false;
4555 // Ignore some mnemonics we know aren't predicated forms.
4557 // FIXME: Would be nice to autogen this.
4558 if ((Mnemonic == "movs" && isThumb()) ||
4559 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4560 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4561 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4562 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4563 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
4564 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4565 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4566 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4567 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
4568 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4569 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4570 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
4573 // First, split out any predication code. Ignore mnemonics we know aren't
4574 // predicated but do have a carry-set and so weren't caught above.
4575 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4576 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4577 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4578 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4579 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4580 .Case("eq", ARMCC::EQ)
4581 .Case("ne", ARMCC::NE)
4582 .Case("hs", ARMCC::HS)
4583 .Case("cs", ARMCC::HS)
4584 .Case("lo", ARMCC::LO)
4585 .Case("cc", ARMCC::LO)
4586 .Case("mi", ARMCC::MI)
4587 .Case("pl", ARMCC::PL)
4588 .Case("vs", ARMCC::VS)
4589 .Case("vc", ARMCC::VC)
4590 .Case("hi", ARMCC::HI)
4591 .Case("ls", ARMCC::LS)
4592 .Case("ge", ARMCC::GE)
4593 .Case("lt", ARMCC::LT)
4594 .Case("gt", ARMCC::GT)
4595 .Case("le", ARMCC::LE)
4596 .Case("al", ARMCC::AL)
4599 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4600 PredicationCode = CC;
4604 // Next, determine if we have a carry setting bit. We explicitly ignore all
4605 // the instructions we know end in 's'.
4606 if (Mnemonic.endswith("s") &&
4607 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4608 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4609 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4610 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4611 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4612 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4613 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4614 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4615 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4616 (Mnemonic == "movs" && isThumb()))) {
4617 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4618 CarrySetting = true;
4621 // The "cps" instruction can have a interrupt mode operand which is glued into
4622 // the mnemonic. Check if this is the case, split it and parse the imod op
4623 if (Mnemonic.startswith("cps")) {
4624 // Split out any imod code.
4626 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4627 .Case("ie", ARM_PROC::IE)
4628 .Case("id", ARM_PROC::ID)
4631 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4632 ProcessorIMod = IMod;
4636 // The "it" instruction has the condition mask on the end of the mnemonic.
4637 if (Mnemonic.startswith("it")) {
4638 ITMask = Mnemonic.slice(2, Mnemonic.size());
4639 Mnemonic = Mnemonic.slice(0, 2);
4645 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4646 /// inclusion of carry set or predication code operands.
4648 // FIXME: It would be nice to autogen this.
4650 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
4651 bool &CanAcceptPredicationCode) {
4652 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4653 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4654 Mnemonic == "add" || Mnemonic == "adc" ||
4655 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4656 Mnemonic == "orr" || Mnemonic == "mvn" ||
4657 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4658 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4659 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4660 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4661 Mnemonic == "mla" || Mnemonic == "smlal" ||
4662 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4663 CanAcceptCarrySet = true;
4665 CanAcceptCarrySet = false;
4667 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4668 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4669 Mnemonic == "trap" || Mnemonic == "setend" ||
4670 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4671 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
4672 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4673 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4674 Mnemonic == "vrintm") {
4675 // These mnemonics are never predicable
4676 CanAcceptPredicationCode = false;
4677 } else if (!isThumb()) {
4678 // Some instructions are only predicable in Thumb mode
4679 CanAcceptPredicationCode
4680 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4681 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4682 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4683 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4684 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4685 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4686 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4687 } else if (isThumbOne()) {
4688 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4690 CanAcceptPredicationCode = true;
4693 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4694 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4695 // FIXME: This is all horribly hacky. We really need a better way to deal
4696 // with optional operands like this in the matcher table.
4698 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4699 // another does not. Specifically, the MOVW instruction does not. So we
4700 // special case it here and remove the defaulted (non-setting) cc_out
4701 // operand if that's the instruction we're trying to match.
4703 // We do this as post-processing of the explicit operands rather than just
4704 // conditionally adding the cc_out in the first place because we need
4705 // to check the type of the parsed immediate operand.
4706 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4707 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4708 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4709 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4712 // Register-register 'add' for thumb does not have a cc_out operand
4713 // when there are only two register operands.
4714 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4715 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4716 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4717 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4719 // Register-register 'add' for thumb does not have a cc_out operand
4720 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4721 // have to check the immediate range here since Thumb2 has a variant
4722 // that can handle a different range and has a cc_out operand.
4723 if (((isThumb() && Mnemonic == "add") ||
4724 (isThumbTwo() && Mnemonic == "sub")) &&
4725 Operands.size() == 6 &&
4726 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4727 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4728 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4729 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4730 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4731 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4733 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4734 // imm0_4095 variant. That's the least-preferred variant when
4735 // selecting via the generic "add" mnemonic, so to know that we
4736 // should remove the cc_out operand, we have to explicitly check that
4737 // it's not one of the other variants. Ugh.
4738 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4739 Operands.size() == 6 &&
4740 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4741 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4742 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4743 // Nest conditions rather than one big 'if' statement for readability.
4745 // If both registers are low, we're in an IT block, and the immediate is
4746 // in range, we should use encoding T1 instead, which has a cc_out.
4748 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4749 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4750 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4752 // Check against T3. If the second register is the PC, this is an
4753 // alternate form of ADR, which uses encoding T4, so check for that too.
4754 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4755 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4758 // Otherwise, we use encoding T4, which does not have a cc_out
4763 // The thumb2 multiply instruction doesn't have a CCOut register, so
4764 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4765 // use the 16-bit encoding or not.
4766 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4767 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4768 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4769 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4770 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4771 // If the registers aren't low regs, the destination reg isn't the
4772 // same as one of the source regs, or the cc_out operand is zero
4773 // outside of an IT block, we have to use the 32-bit encoding, so
4774 // remove the cc_out operand.
4775 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4776 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4777 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4779 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4780 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4781 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4782 static_cast<ARMOperand*>(Operands[4])->getReg())))
4785 // Also check the 'mul' syntax variant that doesn't specify an explicit
4786 // destination register.
4787 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4788 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4789 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4790 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4791 // If the registers aren't low regs or the cc_out operand is zero
4792 // outside of an IT block, we have to use the 32-bit encoding, so
4793 // remove the cc_out operand.
4794 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4795 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4801 // Register-register 'add/sub' for thumb does not have a cc_out operand
4802 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4803 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4804 // right, this will result in better diagnostics (which operand is off)
4806 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4807 (Operands.size() == 5 || Operands.size() == 6) &&
4808 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4809 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4810 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4811 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4812 (Operands.size() == 6 &&
4813 static_cast<ARMOperand*>(Operands[5])->isImm())))
4819 bool ARMAsmParser::shouldOmitPredicateOperand(
4820 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4821 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4822 unsigned RegIdx = 3;
4823 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4824 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4825 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4826 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4829 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4830 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4831 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4832 ARMMCRegisterClasses[ARM::QPRRegClassID]
4833 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4839 static bool isDataTypeToken(StringRef Tok) {
4840 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4841 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4842 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4843 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4844 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4845 Tok == ".f" || Tok == ".d";
4848 // FIXME: This bit should probably be handled via an explicit match class
4849 // in the .td files that matches the suffix instead of having it be
4850 // a literal string token the way it is now.
4851 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4852 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4854 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4855 unsigned VariantID);
4856 /// Parse an arm instruction mnemonic followed by its operands.
4857 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4859 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4860 // Apply mnemonic aliases before doing anything else, as the destination
4861 // mnemnonic may include suffices and we want to handle them normally.
4862 // The generic tblgen'erated code does this later, at the start of
4863 // MatchInstructionImpl(), but that's too late for aliases that include
4864 // any sort of suffix.
4865 unsigned AvailableFeatures = getAvailableFeatures();
4866 unsigned AssemblerDialect = getParser().getAssemblerDialect();
4867 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
4869 // First check for the ARM-specific .req directive.
4870 if (Parser.getTok().is(AsmToken::Identifier) &&
4871 Parser.getTok().getIdentifier() == ".req") {
4872 parseDirectiveReq(Name, NameLoc);
4873 // We always return 'error' for this, as we're done with this
4874 // statement and don't need to match the 'instruction."
4878 // Create the leading tokens for the mnemonic, split by '.' characters.
4879 size_t Start = 0, Next = Name.find('.');
4880 StringRef Mnemonic = Name.slice(Start, Next);
4882 // Split out the predication code and carry setting flag from the mnemonic.
4883 unsigned PredicationCode;
4884 unsigned ProcessorIMod;
4887 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
4888 ProcessorIMod, ITMask);
4890 // In Thumb1, only the branch (B) instruction can be predicated.
4891 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4892 Parser.eatToEndOfStatement();
4893 return Error(NameLoc, "conditional execution not supported in Thumb1");
4896 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4898 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4899 // is the mask as it will be for the IT encoding if the conditional
4900 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4901 // where the conditional bit0 is zero, the instruction post-processing
4902 // will adjust the mask accordingly.
4903 if (Mnemonic == "it") {
4904 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4905 if (ITMask.size() > 3) {
4906 Parser.eatToEndOfStatement();
4907 return Error(Loc, "too many conditions on IT instruction");
4910 for (unsigned i = ITMask.size(); i != 0; --i) {
4911 char pos = ITMask[i - 1];
4912 if (pos != 't' && pos != 'e') {
4913 Parser.eatToEndOfStatement();
4914 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
4917 if (ITMask[i - 1] == 't')
4920 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
4923 // FIXME: This is all a pretty gross hack. We should automatically handle
4924 // optional operands like this via tblgen.
4926 // Next, add the CCOut and ConditionCode operands, if needed.
4928 // For mnemonics which can ever incorporate a carry setting bit or predication
4929 // code, our matching model involves us always generating CCOut and
4930 // ConditionCode operands to match the mnemonic "as written" and then we let
4931 // the matcher deal with finding the right instruction or generating an
4932 // appropriate error.
4933 bool CanAcceptCarrySet, CanAcceptPredicationCode;
4934 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
4936 // If we had a carry-set on an instruction that can't do that, issue an
4938 if (!CanAcceptCarrySet && CarrySetting) {
4939 Parser.eatToEndOfStatement();
4940 return Error(NameLoc, "instruction '" + Mnemonic +
4941 "' can not set flags, but 's' suffix specified");
4943 // If we had a predication code on an instruction that can't do that, issue an
4945 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
4946 Parser.eatToEndOfStatement();
4947 return Error(NameLoc, "instruction '" + Mnemonic +
4948 "' is not predicable, but condition code specified");
4951 // Add the carry setting operand, if necessary.
4952 if (CanAcceptCarrySet) {
4953 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
4954 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
4958 // Add the predication code operand, if necessary.
4959 if (CanAcceptPredicationCode) {
4960 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
4962 Operands.push_back(ARMOperand::CreateCondCode(
4963 ARMCC::CondCodes(PredicationCode), Loc));
4966 // Add the processor imod operand, if necessary.
4967 if (ProcessorIMod) {
4968 Operands.push_back(ARMOperand::CreateImm(
4969 MCConstantExpr::Create(ProcessorIMod, getContext()),
4973 // Add the remaining tokens in the mnemonic.
4974 while (Next != StringRef::npos) {
4976 Next = Name.find('.', Start + 1);
4977 StringRef ExtraToken = Name.slice(Start, Next);
4979 // Some NEON instructions have an optional datatype suffix that is
4980 // completely ignored. Check for that.
4981 if (isDataTypeToken(ExtraToken) &&
4982 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
4985 // For for ARM mode generate an error if the .n qualifier is used.
4986 if (ExtraToken == ".n" && !isThumb()) {
4987 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
4988 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
4992 // The .n qualifier is always discarded as that is what the tables
4993 // and matcher expect. In ARM mode the .w qualifier has no effect,
4994 // so discard it to avoid errors that can be caused by the matcher.
4995 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
4996 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
4997 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5001 // Read the remaining operands.
5002 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5003 // Read the first operand.
5004 if (parseOperand(Operands, Mnemonic)) {
5005 Parser.eatToEndOfStatement();
5009 while (getLexer().is(AsmToken::Comma)) {
5010 Parser.Lex(); // Eat the comma.
5012 // Parse and remember the operand.
5013 if (parseOperand(Operands, Mnemonic)) {
5014 Parser.eatToEndOfStatement();
5020 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5021 SMLoc Loc = getLexer().getLoc();
5022 Parser.eatToEndOfStatement();
5023 return Error(Loc, "unexpected token in argument list");
5026 Parser.Lex(); // Consume the EndOfStatement
5028 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5029 // do and don't have a cc_out optional-def operand. With some spot-checks
5030 // of the operand list, we can figure out which variant we're trying to
5031 // parse and adjust accordingly before actually matching. We shouldn't ever
5032 // try to remove a cc_out operand that was explicitly set on the the
5033 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5034 // table driven matcher doesn't fit well with the ARM instruction set.
5035 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5036 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5037 Operands.erase(Operands.begin() + 1);
5041 // Some instructions have the same mnemonic, but don't always
5042 // have a predicate. Distinguish them here and delete the
5043 // predicate if needed.
5044 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5045 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5046 Operands.erase(Operands.begin() + 1);
5050 // ARM mode 'blx' need special handling, as the register operand version
5051 // is predicable, but the label operand version is not. So, we can't rely
5052 // on the Mnemonic based checking to correctly figure out when to put
5053 // a k_CondCode operand in the list. If we're trying to match the label
5054 // version, remove the k_CondCode operand here.
5055 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5056 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5057 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5058 Operands.erase(Operands.begin() + 1);
5062 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5063 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5064 // a single GPRPair reg operand is used in the .td file to replace the two
5065 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5066 // expressed as a GPRPair, so we have to manually merge them.
5067 // FIXME: We would really like to be able to tablegen'erate this.
5068 if (!isThumb() && Operands.size() > 4 &&
5069 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5070 bool isLoad = (Mnemonic == "ldrexd");
5071 unsigned Idx = isLoad ? 2 : 3;
5072 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5073 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5075 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5076 // Adjust only if Op1 and Op2 are GPRs.
5077 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5078 MRC.contains(Op2->getReg())) {
5079 unsigned Reg1 = Op1->getReg();
5080 unsigned Reg2 = Op2->getReg();
5081 unsigned Rt = MRI->getEncodingValue(Reg1);
5082 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5084 // Rt2 must be Rt + 1 and Rt must be even.
5085 if (Rt + 1 != Rt2 || (Rt & 1)) {
5086 Error(Op2->getStartLoc(), isLoad ?
5087 "destination operands must be sequential" :
5088 "source operands must be sequential");
5091 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5092 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5093 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5094 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5095 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5104 // Validate context-sensitive operand constraints.
5106 // return 'true' if register list contains non-low GPR registers,
5107 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5108 // 'containsReg' to true.
5109 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5110 unsigned HiReg, bool &containsReg) {
5111 containsReg = false;
5112 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5113 unsigned OpReg = Inst.getOperand(i).getReg();
5116 // Anything other than a low register isn't legal here.
5117 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5123 // Check if the specified regisgter is in the register list of the inst,
5124 // starting at the indicated operand number.
5125 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5126 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5127 unsigned OpReg = Inst.getOperand(i).getReg();
5134 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5135 // the ARMInsts array) instead. Getting that here requires awkward
5136 // API changes, though. Better way?
5138 extern const MCInstrDesc ARMInsts[];
5140 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
5141 return ARMInsts[Opcode];
5144 // FIXME: We would really like to be able to tablegen'erate this.
5146 validateInstruction(MCInst &Inst,
5147 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5148 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
5149 SMLoc Loc = Operands[0]->getStartLoc();
5150 // Check the IT block state first.
5151 // NOTE: BKPT instruction has the interesting property of being
5152 // allowed in IT blocks, but not being predicable. It just always
5154 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5155 Inst.getOpcode() != ARM::BKPT) {
5157 if (ITState.FirstCond)
5158 ITState.FirstCond = false;
5160 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5161 // The instruction must be predicable.
5162 if (!MCID.isPredicable())
5163 return Error(Loc, "instructions in IT block must be predicable");
5164 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5165 unsigned ITCond = bit ? ITState.Cond :
5166 ARMCC::getOppositeCondition(ITState.Cond);
5167 if (Cond != ITCond) {
5168 // Find the condition code Operand to get its SMLoc information.
5170 for (unsigned i = 1; i < Operands.size(); ++i)
5171 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5172 CondLoc = Operands[i]->getStartLoc();
5173 return Error(CondLoc, "incorrect condition in IT block; got '" +
5174 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5175 "', but expected '" +
5176 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5178 // Check for non-'al' condition codes outside of the IT block.
5179 } else if (isThumbTwo() && MCID.isPredicable() &&
5180 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5181 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5182 Inst.getOpcode() != ARM::t2B)
5183 return Error(Loc, "predicated instructions must be in IT block");
5185 switch (Inst.getOpcode()) {
5188 case ARM::LDRD_POST: {
5189 // Rt2 must be Rt + 1.
5190 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5191 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5193 return Error(Operands[3]->getStartLoc(),
5194 "destination operands must be sequential");
5198 // Rt2 must be Rt + 1.
5199 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5200 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5202 return Error(Operands[3]->getStartLoc(),
5203 "source operands must be sequential");
5207 case ARM::STRD_POST: {
5208 // Rt2 must be Rt + 1.
5209 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5210 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5212 return Error(Operands[3]->getStartLoc(),
5213 "source operands must be sequential");
5218 // width must be in range [1, 32-lsb]
5219 unsigned lsb = Inst.getOperand(2).getImm();
5220 unsigned widthm1 = Inst.getOperand(3).getImm();
5221 if (widthm1 >= 32 - lsb)
5222 return Error(Operands[5]->getStartLoc(),
5223 "bitfield width must be in range [1,32-lsb]");
5227 // If we're parsing Thumb2, the .w variant is available and handles
5228 // most cases that are normally illegal for a Thumb1 LDM
5229 // instruction. We'll make the transformation in processInstruction()
5232 // Thumb LDM instructions are writeback iff the base register is not
5233 // in the register list.
5234 unsigned Rn = Inst.getOperand(0).getReg();
5235 bool hasWritebackToken =
5236 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5237 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5238 bool listContainsBase;
5239 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5240 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5241 "registers must be in range r0-r7");
5242 // If we should have writeback, then there should be a '!' token.
5243 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5244 return Error(Operands[2]->getStartLoc(),
5245 "writeback operator '!' expected");
5246 // If we should not have writeback, there must not be a '!'. This is
5247 // true even for the 32-bit wide encodings.
5248 if (listContainsBase && hasWritebackToken)
5249 return Error(Operands[3]->getStartLoc(),
5250 "writeback operator '!' not allowed when base register "
5251 "in register list");
5255 case ARM::t2LDMIA_UPD: {
5256 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5257 return Error(Operands[4]->getStartLoc(),
5258 "writeback operator '!' not allowed when base register "
5259 "in register list");
5263 // The second source operand must be the same register as the destination
5266 // In this case, we must directly check the parsed operands because the
5267 // cvtThumbMultiply() function is written in such a way that it guarantees
5268 // this first statement is always true for the new Inst. Essentially, the
5269 // destination is unconditionally copied into the second source operand
5270 // without checking to see if it matches what we actually parsed.
5271 if (Operands.size() == 6 &&
5272 (((ARMOperand*)Operands[3])->getReg() !=
5273 ((ARMOperand*)Operands[5])->getReg()) &&
5274 (((ARMOperand*)Operands[3])->getReg() !=
5275 ((ARMOperand*)Operands[4])->getReg())) {
5276 return Error(Operands[3]->getStartLoc(),
5277 "destination register must match source register");
5281 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5282 // so only issue a diagnostic for thumb1. The instructions will be
5283 // switched to the t2 encodings in processInstruction() if necessary.
5285 bool listContainsBase;
5286 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5288 return Error(Operands[2]->getStartLoc(),
5289 "registers must be in range r0-r7 or pc");
5293 bool listContainsBase;
5294 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5296 return Error(Operands[2]->getStartLoc(),
5297 "registers must be in range r0-r7 or lr");
5300 case ARM::tSTMIA_UPD: {
5301 bool listContainsBase;
5302 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5303 return Error(Operands[4]->getStartLoc(),
5304 "registers must be in range r0-r7");
5307 case ARM::tADDrSP: {
5308 // If the non-SP source operand and the destination operand are not the
5309 // same, we need thumb2 (for the wide encoding), or we have an error.
5310 if (!isThumbTwo() &&
5311 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5312 return Error(Operands[4]->getStartLoc(),
5313 "source register must be the same as destination");
5322 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5324 default: llvm_unreachable("unexpected opcode!");
5326 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5327 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5328 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5329 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5330 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5331 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5332 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5333 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5334 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5337 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5338 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5339 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5340 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5341 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5343 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5344 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5345 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5346 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5347 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5349 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5350 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5351 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5352 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5353 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5356 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5357 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5358 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5359 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5360 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5361 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5362 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5363 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5364 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5365 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5366 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5367 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5368 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5369 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5370 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5373 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5374 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5375 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5376 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5377 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5378 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5379 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5380 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5381 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5382 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5383 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5384 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5385 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5386 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5387 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5388 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5389 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5390 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5393 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5394 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5395 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5396 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5397 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5398 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5399 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5400 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5401 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5402 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5403 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5404 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5405 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5406 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5407 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5410 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5411 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5412 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5413 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5414 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5415 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5416 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5417 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5418 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5419 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5420 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5421 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5422 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5423 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5424 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5425 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5426 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5427 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5431 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5433 default: llvm_unreachable("unexpected opcode!");
5435 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5436 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5437 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5438 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5439 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5440 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5441 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5442 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5443 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5446 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5447 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5448 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5449 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5450 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5451 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5452 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5453 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5454 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5455 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5456 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5457 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5458 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5459 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5460 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5463 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5464 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5465 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5466 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5467 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5468 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5469 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5470 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5471 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5472 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5473 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5474 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5475 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5476 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5477 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5478 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5479 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5480 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5483 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5484 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5485 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5486 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5487 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5488 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5489 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5490 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5491 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5492 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5493 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5494 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5495 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5496 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5497 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5500 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5501 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5502 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5503 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5504 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5505 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5506 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5507 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5508 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5509 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5510 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5511 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5512 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5513 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5514 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5515 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5516 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5517 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5520 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5521 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5522 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5523 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5524 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5525 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5526 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5527 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5528 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5529 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5530 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5531 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5532 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5533 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5534 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5537 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5538 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5539 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5540 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5541 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5542 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5543 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5544 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5545 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5546 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5547 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5548 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5549 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5550 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5551 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5552 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5553 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5554 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5557 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5558 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5559 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5560 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5561 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5562 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5563 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5564 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5565 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5566 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5567 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5568 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5569 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5570 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5571 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5572 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5573 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5574 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5579 processInstruction(MCInst &Inst,
5580 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5581 switch (Inst.getOpcode()) {
5582 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5584 if (Inst.getOperand(1).getReg() != ARM::PC ||
5585 Inst.getOperand(5).getReg() != 0)
5588 TmpInst.setOpcode(ARM::ADR);
5589 TmpInst.addOperand(Inst.getOperand(0));
5590 TmpInst.addOperand(Inst.getOperand(2));
5591 TmpInst.addOperand(Inst.getOperand(3));
5592 TmpInst.addOperand(Inst.getOperand(4));
5596 // Aliases for alternate PC+imm syntax of LDR instructions.
5597 case ARM::t2LDRpcrel:
5598 // Select the narrow version if the immediate will fit.
5599 if (Inst.getOperand(1).getImm() > 0 &&
5600 Inst.getOperand(1).getImm() <= 0xff &&
5601 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5602 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
5603 Inst.setOpcode(ARM::tLDRpci);
5605 Inst.setOpcode(ARM::t2LDRpci);
5607 case ARM::t2LDRBpcrel:
5608 Inst.setOpcode(ARM::t2LDRBpci);
5610 case ARM::t2LDRHpcrel:
5611 Inst.setOpcode(ARM::t2LDRHpci);
5613 case ARM::t2LDRSBpcrel:
5614 Inst.setOpcode(ARM::t2LDRSBpci);
5616 case ARM::t2LDRSHpcrel:
5617 Inst.setOpcode(ARM::t2LDRSHpci);
5619 // Handle NEON VST complex aliases.
5620 case ARM::VST1LNdWB_register_Asm_8:
5621 case ARM::VST1LNdWB_register_Asm_16:
5622 case ARM::VST1LNdWB_register_Asm_32: {
5624 // Shuffle the operands around so the lane index operand is in the
5627 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5628 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5629 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5630 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5631 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5632 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5633 TmpInst.addOperand(Inst.getOperand(1)); // lane
5634 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5635 TmpInst.addOperand(Inst.getOperand(6));
5640 case ARM::VST2LNdWB_register_Asm_8:
5641 case ARM::VST2LNdWB_register_Asm_16:
5642 case ARM::VST2LNdWB_register_Asm_32:
5643 case ARM::VST2LNqWB_register_Asm_16:
5644 case ARM::VST2LNqWB_register_Asm_32: {
5646 // Shuffle the operands around so the lane index operand is in the
5649 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5650 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5651 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5652 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5653 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5654 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5657 TmpInst.addOperand(Inst.getOperand(1)); // lane
5658 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5659 TmpInst.addOperand(Inst.getOperand(6));
5664 case ARM::VST3LNdWB_register_Asm_8:
5665 case ARM::VST3LNdWB_register_Asm_16:
5666 case ARM::VST3LNdWB_register_Asm_32:
5667 case ARM::VST3LNqWB_register_Asm_16:
5668 case ARM::VST3LNqWB_register_Asm_32: {
5670 // Shuffle the operands around so the lane index operand is in the
5673 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5674 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5675 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5676 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5677 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5678 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5679 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5681 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5683 TmpInst.addOperand(Inst.getOperand(1)); // lane
5684 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5685 TmpInst.addOperand(Inst.getOperand(6));
5690 case ARM::VST4LNdWB_register_Asm_8:
5691 case ARM::VST4LNdWB_register_Asm_16:
5692 case ARM::VST4LNdWB_register_Asm_32:
5693 case ARM::VST4LNqWB_register_Asm_16:
5694 case ARM::VST4LNqWB_register_Asm_32: {
5696 // Shuffle the operands around so the lane index operand is in the
5699 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5700 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5701 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5702 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5703 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5704 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5705 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5707 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5709 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5711 TmpInst.addOperand(Inst.getOperand(1)); // lane
5712 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5713 TmpInst.addOperand(Inst.getOperand(6));
5718 case ARM::VST1LNdWB_fixed_Asm_8:
5719 case ARM::VST1LNdWB_fixed_Asm_16:
5720 case ARM::VST1LNdWB_fixed_Asm_32: {
5722 // Shuffle the operands around so the lane index operand is in the
5725 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5726 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5727 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5728 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5729 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5730 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5731 TmpInst.addOperand(Inst.getOperand(1)); // lane
5732 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5733 TmpInst.addOperand(Inst.getOperand(5));
5738 case ARM::VST2LNdWB_fixed_Asm_8:
5739 case ARM::VST2LNdWB_fixed_Asm_16:
5740 case ARM::VST2LNdWB_fixed_Asm_32:
5741 case ARM::VST2LNqWB_fixed_Asm_16:
5742 case ARM::VST2LNqWB_fixed_Asm_32: {
5744 // Shuffle the operands around so the lane index operand is in the
5747 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5748 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5749 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5750 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5751 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5752 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5755 TmpInst.addOperand(Inst.getOperand(1)); // lane
5756 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5757 TmpInst.addOperand(Inst.getOperand(5));
5762 case ARM::VST3LNdWB_fixed_Asm_8:
5763 case ARM::VST3LNdWB_fixed_Asm_16:
5764 case ARM::VST3LNdWB_fixed_Asm_32:
5765 case ARM::VST3LNqWB_fixed_Asm_16:
5766 case ARM::VST3LNqWB_fixed_Asm_32: {
5768 // Shuffle the operands around so the lane index operand is in the
5771 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5772 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5773 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5774 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5775 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5776 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5781 TmpInst.addOperand(Inst.getOperand(1)); // lane
5782 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5783 TmpInst.addOperand(Inst.getOperand(5));
5788 case ARM::VST4LNdWB_fixed_Asm_8:
5789 case ARM::VST4LNdWB_fixed_Asm_16:
5790 case ARM::VST4LNdWB_fixed_Asm_32:
5791 case ARM::VST4LNqWB_fixed_Asm_16:
5792 case ARM::VST4LNqWB_fixed_Asm_32: {
5794 // Shuffle the operands around so the lane index operand is in the
5797 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5798 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5799 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5800 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5801 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5802 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5803 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5805 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5807 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5809 TmpInst.addOperand(Inst.getOperand(1)); // lane
5810 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5811 TmpInst.addOperand(Inst.getOperand(5));
5816 case ARM::VST1LNdAsm_8:
5817 case ARM::VST1LNdAsm_16:
5818 case ARM::VST1LNdAsm_32: {
5820 // Shuffle the operands around so the lane index operand is in the
5823 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5824 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5825 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5826 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5827 TmpInst.addOperand(Inst.getOperand(1)); // lane
5828 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5829 TmpInst.addOperand(Inst.getOperand(5));
5834 case ARM::VST2LNdAsm_8:
5835 case ARM::VST2LNdAsm_16:
5836 case ARM::VST2LNdAsm_32:
5837 case ARM::VST2LNqAsm_16:
5838 case ARM::VST2LNqAsm_32: {
5840 // Shuffle the operands around so the lane index operand is in the
5843 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5844 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5845 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5846 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5847 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5849 TmpInst.addOperand(Inst.getOperand(1)); // lane
5850 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5851 TmpInst.addOperand(Inst.getOperand(5));
5856 case ARM::VST3LNdAsm_8:
5857 case ARM::VST3LNdAsm_16:
5858 case ARM::VST3LNdAsm_32:
5859 case ARM::VST3LNqAsm_16:
5860 case ARM::VST3LNqAsm_32: {
5862 // Shuffle the operands around so the lane index operand is in the
5865 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5866 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5867 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5868 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5869 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5871 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5873 TmpInst.addOperand(Inst.getOperand(1)); // lane
5874 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5875 TmpInst.addOperand(Inst.getOperand(5));
5880 case ARM::VST4LNdAsm_8:
5881 case ARM::VST4LNdAsm_16:
5882 case ARM::VST4LNdAsm_32:
5883 case ARM::VST4LNqAsm_16:
5884 case ARM::VST4LNqAsm_32: {
5886 // Shuffle the operands around so the lane index operand is in the
5889 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5890 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5891 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5892 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5893 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5895 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5897 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5899 TmpInst.addOperand(Inst.getOperand(1)); // lane
5900 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5901 TmpInst.addOperand(Inst.getOperand(5));
5906 // Handle NEON VLD complex aliases.
5907 case ARM::VLD1LNdWB_register_Asm_8:
5908 case ARM::VLD1LNdWB_register_Asm_16:
5909 case ARM::VLD1LNdWB_register_Asm_32: {
5911 // Shuffle the operands around so the lane index operand is in the
5914 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5915 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5916 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5917 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5918 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5919 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5920 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5921 TmpInst.addOperand(Inst.getOperand(1)); // lane
5922 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5923 TmpInst.addOperand(Inst.getOperand(6));
5928 case ARM::VLD2LNdWB_register_Asm_8:
5929 case ARM::VLD2LNdWB_register_Asm_16:
5930 case ARM::VLD2LNdWB_register_Asm_32:
5931 case ARM::VLD2LNqWB_register_Asm_16:
5932 case ARM::VLD2LNqWB_register_Asm_32: {
5934 // Shuffle the operands around so the lane index operand is in the
5937 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5938 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5939 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5941 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5942 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5943 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5944 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5945 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5946 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5948 TmpInst.addOperand(Inst.getOperand(1)); // lane
5949 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5950 TmpInst.addOperand(Inst.getOperand(6));
5955 case ARM::VLD3LNdWB_register_Asm_8:
5956 case ARM::VLD3LNdWB_register_Asm_16:
5957 case ARM::VLD3LNdWB_register_Asm_32:
5958 case ARM::VLD3LNqWB_register_Asm_16:
5959 case ARM::VLD3LNqWB_register_Asm_32: {
5961 // Shuffle the operands around so the lane index operand is in the
5964 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5965 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5966 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5968 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5970 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5971 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5972 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5973 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5974 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5975 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5977 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5979 TmpInst.addOperand(Inst.getOperand(1)); // lane
5980 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5981 TmpInst.addOperand(Inst.getOperand(6));
5986 case ARM::VLD4LNdWB_register_Asm_8:
5987 case ARM::VLD4LNdWB_register_Asm_16:
5988 case ARM::VLD4LNdWB_register_Asm_32:
5989 case ARM::VLD4LNqWB_register_Asm_16:
5990 case ARM::VLD4LNqWB_register_Asm_32: {
5992 // Shuffle the operands around so the lane index operand is in the
5995 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5996 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5997 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5999 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6001 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6003 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6004 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6005 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6006 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6007 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6008 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6010 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6012 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6014 TmpInst.addOperand(Inst.getOperand(1)); // lane
6015 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6016 TmpInst.addOperand(Inst.getOperand(6));
6021 case ARM::VLD1LNdWB_fixed_Asm_8:
6022 case ARM::VLD1LNdWB_fixed_Asm_16:
6023 case ARM::VLD1LNdWB_fixed_Asm_32: {
6025 // Shuffle the operands around so the lane index operand is in the
6028 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6029 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6030 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6031 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6032 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6033 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6034 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6035 TmpInst.addOperand(Inst.getOperand(1)); // lane
6036 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6037 TmpInst.addOperand(Inst.getOperand(5));
6042 case ARM::VLD2LNdWB_fixed_Asm_8:
6043 case ARM::VLD2LNdWB_fixed_Asm_16:
6044 case ARM::VLD2LNdWB_fixed_Asm_32:
6045 case ARM::VLD2LNqWB_fixed_Asm_16:
6046 case ARM::VLD2LNqWB_fixed_Asm_32: {
6048 // Shuffle the operands around so the lane index operand is in the
6051 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6052 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6053 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6055 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6056 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6057 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6058 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6059 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6060 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6062 TmpInst.addOperand(Inst.getOperand(1)); // lane
6063 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6064 TmpInst.addOperand(Inst.getOperand(5));
6069 case ARM::VLD3LNdWB_fixed_Asm_8:
6070 case ARM::VLD3LNdWB_fixed_Asm_16:
6071 case ARM::VLD3LNdWB_fixed_Asm_32:
6072 case ARM::VLD3LNqWB_fixed_Asm_16:
6073 case ARM::VLD3LNqWB_fixed_Asm_32: {
6075 // Shuffle the operands around so the lane index operand is in the
6078 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6079 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6082 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6084 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6085 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6086 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6087 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6088 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6089 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6091 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6093 TmpInst.addOperand(Inst.getOperand(1)); // lane
6094 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6095 TmpInst.addOperand(Inst.getOperand(5));
6100 case ARM::VLD4LNdWB_fixed_Asm_8:
6101 case ARM::VLD4LNdWB_fixed_Asm_16:
6102 case ARM::VLD4LNdWB_fixed_Asm_32:
6103 case ARM::VLD4LNqWB_fixed_Asm_16:
6104 case ARM::VLD4LNqWB_fixed_Asm_32: {
6106 // Shuffle the operands around so the lane index operand is in the
6109 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6110 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6111 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6113 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6115 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6117 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6118 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6119 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6120 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6121 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6122 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6124 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6126 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6128 TmpInst.addOperand(Inst.getOperand(1)); // lane
6129 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6130 TmpInst.addOperand(Inst.getOperand(5));
6135 case ARM::VLD1LNdAsm_8:
6136 case ARM::VLD1LNdAsm_16:
6137 case ARM::VLD1LNdAsm_32: {
6139 // Shuffle the operands around so the lane index operand is in the
6142 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6143 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6144 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6145 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6146 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6147 TmpInst.addOperand(Inst.getOperand(1)); // lane
6148 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6149 TmpInst.addOperand(Inst.getOperand(5));
6154 case ARM::VLD2LNdAsm_8:
6155 case ARM::VLD2LNdAsm_16:
6156 case ARM::VLD2LNdAsm_32:
6157 case ARM::VLD2LNqAsm_16:
6158 case ARM::VLD2LNqAsm_32: {
6160 // Shuffle the operands around so the lane index operand is in the
6163 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6164 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6165 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6167 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6168 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6169 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6170 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6172 TmpInst.addOperand(Inst.getOperand(1)); // lane
6173 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6174 TmpInst.addOperand(Inst.getOperand(5));
6179 case ARM::VLD3LNdAsm_8:
6180 case ARM::VLD3LNdAsm_16:
6181 case ARM::VLD3LNdAsm_32:
6182 case ARM::VLD3LNqAsm_16:
6183 case ARM::VLD3LNqAsm_32: {
6185 // Shuffle the operands around so the lane index operand is in the
6188 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6189 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6190 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6192 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6194 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6195 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6196 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6197 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6199 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6201 TmpInst.addOperand(Inst.getOperand(1)); // lane
6202 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6203 TmpInst.addOperand(Inst.getOperand(5));
6208 case ARM::VLD4LNdAsm_8:
6209 case ARM::VLD4LNdAsm_16:
6210 case ARM::VLD4LNdAsm_32:
6211 case ARM::VLD4LNqAsm_16:
6212 case ARM::VLD4LNqAsm_32: {
6214 // Shuffle the operands around so the lane index operand is in the
6217 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6218 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6219 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6221 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6223 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6225 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6226 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6227 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6228 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6230 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6232 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6234 TmpInst.addOperand(Inst.getOperand(1)); // lane
6235 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6236 TmpInst.addOperand(Inst.getOperand(5));
6241 // VLD3DUP single 3-element structure to all lanes instructions.
6242 case ARM::VLD3DUPdAsm_8:
6243 case ARM::VLD3DUPdAsm_16:
6244 case ARM::VLD3DUPdAsm_32:
6245 case ARM::VLD3DUPqAsm_8:
6246 case ARM::VLD3DUPqAsm_16:
6247 case ARM::VLD3DUPqAsm_32: {
6250 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6251 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6252 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6254 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6256 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6257 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6258 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6259 TmpInst.addOperand(Inst.getOperand(4));
6264 case ARM::VLD3DUPdWB_fixed_Asm_8:
6265 case ARM::VLD3DUPdWB_fixed_Asm_16:
6266 case ARM::VLD3DUPdWB_fixed_Asm_32:
6267 case ARM::VLD3DUPqWB_fixed_Asm_8:
6268 case ARM::VLD3DUPqWB_fixed_Asm_16:
6269 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6272 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6273 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6274 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6276 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6278 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6279 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6280 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6281 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6282 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6283 TmpInst.addOperand(Inst.getOperand(4));
6288 case ARM::VLD3DUPdWB_register_Asm_8:
6289 case ARM::VLD3DUPdWB_register_Asm_16:
6290 case ARM::VLD3DUPdWB_register_Asm_32:
6291 case ARM::VLD3DUPqWB_register_Asm_8:
6292 case ARM::VLD3DUPqWB_register_Asm_16:
6293 case ARM::VLD3DUPqWB_register_Asm_32: {
6296 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6297 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6298 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6302 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6303 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6304 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6305 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6306 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6307 TmpInst.addOperand(Inst.getOperand(5));
6312 // VLD3 multiple 3-element structure instructions.
6313 case ARM::VLD3dAsm_8:
6314 case ARM::VLD3dAsm_16:
6315 case ARM::VLD3dAsm_32:
6316 case ARM::VLD3qAsm_8:
6317 case ARM::VLD3qAsm_16:
6318 case ARM::VLD3qAsm_32: {
6321 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6322 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6323 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6325 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6327 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6328 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6329 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6330 TmpInst.addOperand(Inst.getOperand(4));
6335 case ARM::VLD3dWB_fixed_Asm_8:
6336 case ARM::VLD3dWB_fixed_Asm_16:
6337 case ARM::VLD3dWB_fixed_Asm_32:
6338 case ARM::VLD3qWB_fixed_Asm_8:
6339 case ARM::VLD3qWB_fixed_Asm_16:
6340 case ARM::VLD3qWB_fixed_Asm_32: {
6343 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6344 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6347 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6349 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6350 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6351 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6352 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6353 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6354 TmpInst.addOperand(Inst.getOperand(4));
6359 case ARM::VLD3dWB_register_Asm_8:
6360 case ARM::VLD3dWB_register_Asm_16:
6361 case ARM::VLD3dWB_register_Asm_32:
6362 case ARM::VLD3qWB_register_Asm_8:
6363 case ARM::VLD3qWB_register_Asm_16:
6364 case ARM::VLD3qWB_register_Asm_32: {
6367 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6368 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6369 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6371 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6373 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6374 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6375 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6376 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6377 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6378 TmpInst.addOperand(Inst.getOperand(5));
6383 // VLD4DUP single 3-element structure to all lanes instructions.
6384 case ARM::VLD4DUPdAsm_8:
6385 case ARM::VLD4DUPdAsm_16:
6386 case ARM::VLD4DUPdAsm_32:
6387 case ARM::VLD4DUPqAsm_8:
6388 case ARM::VLD4DUPqAsm_16:
6389 case ARM::VLD4DUPqAsm_32: {
6392 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6393 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6394 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6396 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6400 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6401 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6402 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6403 TmpInst.addOperand(Inst.getOperand(4));
6408 case ARM::VLD4DUPdWB_fixed_Asm_8:
6409 case ARM::VLD4DUPdWB_fixed_Asm_16:
6410 case ARM::VLD4DUPdWB_fixed_Asm_32:
6411 case ARM::VLD4DUPqWB_fixed_Asm_8:
6412 case ARM::VLD4DUPqWB_fixed_Asm_16:
6413 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6416 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6417 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6418 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6422 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6424 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6425 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6426 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6427 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6428 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6429 TmpInst.addOperand(Inst.getOperand(4));
6434 case ARM::VLD4DUPdWB_register_Asm_8:
6435 case ARM::VLD4DUPdWB_register_Asm_16:
6436 case ARM::VLD4DUPdWB_register_Asm_32:
6437 case ARM::VLD4DUPqWB_register_Asm_8:
6438 case ARM::VLD4DUPqWB_register_Asm_16:
6439 case ARM::VLD4DUPqWB_register_Asm_32: {
6442 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6443 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6444 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6446 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6448 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6450 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6451 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6452 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6453 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6454 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6455 TmpInst.addOperand(Inst.getOperand(5));
6460 // VLD4 multiple 4-element structure instructions.
6461 case ARM::VLD4dAsm_8:
6462 case ARM::VLD4dAsm_16:
6463 case ARM::VLD4dAsm_32:
6464 case ARM::VLD4qAsm_8:
6465 case ARM::VLD4qAsm_16:
6466 case ARM::VLD4qAsm_32: {
6469 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6470 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6477 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6478 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6479 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6480 TmpInst.addOperand(Inst.getOperand(4));
6485 case ARM::VLD4dWB_fixed_Asm_8:
6486 case ARM::VLD4dWB_fixed_Asm_16:
6487 case ARM::VLD4dWB_fixed_Asm_32:
6488 case ARM::VLD4qWB_fixed_Asm_8:
6489 case ARM::VLD4qWB_fixed_Asm_16:
6490 case ARM::VLD4qWB_fixed_Asm_32: {
6493 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6494 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6501 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6502 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6503 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6504 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6505 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6506 TmpInst.addOperand(Inst.getOperand(4));
6511 case ARM::VLD4dWB_register_Asm_8:
6512 case ARM::VLD4dWB_register_Asm_16:
6513 case ARM::VLD4dWB_register_Asm_32:
6514 case ARM::VLD4qWB_register_Asm_8:
6515 case ARM::VLD4qWB_register_Asm_16:
6516 case ARM::VLD4qWB_register_Asm_32: {
6519 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6520 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6521 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6523 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6525 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6527 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6528 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6529 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6530 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6531 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6532 TmpInst.addOperand(Inst.getOperand(5));
6537 // VST3 multiple 3-element structure instructions.
6538 case ARM::VST3dAsm_8:
6539 case ARM::VST3dAsm_16:
6540 case ARM::VST3dAsm_32:
6541 case ARM::VST3qAsm_8:
6542 case ARM::VST3qAsm_16:
6543 case ARM::VST3qAsm_32: {
6546 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6547 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6548 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6549 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6550 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6552 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6554 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6555 TmpInst.addOperand(Inst.getOperand(4));
6560 case ARM::VST3dWB_fixed_Asm_8:
6561 case ARM::VST3dWB_fixed_Asm_16:
6562 case ARM::VST3dWB_fixed_Asm_32:
6563 case ARM::VST3qWB_fixed_Asm_8:
6564 case ARM::VST3qWB_fixed_Asm_16:
6565 case ARM::VST3qWB_fixed_Asm_32: {
6568 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6569 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6570 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6571 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6572 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6573 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6574 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6578 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6579 TmpInst.addOperand(Inst.getOperand(4));
6584 case ARM::VST3dWB_register_Asm_8:
6585 case ARM::VST3dWB_register_Asm_16:
6586 case ARM::VST3dWB_register_Asm_32:
6587 case ARM::VST3qWB_register_Asm_8:
6588 case ARM::VST3qWB_register_Asm_16:
6589 case ARM::VST3qWB_register_Asm_32: {
6592 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6593 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6594 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6595 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6596 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6597 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6598 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6600 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6602 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6603 TmpInst.addOperand(Inst.getOperand(5));
6608 // VST4 multiple 3-element structure instructions.
6609 case ARM::VST4dAsm_8:
6610 case ARM::VST4dAsm_16:
6611 case ARM::VST4dAsm_32:
6612 case ARM::VST4qAsm_8:
6613 case ARM::VST4qAsm_16:
6614 case ARM::VST4qAsm_32: {
6617 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6618 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6619 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6620 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6625 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6627 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6628 TmpInst.addOperand(Inst.getOperand(4));
6633 case ARM::VST4dWB_fixed_Asm_8:
6634 case ARM::VST4dWB_fixed_Asm_16:
6635 case ARM::VST4dWB_fixed_Asm_32:
6636 case ARM::VST4qWB_fixed_Asm_8:
6637 case ARM::VST4qWB_fixed_Asm_16:
6638 case ARM::VST4qWB_fixed_Asm_32: {
6641 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6642 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6643 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6644 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6645 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6646 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6647 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6649 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6651 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6653 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6654 TmpInst.addOperand(Inst.getOperand(4));
6659 case ARM::VST4dWB_register_Asm_8:
6660 case ARM::VST4dWB_register_Asm_16:
6661 case ARM::VST4dWB_register_Asm_32:
6662 case ARM::VST4qWB_register_Asm_8:
6663 case ARM::VST4qWB_register_Asm_16:
6664 case ARM::VST4qWB_register_Asm_32: {
6667 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6668 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6669 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6670 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6671 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6672 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6673 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6675 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6677 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6679 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6680 TmpInst.addOperand(Inst.getOperand(5));
6685 // Handle encoding choice for the shift-immediate instructions.
6688 case ARM::t2ASRri: {
6689 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6690 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6691 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6692 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6693 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6695 switch (Inst.getOpcode()) {
6696 default: llvm_unreachable("unexpected opcode");
6697 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6698 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6699 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6701 // The Thumb1 operands aren't in the same order. Awesome, eh?
6703 TmpInst.setOpcode(NewOpc);
6704 TmpInst.addOperand(Inst.getOperand(0));
6705 TmpInst.addOperand(Inst.getOperand(5));
6706 TmpInst.addOperand(Inst.getOperand(1));
6707 TmpInst.addOperand(Inst.getOperand(2));
6708 TmpInst.addOperand(Inst.getOperand(3));
6709 TmpInst.addOperand(Inst.getOperand(4));
6716 // Handle the Thumb2 mode MOV complex aliases.
6718 case ARM::t2MOVSsr: {
6719 // Which instruction to expand to depends on the CCOut operand and
6720 // whether we're in an IT block if the register operands are low
6722 bool isNarrow = false;
6723 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6724 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6725 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6726 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6727 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6731 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6732 default: llvm_unreachable("unexpected opcode!");
6733 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6734 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6735 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6736 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6738 TmpInst.setOpcode(newOpc);
6739 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6741 TmpInst.addOperand(MCOperand::CreateReg(
6742 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6743 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6744 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6745 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6746 TmpInst.addOperand(Inst.getOperand(5));
6748 TmpInst.addOperand(MCOperand::CreateReg(
6749 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6754 case ARM::t2MOVSsi: {
6755 // Which instruction to expand to depends on the CCOut operand and
6756 // whether we're in an IT block if the register operands are low
6758 bool isNarrow = false;
6759 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6760 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6761 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6765 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6766 default: llvm_unreachable("unexpected opcode!");
6767 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6768 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6769 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6770 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
6771 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
6773 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6774 if (Amount == 32) Amount = 0;
6775 TmpInst.setOpcode(newOpc);
6776 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6778 TmpInst.addOperand(MCOperand::CreateReg(
6779 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6780 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6781 if (newOpc != ARM::t2RRX)
6782 TmpInst.addOperand(MCOperand::CreateImm(Amount));
6783 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6784 TmpInst.addOperand(Inst.getOperand(4));
6786 TmpInst.addOperand(MCOperand::CreateReg(
6787 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6791 // Handle the ARM mode MOV complex aliases.
6796 ARM_AM::ShiftOpc ShiftTy;
6797 switch(Inst.getOpcode()) {
6798 default: llvm_unreachable("unexpected opcode!");
6799 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6800 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6801 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6802 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6804 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6806 TmpInst.setOpcode(ARM::MOVsr);
6807 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6808 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6809 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6810 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6811 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6812 TmpInst.addOperand(Inst.getOperand(4));
6813 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6821 ARM_AM::ShiftOpc ShiftTy;
6822 switch(Inst.getOpcode()) {
6823 default: llvm_unreachable("unexpected opcode!");
6824 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6825 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6826 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6827 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6829 // A shift by zero is a plain MOVr, not a MOVsi.
6830 unsigned Amt = Inst.getOperand(2).getImm();
6831 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
6832 // A shift by 32 should be encoded as 0 when permitted
6833 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6835 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
6837 TmpInst.setOpcode(Opc);
6838 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6839 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6840 if (Opc == ARM::MOVsi)
6841 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6842 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6843 TmpInst.addOperand(Inst.getOperand(4));
6844 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6849 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6851 TmpInst.setOpcode(ARM::MOVsi);
6852 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6853 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6854 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6855 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6856 TmpInst.addOperand(Inst.getOperand(3));
6857 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6861 case ARM::t2LDMIA_UPD: {
6862 // If this is a load of a single register, then we should use
6863 // a post-indexed LDR instruction instead, per the ARM ARM.
6864 if (Inst.getNumOperands() != 5)
6867 TmpInst.setOpcode(ARM::t2LDR_POST);
6868 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6869 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6870 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6871 TmpInst.addOperand(MCOperand::CreateImm(4));
6872 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6873 TmpInst.addOperand(Inst.getOperand(3));
6877 case ARM::t2STMDB_UPD: {
6878 // If this is a store of a single register, then we should use
6879 // a pre-indexed STR instruction instead, per the ARM ARM.
6880 if (Inst.getNumOperands() != 5)
6883 TmpInst.setOpcode(ARM::t2STR_PRE);
6884 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6885 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6886 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6887 TmpInst.addOperand(MCOperand::CreateImm(-4));
6888 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6889 TmpInst.addOperand(Inst.getOperand(3));
6893 case ARM::LDMIA_UPD:
6894 // If this is a load of a single register via a 'pop', then we should use
6895 // a post-indexed LDR instruction instead, per the ARM ARM.
6896 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6897 Inst.getNumOperands() == 5) {
6899 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6900 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6901 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6902 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6903 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6904 TmpInst.addOperand(MCOperand::CreateImm(4));
6905 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6906 TmpInst.addOperand(Inst.getOperand(3));
6911 case ARM::STMDB_UPD:
6912 // If this is a store of a single register via a 'push', then we should use
6913 // a pre-indexed STR instruction instead, per the ARM ARM.
6914 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6915 Inst.getNumOperands() == 5) {
6917 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6918 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6919 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6920 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6921 TmpInst.addOperand(MCOperand::CreateImm(-4));
6922 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6923 TmpInst.addOperand(Inst.getOperand(3));
6927 case ARM::t2ADDri12:
6928 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6929 // mnemonic was used (not "addw"), encoding T3 is preferred.
6930 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6931 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6933 Inst.setOpcode(ARM::t2ADDri);
6934 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6936 case ARM::t2SUBri12:
6937 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6938 // mnemonic was used (not "subw"), encoding T3 is preferred.
6939 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6940 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6942 Inst.setOpcode(ARM::t2SUBri);
6943 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6946 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6947 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6948 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6949 // to encoding T1 if <Rd> is omitted."
6950 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
6951 Inst.setOpcode(ARM::tADDi3);
6956 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6957 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6958 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6959 // to encoding T1 if <Rd> is omitted."
6960 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
6961 Inst.setOpcode(ARM::tSUBi3);
6966 case ARM::t2SUBri: {
6967 // If the destination and first source operand are the same, and
6968 // the flags are compatible with the current IT status, use encoding T2
6969 // instead of T3. For compatibility with the system 'as'. Make sure the
6970 // wide encoding wasn't explicit.
6971 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
6972 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
6973 (unsigned)Inst.getOperand(2).getImm() > 255 ||
6974 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
6975 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
6976 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6977 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
6980 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
6981 ARM::tADDi8 : ARM::tSUBi8);
6982 TmpInst.addOperand(Inst.getOperand(0));
6983 TmpInst.addOperand(Inst.getOperand(5));
6984 TmpInst.addOperand(Inst.getOperand(0));
6985 TmpInst.addOperand(Inst.getOperand(2));
6986 TmpInst.addOperand(Inst.getOperand(3));
6987 TmpInst.addOperand(Inst.getOperand(4));
6991 case ARM::t2ADDrr: {
6992 // If the destination and first source operand are the same, and
6993 // there's no setting of the flags, use encoding T2 instead of T3.
6994 // Note that this is only for ADD, not SUB. This mirrors the system
6995 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
6996 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
6997 Inst.getOperand(5).getReg() != 0 ||
6998 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6999 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7002 TmpInst.setOpcode(ARM::tADDhirr);
7003 TmpInst.addOperand(Inst.getOperand(0));
7004 TmpInst.addOperand(Inst.getOperand(0));
7005 TmpInst.addOperand(Inst.getOperand(2));
7006 TmpInst.addOperand(Inst.getOperand(3));
7007 TmpInst.addOperand(Inst.getOperand(4));
7011 case ARM::tADDrSP: {
7012 // If the non-SP source operand and the destination operand are not the
7013 // same, we need to use the 32-bit encoding if it's available.
7014 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7015 Inst.setOpcode(ARM::t2ADDrr);
7016 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7022 // A Thumb conditional branch outside of an IT block is a tBcc.
7023 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7024 Inst.setOpcode(ARM::tBcc);
7029 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7030 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7031 Inst.setOpcode(ARM::t2Bcc);
7036 // If the conditional is AL or we're in an IT block, we really want t2B.
7037 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7038 Inst.setOpcode(ARM::t2B);
7043 // If the conditional is AL, we really want tB.
7044 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7045 Inst.setOpcode(ARM::tB);
7050 // If the register list contains any high registers, or if the writeback
7051 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7052 // instead if we're in Thumb2. Otherwise, this should have generated
7053 // an error in validateInstruction().
7054 unsigned Rn = Inst.getOperand(0).getReg();
7055 bool hasWritebackToken =
7056 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7057 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7058 bool listContainsBase;
7059 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7060 (!listContainsBase && !hasWritebackToken) ||
7061 (listContainsBase && hasWritebackToken)) {
7062 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7063 assert (isThumbTwo());
7064 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7065 // If we're switching to the updating version, we need to insert
7066 // the writeback tied operand.
7067 if (hasWritebackToken)
7068 Inst.insert(Inst.begin(),
7069 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7074 case ARM::tSTMIA_UPD: {
7075 // If the register list contains any high registers, we need to use
7076 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7077 // should have generated an error in validateInstruction().
7078 unsigned Rn = Inst.getOperand(0).getReg();
7079 bool listContainsBase;
7080 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7081 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7082 assert (isThumbTwo());
7083 Inst.setOpcode(ARM::t2STMIA_UPD);
7089 bool listContainsBase;
7090 // If the register list contains any high registers, we need to use
7091 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7092 // should have generated an error in validateInstruction().
7093 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7095 assert (isThumbTwo());
7096 Inst.setOpcode(ARM::t2LDMIA_UPD);
7097 // Add the base register and writeback operands.
7098 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7099 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7103 bool listContainsBase;
7104 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7106 assert (isThumbTwo());
7107 Inst.setOpcode(ARM::t2STMDB_UPD);
7108 // Add the base register and writeback operands.
7109 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7110 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7114 // If we can use the 16-bit encoding and the user didn't explicitly
7115 // request the 32-bit variant, transform it here.
7116 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7117 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7118 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7119 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7120 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7121 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7122 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7123 // The operands aren't in the same order for tMOVi8...
7125 TmpInst.setOpcode(ARM::tMOVi8);
7126 TmpInst.addOperand(Inst.getOperand(0));
7127 TmpInst.addOperand(Inst.getOperand(4));
7128 TmpInst.addOperand(Inst.getOperand(1));
7129 TmpInst.addOperand(Inst.getOperand(2));
7130 TmpInst.addOperand(Inst.getOperand(3));
7137 // If we can use the 16-bit encoding and the user didn't explicitly
7138 // request the 32-bit variant, transform it here.
7139 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7140 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7141 Inst.getOperand(2).getImm() == ARMCC::AL &&
7142 Inst.getOperand(4).getReg() == ARM::CPSR &&
7143 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7144 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7145 // The operands aren't the same for tMOV[S]r... (no cc_out)
7147 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7148 TmpInst.addOperand(Inst.getOperand(0));
7149 TmpInst.addOperand(Inst.getOperand(1));
7150 TmpInst.addOperand(Inst.getOperand(2));
7151 TmpInst.addOperand(Inst.getOperand(3));
7161 // If we can use the 16-bit encoding and the user didn't explicitly
7162 // request the 32-bit variant, transform it here.
7163 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7164 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7165 Inst.getOperand(2).getImm() == 0 &&
7166 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7167 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7169 switch (Inst.getOpcode()) {
7170 default: llvm_unreachable("Illegal opcode!");
7171 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7172 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7173 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7174 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7176 // The operands aren't the same for thumb1 (no rotate operand).
7178 TmpInst.setOpcode(NewOpc);
7179 TmpInst.addOperand(Inst.getOperand(0));
7180 TmpInst.addOperand(Inst.getOperand(1));
7181 TmpInst.addOperand(Inst.getOperand(3));
7182 TmpInst.addOperand(Inst.getOperand(4));
7189 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7190 // rrx shifts and asr/lsr of #32 is encoded as 0
7191 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7193 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7194 // Shifting by zero is accepted as a vanilla 'MOVr'
7196 TmpInst.setOpcode(ARM::MOVr);
7197 TmpInst.addOperand(Inst.getOperand(0));
7198 TmpInst.addOperand(Inst.getOperand(1));
7199 TmpInst.addOperand(Inst.getOperand(3));
7200 TmpInst.addOperand(Inst.getOperand(4));
7201 TmpInst.addOperand(Inst.getOperand(5));
7214 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7215 if (SOpc == ARM_AM::rrx) return false;
7216 switch (Inst.getOpcode()) {
7217 default: llvm_unreachable("unexpected opcode!");
7218 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7219 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7220 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7221 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7222 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7223 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7225 // If the shift is by zero, use the non-shifted instruction definition.
7226 // The exception is for right shifts, where 0 == 32
7227 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7228 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7230 TmpInst.setOpcode(newOpc);
7231 TmpInst.addOperand(Inst.getOperand(0));
7232 TmpInst.addOperand(Inst.getOperand(1));
7233 TmpInst.addOperand(Inst.getOperand(2));
7234 TmpInst.addOperand(Inst.getOperand(4));
7235 TmpInst.addOperand(Inst.getOperand(5));
7236 TmpInst.addOperand(Inst.getOperand(6));
7244 // The mask bits for all but the first condition are represented as
7245 // the low bit of the condition code value implies 't'. We currently
7246 // always have 1 implies 't', so XOR toggle the bits if the low bit
7247 // of the condition code is zero.
7248 MCOperand &MO = Inst.getOperand(1);
7249 unsigned Mask = MO.getImm();
7250 unsigned OrigMask = Mask;
7251 unsigned TZ = countTrailingZeros(Mask);
7252 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7253 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7254 Mask ^= (0xE << TZ) & 0xF;
7258 // Set up the IT block state according to the IT instruction we just
7260 assert(!inITBlock() && "nested IT blocks?!");
7261 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7262 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7263 ITState.CurPosition = 0;
7264 ITState.FirstCond = true;
7274 // Assemblers should use the narrow encodings of these instructions when permissible.
7275 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7276 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7277 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7278 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7279 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7280 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7281 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7283 switch (Inst.getOpcode()) {
7284 default: llvm_unreachable("unexpected opcode");
7285 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7286 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7287 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7288 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7289 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7290 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7293 TmpInst.setOpcode(NewOpc);
7294 TmpInst.addOperand(Inst.getOperand(0));
7295 TmpInst.addOperand(Inst.getOperand(5));
7296 TmpInst.addOperand(Inst.getOperand(1));
7297 TmpInst.addOperand(Inst.getOperand(2));
7298 TmpInst.addOperand(Inst.getOperand(3));
7299 TmpInst.addOperand(Inst.getOperand(4));
7310 // Assemblers should use the narrow encodings of these instructions when permissible.
7311 // These instructions are special in that they are commutable, so shorter encodings
7312 // are available more often.
7313 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7314 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7315 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7316 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7317 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7318 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7319 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7320 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7322 switch (Inst.getOpcode()) {
7323 default: llvm_unreachable("unexpected opcode");
7324 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7325 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7326 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7327 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7330 TmpInst.setOpcode(NewOpc);
7331 TmpInst.addOperand(Inst.getOperand(0));
7332 TmpInst.addOperand(Inst.getOperand(5));
7333 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7334 TmpInst.addOperand(Inst.getOperand(1));
7335 TmpInst.addOperand(Inst.getOperand(2));
7337 TmpInst.addOperand(Inst.getOperand(2));
7338 TmpInst.addOperand(Inst.getOperand(1));
7340 TmpInst.addOperand(Inst.getOperand(3));
7341 TmpInst.addOperand(Inst.getOperand(4));
7351 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7352 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7353 // suffix depending on whether they're in an IT block or not.
7354 unsigned Opc = Inst.getOpcode();
7355 const MCInstrDesc &MCID = getInstDesc(Opc);
7356 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7357 assert(MCID.hasOptionalDef() &&
7358 "optionally flag setting instruction missing optional def operand");
7359 assert(MCID.NumOperands == Inst.getNumOperands() &&
7360 "operand count mismatch!");
7361 // Find the optional-def operand (cc_out).
7364 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7367 // If we're parsing Thumb1, reject it completely.
7368 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7369 return Match_MnemonicFail;
7370 // If we're parsing Thumb2, which form is legal depends on whether we're
7372 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7374 return Match_RequiresITBlock;
7375 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7377 return Match_RequiresNotITBlock;
7379 // Some high-register supporting Thumb1 encodings only allow both registers
7380 // to be from r0-r7 when in Thumb2.
7381 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7382 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7383 isARMLowRegister(Inst.getOperand(2).getReg()))
7384 return Match_RequiresThumb2;
7385 // Others only require ARMv6 or later.
7386 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7387 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7388 isARMLowRegister(Inst.getOperand(1).getReg()))
7389 return Match_RequiresV6;
7390 return Match_Success;
7393 static const char *getSubtargetFeatureName(unsigned Val);
7395 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7396 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7397 MCStreamer &Out, unsigned &ErrorInfo,
7398 bool MatchingInlineAsm) {
7400 unsigned MatchResult;
7402 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7404 switch (MatchResult) {
7407 // Context sensitive operand constraints aren't handled by the matcher,
7408 // so check them here.
7409 if (validateInstruction(Inst, Operands)) {
7410 // Still progress the IT block, otherwise one wrong condition causes
7411 // nasty cascading errors.
7412 forwardITPosition();
7416 // Some instructions need post-processing to, for example, tweak which
7417 // encoding is selected. Loop on it while changes happen so the
7418 // individual transformations can chain off each other. E.g.,
7419 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7420 while (processInstruction(Inst, Operands))
7423 // Only move forward at the very end so that everything in validate
7424 // and process gets a consistent answer about whether we're in an IT
7426 forwardITPosition();
7428 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7429 // doesn't actually encode.
7430 if (Inst.getOpcode() == ARM::ITasm)
7434 Out.EmitInstruction(Inst);
7436 case Match_MissingFeature: {
7437 assert(ErrorInfo && "Unknown missing feature!");
7438 // Special case the error message for the very common case where only
7439 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7440 std::string Msg = "instruction requires:";
7442 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7443 if (ErrorInfo & Mask) {
7445 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7449 return Error(IDLoc, Msg);
7451 case Match_InvalidOperand: {
7452 SMLoc ErrorLoc = IDLoc;
7453 if (ErrorInfo != ~0U) {
7454 if (ErrorInfo >= Operands.size())
7455 return Error(IDLoc, "too few operands for instruction");
7457 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7458 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7461 return Error(ErrorLoc, "invalid operand for instruction");
7463 case Match_MnemonicFail:
7464 return Error(IDLoc, "invalid instruction",
7465 ((ARMOperand*)Operands[0])->getLocRange());
7466 case Match_RequiresNotITBlock:
7467 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7468 case Match_RequiresITBlock:
7469 return Error(IDLoc, "instruction only valid inside IT block");
7470 case Match_RequiresV6:
7471 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7472 case Match_RequiresThumb2:
7473 return Error(IDLoc, "instruction variant requires Thumb2");
7474 case Match_ImmRange0_4: {
7475 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7476 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7477 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7479 case Match_ImmRange0_15: {
7480 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7481 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7482 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7486 llvm_unreachable("Implement any new match types added!");
7489 /// parseDirective parses the arm specific directives
7490 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7491 StringRef IDVal = DirectiveID.getIdentifier();
7492 if (IDVal == ".word")
7493 return parseDirectiveWord(4, DirectiveID.getLoc());
7494 else if (IDVal == ".thumb")
7495 return parseDirectiveThumb(DirectiveID.getLoc());
7496 else if (IDVal == ".arm")
7497 return parseDirectiveARM(DirectiveID.getLoc());
7498 else if (IDVal == ".thumb_func")
7499 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7500 else if (IDVal == ".code")
7501 return parseDirectiveCode(DirectiveID.getLoc());
7502 else if (IDVal == ".syntax")
7503 return parseDirectiveSyntax(DirectiveID.getLoc());
7504 else if (IDVal == ".unreq")
7505 return parseDirectiveUnreq(DirectiveID.getLoc());
7506 else if (IDVal == ".arch")
7507 return parseDirectiveArch(DirectiveID.getLoc());
7508 else if (IDVal == ".eabi_attribute")
7509 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7510 else if (IDVal == ".fnstart")
7511 return parseDirectiveFnStart(DirectiveID.getLoc());
7512 else if (IDVal == ".fnend")
7513 return parseDirectiveFnEnd(DirectiveID.getLoc());
7514 else if (IDVal == ".cantunwind")
7515 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7516 else if (IDVal == ".personality")
7517 return parseDirectivePersonality(DirectiveID.getLoc());
7518 else if (IDVal == ".handlerdata")
7519 return parseDirectiveHandlerData(DirectiveID.getLoc());
7520 else if (IDVal == ".setfp")
7521 return parseDirectiveSetFP(DirectiveID.getLoc());
7522 else if (IDVal == ".pad")
7523 return parseDirectivePad(DirectiveID.getLoc());
7524 else if (IDVal == ".save")
7525 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7526 else if (IDVal == ".vsave")
7527 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7531 /// parseDirectiveWord
7532 /// ::= .word [ expression (, expression)* ]
7533 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7534 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7536 const MCExpr *Value;
7537 if (getParser().parseExpression(Value))
7540 getParser().getStreamer().EmitValue(Value, Size);
7542 if (getLexer().is(AsmToken::EndOfStatement))
7545 // FIXME: Improve diagnostic.
7546 if (getLexer().isNot(AsmToken::Comma))
7547 return Error(L, "unexpected token in directive");
7556 /// parseDirectiveThumb
7558 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7559 if (getLexer().isNot(AsmToken::EndOfStatement))
7560 return Error(L, "unexpected token in directive");
7564 return Error(L, "target does not support Thumb mode");
7568 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7572 /// parseDirectiveARM
7574 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7575 if (getLexer().isNot(AsmToken::EndOfStatement))
7576 return Error(L, "unexpected token in directive");
7580 return Error(L, "target does not support ARM mode");
7584 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7588 /// parseDirectiveThumbFunc
7589 /// ::= .thumbfunc symbol_name
7590 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7591 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7592 bool isMachO = MAI->hasSubsectionsViaSymbols();
7594 bool needFuncName = true;
7596 // Darwin asm has (optionally) function name after .thumb_func direction
7599 const AsmToken &Tok = Parser.getTok();
7600 if (Tok.isNot(AsmToken::EndOfStatement)) {
7601 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7602 return Error(L, "unexpected token in .thumb_func directive");
7603 Name = Tok.getIdentifier();
7604 Parser.Lex(); // Consume the identifier token.
7605 needFuncName = false;
7609 if (getLexer().isNot(AsmToken::EndOfStatement))
7610 return Error(L, "unexpected token in directive");
7612 // Eat the end of statement and any blank lines that follow.
7613 while (getLexer().is(AsmToken::EndOfStatement))
7616 // FIXME: assuming function name will be the line following .thumb_func
7617 // We really should be checking the next symbol definition even if there's
7618 // stuff in between.
7620 Name = Parser.getTok().getIdentifier();
7623 // Mark symbol as a thumb symbol.
7624 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7625 getParser().getStreamer().EmitThumbFunc(Func);
7629 /// parseDirectiveSyntax
7630 /// ::= .syntax unified | divided
7631 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7632 const AsmToken &Tok = Parser.getTok();
7633 if (Tok.isNot(AsmToken::Identifier))
7634 return Error(L, "unexpected token in .syntax directive");
7635 StringRef Mode = Tok.getString();
7636 if (Mode == "unified" || Mode == "UNIFIED")
7638 else if (Mode == "divided" || Mode == "DIVIDED")
7639 return Error(L, "'.syntax divided' arm asssembly not supported");
7641 return Error(L, "unrecognized syntax mode in .syntax directive");
7643 if (getLexer().isNot(AsmToken::EndOfStatement))
7644 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7647 // TODO tell the MC streamer the mode
7648 // getParser().getStreamer().Emit???();
7652 /// parseDirectiveCode
7653 /// ::= .code 16 | 32
7654 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7655 const AsmToken &Tok = Parser.getTok();
7656 if (Tok.isNot(AsmToken::Integer))
7657 return Error(L, "unexpected token in .code directive");
7658 int64_t Val = Parser.getTok().getIntVal();
7664 return Error(L, "invalid operand to .code directive");
7666 if (getLexer().isNot(AsmToken::EndOfStatement))
7667 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7672 return Error(L, "target does not support Thumb mode");
7676 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7679 return Error(L, "target does not support ARM mode");
7683 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7689 /// parseDirectiveReq
7690 /// ::= name .req registername
7691 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7692 Parser.Lex(); // Eat the '.req' token.
7694 SMLoc SRegLoc, ERegLoc;
7695 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7696 Parser.eatToEndOfStatement();
7697 return Error(SRegLoc, "register name expected");
7700 // Shouldn't be anything else.
7701 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7702 Parser.eatToEndOfStatement();
7703 return Error(Parser.getTok().getLoc(),
7704 "unexpected input in .req directive.");
7707 Parser.Lex(); // Consume the EndOfStatement
7709 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7710 return Error(SRegLoc, "redefinition of '" + Name +
7711 "' does not match original.");
7716 /// parseDirectiveUneq
7717 /// ::= .unreq registername
7718 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7719 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7720 Parser.eatToEndOfStatement();
7721 return Error(L, "unexpected input in .unreq directive.");
7723 RegisterReqs.erase(Parser.getTok().getIdentifier());
7724 Parser.Lex(); // Eat the identifier.
7728 /// parseDirectiveArch
7730 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7734 /// parseDirectiveEabiAttr
7735 /// ::= .eabi_attribute int, int
7736 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7740 /// parseDirectiveFnStart
7742 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7743 if (FnStartLoc.isValid()) {
7744 Error(L, ".fnstart starts before the end of previous one");
7745 Error(FnStartLoc, "previous .fnstart starts here");
7750 getParser().getStreamer().EmitFnStart();
7754 /// parseDirectiveFnEnd
7756 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7757 // Check the ordering of unwind directives
7758 if (!FnStartLoc.isValid())
7759 return Error(L, ".fnstart must precede .fnend directive");
7761 // Reset the unwind directives parser state
7762 resetUnwindDirectiveParserState();
7764 getParser().getStreamer().EmitFnEnd();
7768 /// parseDirectiveCantUnwind
7770 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7771 // Check the ordering of unwind directives
7773 if (!FnStartLoc.isValid())
7774 return Error(L, ".fnstart must precede .cantunwind directive");
7775 if (HandlerDataLoc.isValid()) {
7776 Error(L, ".cantunwind can't be used with .handlerdata directive");
7777 Error(HandlerDataLoc, ".handlerdata was specified here");
7780 if (PersonalityLoc.isValid()) {
7781 Error(L, ".cantunwind can't be used with .personality directive");
7782 Error(PersonalityLoc, ".personality was specified here");
7786 getParser().getStreamer().EmitCantUnwind();
7790 /// parseDirectivePersonality
7791 /// ::= .personality name
7792 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7793 // Check the ordering of unwind directives
7795 if (!FnStartLoc.isValid())
7796 return Error(L, ".fnstart must precede .personality directive");
7797 if (CantUnwindLoc.isValid()) {
7798 Error(L, ".personality can't be used with .cantunwind directive");
7799 Error(CantUnwindLoc, ".cantunwind was specified here");
7802 if (HandlerDataLoc.isValid()) {
7803 Error(L, ".personality must precede .handlerdata directive");
7804 Error(HandlerDataLoc, ".handlerdata was specified here");
7808 // Parse the name of the personality routine
7809 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7810 Parser.eatToEndOfStatement();
7811 return Error(L, "unexpected input in .personality directive.");
7813 StringRef Name(Parser.getTok().getIdentifier());
7816 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
7817 getParser().getStreamer().EmitPersonality(PR);
7821 /// parseDirectiveHandlerData
7822 /// ::= .handlerdata
7823 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
7824 // Check the ordering of unwind directives
7826 if (!FnStartLoc.isValid())
7827 return Error(L, ".fnstart must precede .personality directive");
7828 if (CantUnwindLoc.isValid()) {
7829 Error(L, ".handlerdata can't be used with .cantunwind directive");
7830 Error(CantUnwindLoc, ".cantunwind was specified here");
7834 getParser().getStreamer().EmitHandlerData();
7838 /// parseDirectiveSetFP
7839 /// ::= .setfp fpreg, spreg [, offset]
7840 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
7841 // Check the ordering of unwind directives
7842 if (!FnStartLoc.isValid())
7843 return Error(L, ".fnstart must precede .setfp directive");
7844 if (HandlerDataLoc.isValid())
7845 return Error(L, ".setfp must precede .handlerdata directive");
7848 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
7849 int NewFPReg = tryParseRegister();
7851 return Error(NewFPRegLoc, "frame pointer register expected");
7854 if (!Parser.getTok().is(AsmToken::Comma))
7855 return Error(Parser.getTok().getLoc(), "comma expected");
7856 Parser.Lex(); // skip comma
7859 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
7860 int NewSPReg = tryParseRegister();
7862 return Error(NewSPRegLoc, "stack pointer register expected");
7864 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
7865 return Error(NewSPRegLoc,
7866 "register should be either $sp or the latest fp register");
7868 // Update the frame pointer register
7873 if (Parser.getTok().is(AsmToken::Comma)) {
7874 Parser.Lex(); // skip comma
7876 if (Parser.getTok().isNot(AsmToken::Hash) &&
7877 Parser.getTok().isNot(AsmToken::Dollar)) {
7878 return Error(Parser.getTok().getLoc(), "'#' expected");
7880 Parser.Lex(); // skip hash token.
7882 const MCExpr *OffsetExpr;
7883 SMLoc ExLoc = Parser.getTok().getLoc();
7885 if (getParser().parseExpression(OffsetExpr, EndLoc))
7886 return Error(ExLoc, "malformed setfp offset");
7887 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
7889 return Error(ExLoc, "setfp offset must be an immediate");
7891 Offset = CE->getValue();
7894 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
7895 static_cast<unsigned>(NewSPReg),
7902 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
7903 // Check the ordering of unwind directives
7904 if (!FnStartLoc.isValid())
7905 return Error(L, ".fnstart must precede .pad directive");
7906 if (HandlerDataLoc.isValid())
7907 return Error(L, ".pad must precede .handlerdata directive");
7910 if (Parser.getTok().isNot(AsmToken::Hash) &&
7911 Parser.getTok().isNot(AsmToken::Dollar)) {
7912 return Error(Parser.getTok().getLoc(), "'#' expected");
7914 Parser.Lex(); // skip hash token.
7916 const MCExpr *OffsetExpr;
7917 SMLoc ExLoc = Parser.getTok().getLoc();
7919 if (getParser().parseExpression(OffsetExpr, EndLoc))
7920 return Error(ExLoc, "malformed pad offset");
7921 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
7923 return Error(ExLoc, "pad offset must be an immediate");
7925 getParser().getStreamer().EmitPad(CE->getValue());
7929 /// parseDirectiveRegSave
7930 /// ::= .save { registers }
7931 /// ::= .vsave { registers }
7932 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
7933 // Check the ordering of unwind directives
7934 if (!FnStartLoc.isValid())
7935 return Error(L, ".fnstart must precede .save or .vsave directives");
7936 if (HandlerDataLoc.isValid())
7937 return Error(L, ".save or .vsave must precede .handlerdata directive");
7939 // Parse the register list
7940 SmallVector<MCParsedAsmOperand*, 1> Operands;
7941 if (parseRegisterList(Operands))
7943 ARMOperand *Op = (ARMOperand*)Operands[0];
7944 if (!IsVector && !Op->isRegList())
7945 return Error(L, ".save expects GPR registers");
7946 if (IsVector && !Op->isDPRRegList())
7947 return Error(L, ".vsave expects DPR registers");
7949 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
7953 /// Force static initialization.
7954 extern "C" void LLVMInitializeARMAsmParser() {
7955 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7956 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
7959 #define GET_REGISTER_MATCHER
7960 #define GET_SUBTARGET_FEATURE_NAME
7961 #define GET_MATCHER_IMPLEMENTATION
7962 #include "ARMGenAsmMatcher.inc"
7964 // Define this matcher function after the auto-generated include so we
7965 // have the match class enum definitions.
7966 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
7968 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
7969 // If the kind is a token for a literal immediate, check if our asm
7970 // operand matches. This is for InstAliases which have a fixed-value
7971 // immediate in the syntax.
7972 if (Kind == MCK__35_0 && Op->isImm()) {
7973 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
7975 return Match_InvalidOperand;
7976 if (CE->getValue() == 0)
7977 return Match_Success;
7979 return Match_InvalidOperand;