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/MCInstrInfo.h"
28 #include "llvm/MC/MCParser/MCAsmLexer.h"
29 #include "llvm/MC/MCParser/MCAsmParser.h"
30 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
31 #include "llvm/MC/MCRegisterInfo.h"
32 #include "llvm/MC/MCStreamer.h"
33 #include "llvm/MC/MCSubtargetInfo.h"
34 #include "llvm/Support/ELF.h"
35 #include "llvm/Support/MathExtras.h"
36 #include "llvm/Support/SourceMgr.h"
37 #include "llvm/Support/TargetRegistry.h"
38 #include "llvm/Support/raw_ostream.h"
46 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
48 class ARMAsmParser : public MCTargetAsmParser {
51 const MCInstrInfo &MII;
52 const MCRegisterInfo *MRI;
54 // Unwind directives state
60 void resetUnwindDirectiveParserState() {
62 CantUnwindLoc = SMLoc();
63 PersonalityLoc = SMLoc();
64 HandlerDataLoc = SMLoc();
68 // Map of register aliases registers via the .req directive.
69 StringMap<unsigned> RegisterReqs;
72 ARMCC::CondCodes Cond; // Condition for IT block.
73 unsigned Mask:4; // Condition mask for instructions.
74 // Starting at first 1 (from lsb).
75 // '1' condition as indicated in IT.
76 // '0' inverse of condition (else).
77 // Count of instructions in IT block is
78 // 4 - trailingzeroes(mask)
80 bool FirstCond; // Explicit flag for when we're parsing the
81 // First instruction in the IT block. It's
82 // implied in the mask, so needs special
85 unsigned CurPosition; // Current position in parsing of IT
86 // block. In range [0,3]. Initialized
87 // according to count of instructions in block.
88 // ~0U if no active IT block.
90 bool inITBlock() { return ITState.CurPosition != ~0U;}
91 void forwardITPosition() {
92 if (!inITBlock()) return;
93 // Move to the next instruction in the IT block, if there is one. If not,
94 // mark the block as done.
95 unsigned TZ = countTrailingZeros(ITState.Mask);
96 if (++ITState.CurPosition == 5 - TZ)
97 ITState.CurPosition = ~0U; // Done with the IT block after this.
101 MCAsmParser &getParser() const { return Parser; }
102 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
104 bool Warning(SMLoc L, const Twine &Msg,
105 ArrayRef<SMRange> Ranges = None) {
106 return Parser.Warning(L, Msg, Ranges);
108 bool Error(SMLoc L, const Twine &Msg,
109 ArrayRef<SMRange> Ranges = None) {
110 return Parser.Error(L, Msg, Ranges);
113 int tryParseRegister();
114 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
115 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
116 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
117 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
118 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
119 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
120 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
121 unsigned &ShiftAmount);
122 bool parseDirectiveWord(unsigned Size, SMLoc L);
123 bool parseDirectiveThumb(SMLoc L);
124 bool parseDirectiveARM(SMLoc L);
125 bool parseDirectiveThumbFunc(SMLoc L);
126 bool parseDirectiveCode(SMLoc L);
127 bool parseDirectiveSyntax(SMLoc L);
128 bool parseDirectiveReq(StringRef Name, SMLoc L);
129 bool parseDirectiveUnreq(SMLoc L);
130 bool parseDirectiveArch(SMLoc L);
131 bool parseDirectiveEabiAttr(SMLoc L);
132 bool parseDirectiveFnStart(SMLoc L);
133 bool parseDirectiveFnEnd(SMLoc L);
134 bool parseDirectiveCantUnwind(SMLoc L);
135 bool parseDirectivePersonality(SMLoc L);
136 bool parseDirectiveHandlerData(SMLoc L);
137 bool parseDirectiveSetFP(SMLoc L);
138 bool parseDirectivePad(SMLoc L);
139 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
141 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
142 bool &CarrySetting, unsigned &ProcessorIMod,
144 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
145 bool &CanAcceptCarrySet,
146 bool &CanAcceptPredicationCode);
148 bool isThumb() const {
149 // FIXME: Can tablegen auto-generate this?
150 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
152 bool isThumbOne() const {
153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
155 bool isThumbTwo() const {
156 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
158 bool hasThumb() const {
159 return STI.getFeatureBits() & ARM::HasV4TOps;
161 bool hasV6Ops() const {
162 return STI.getFeatureBits() & ARM::HasV6Ops;
164 bool hasV7Ops() const {
165 return STI.getFeatureBits() & ARM::HasV7Ops;
167 bool hasV8Ops() const {
168 return STI.getFeatureBits() & ARM::HasV8Ops;
170 bool hasARM() const {
171 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
175 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
176 setAvailableFeatures(FB);
178 bool isMClass() const {
179 return STI.getFeatureBits() & ARM::FeatureMClass;
182 /// @name Auto-generated Match Functions
185 #define GET_ASSEMBLER_HEADER
186 #include "ARMGenAsmMatcher.inc"
190 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
191 OperandMatchResultTy parseCoprocNumOperand(
192 SmallVectorImpl<MCParsedAsmOperand*>&);
193 OperandMatchResultTy parseCoprocRegOperand(
194 SmallVectorImpl<MCParsedAsmOperand*>&);
195 OperandMatchResultTy parseCoprocOptionOperand(
196 SmallVectorImpl<MCParsedAsmOperand*>&);
197 OperandMatchResultTy parseMemBarrierOptOperand(
198 SmallVectorImpl<MCParsedAsmOperand*>&);
199 OperandMatchResultTy parseInstSyncBarrierOptOperand(
200 SmallVectorImpl<MCParsedAsmOperand*>&);
201 OperandMatchResultTy parseProcIFlagsOperand(
202 SmallVectorImpl<MCParsedAsmOperand*>&);
203 OperandMatchResultTy parseMSRMaskOperand(
204 SmallVectorImpl<MCParsedAsmOperand*>&);
205 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
206 StringRef Op, int Low, int High);
207 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
208 return parsePKHImm(O, "lsl", 0, 31);
210 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
211 return parsePKHImm(O, "asr", 1, 32);
213 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
214 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
215 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
216 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
217 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
218 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
219 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
220 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
221 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
224 // Asm Match Converter Methods
225 void cvtThumbMultiply(MCInst &Inst,
226 const SmallVectorImpl<MCParsedAsmOperand*> &);
227 void cvtThumbBranches(MCInst &Inst,
228 const SmallVectorImpl<MCParsedAsmOperand*> &);
230 bool validateInstruction(MCInst &Inst,
231 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
232 bool processInstruction(MCInst &Inst,
233 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
234 bool shouldOmitCCOutOperand(StringRef Mnemonic,
235 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
236 bool shouldOmitPredicateOperand(StringRef Mnemonic,
237 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
239 enum ARMMatchResultTy {
240 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
241 Match_RequiresNotITBlock,
243 Match_RequiresThumb2,
244 #define GET_OPERAND_DIAGNOSTIC_TYPES
245 #include "ARMGenAsmMatcher.inc"
249 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
250 const MCInstrInfo &MII)
251 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
252 MCAsmParserExtension::Initialize(_Parser);
254 // Cache the MCRegisterInfo.
255 MRI = getContext().getRegisterInfo();
257 // Initialize the set of available features.
258 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
260 // Not in an ITBlock to start with.
261 ITState.CurPosition = ~0U;
263 // Set ELF header flags.
264 // FIXME: This should eventually end up somewhere else where more
265 // intelligent flag decisions can be made. For now we are just maintaining
266 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
267 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
268 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
271 // Implementation of the MCTargetAsmParser interface:
272 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
273 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
275 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
276 bool ParseDirective(AsmToken DirectiveID);
278 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
279 unsigned checkTargetMatchPredicate(MCInst &Inst);
281 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
282 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
283 MCStreamer &Out, unsigned &ErrorInfo,
284 bool MatchingInlineAsm);
286 } // end anonymous namespace
290 /// ARMOperand - Instances of this class represent a parsed ARM machine
292 class ARMOperand : public MCParsedAsmOperand {
302 k_InstSyncBarrierOpt,
313 k_VectorListAllLanes,
319 k_BitfieldDescriptor,
323 SMLoc StartLoc, EndLoc;
324 SmallVector<unsigned, 8> Registers;
327 ARMCC::CondCodes Val;
334 struct CoprocOptionOp {
347 ARM_ISB::InstSyncBOpt Val;
351 ARM_PROC::IFlags Val;
367 // A vector register list is a sequential list of 1 to 4 registers.
368 struct VectorListOp {
375 struct VectorIndexOp {
383 /// Combined record for all forms of ARM address expressions.
386 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
388 const MCConstantExpr *OffsetImm; // Offset immediate value
389 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
390 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
391 unsigned ShiftImm; // shift for OffsetReg.
392 unsigned Alignment; // 0 = no alignment specified
393 // n = alignment in bytes (2, 4, 8, 16, or 32)
394 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
397 struct PostIdxRegOp {
400 ARM_AM::ShiftOpc ShiftTy;
404 struct ShifterImmOp {
409 struct RegShiftedRegOp {
410 ARM_AM::ShiftOpc ShiftTy;
416 struct RegShiftedImmOp {
417 ARM_AM::ShiftOpc ShiftTy;
434 struct CoprocOptionOp CoprocOption;
435 struct MBOptOp MBOpt;
436 struct ISBOptOp ISBOpt;
437 struct ITMaskOp ITMask;
438 struct IFlagsOp IFlags;
439 struct MMaskOp MMask;
442 struct VectorListOp VectorList;
443 struct VectorIndexOp VectorIndex;
445 struct MemoryOp Memory;
446 struct PostIdxRegOp PostIdxReg;
447 struct ShifterImmOp ShifterImm;
448 struct RegShiftedRegOp RegShiftedReg;
449 struct RegShiftedImmOp RegShiftedImm;
450 struct RotImmOp RotImm;
451 struct BitfieldOp Bitfield;
454 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
456 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
458 StartLoc = o.StartLoc;
475 case k_DPRRegisterList:
476 case k_SPRRegisterList:
477 Registers = o.Registers;
480 case k_VectorListAllLanes:
481 case k_VectorListIndexed:
482 VectorList = o.VectorList;
489 CoprocOption = o.CoprocOption;
494 case k_MemBarrierOpt:
497 case k_InstSyncBarrierOpt:
502 case k_PostIndexRegister:
503 PostIdxReg = o.PostIdxReg;
511 case k_ShifterImmediate:
512 ShifterImm = o.ShifterImm;
514 case k_ShiftedRegister:
515 RegShiftedReg = o.RegShiftedReg;
517 case k_ShiftedImmediate:
518 RegShiftedImm = o.RegShiftedImm;
520 case k_RotateImmediate:
523 case k_BitfieldDescriptor:
524 Bitfield = o.Bitfield;
527 VectorIndex = o.VectorIndex;
532 /// getStartLoc - Get the location of the first token of this operand.
533 SMLoc getStartLoc() const { return StartLoc; }
534 /// getEndLoc - Get the location of the last token of this operand.
535 SMLoc getEndLoc() const { return EndLoc; }
536 /// getLocRange - Get the range between the first and last token of this
538 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
540 ARMCC::CondCodes getCondCode() const {
541 assert(Kind == k_CondCode && "Invalid access!");
545 unsigned getCoproc() const {
546 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
550 StringRef getToken() const {
551 assert(Kind == k_Token && "Invalid access!");
552 return StringRef(Tok.Data, Tok.Length);
555 unsigned getReg() const {
556 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
560 const SmallVectorImpl<unsigned> &getRegList() const {
561 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
562 Kind == k_SPRRegisterList) && "Invalid access!");
566 const MCExpr *getImm() const {
567 assert(isImm() && "Invalid access!");
571 unsigned getVectorIndex() const {
572 assert(Kind == k_VectorIndex && "Invalid access!");
573 return VectorIndex.Val;
576 ARM_MB::MemBOpt getMemBarrierOpt() const {
577 assert(Kind == k_MemBarrierOpt && "Invalid access!");
581 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
582 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
586 ARM_PROC::IFlags getProcIFlags() const {
587 assert(Kind == k_ProcIFlags && "Invalid access!");
591 unsigned getMSRMask() const {
592 assert(Kind == k_MSRMask && "Invalid access!");
596 bool isCoprocNum() const { return Kind == k_CoprocNum; }
597 bool isCoprocReg() const { return Kind == k_CoprocReg; }
598 bool isCoprocOption() const { return Kind == k_CoprocOption; }
599 bool isCondCode() const { return Kind == k_CondCode; }
600 bool isCCOut() const { return Kind == k_CCOut; }
601 bool isITMask() const { return Kind == k_ITCondMask; }
602 bool isITCondCode() const { return Kind == k_CondCode; }
603 bool isImm() const { return Kind == k_Immediate; }
604 // checks whether this operand is an unsigned offset which fits is a field
605 // of specified width and scaled by a specific number of bits
606 template<unsigned width, unsigned scale>
607 bool isUnsignedOffset() const {
608 if (!isImm()) return false;
609 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
610 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
611 int64_t Val = CE->getValue();
612 int64_t Align = 1LL << scale;
613 int64_t Max = Align * ((1LL << width) - 1);
614 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
618 // checks whether this operand is an signed offset which fits is a field
619 // of specified width and scaled by a specific number of bits
620 template<unsigned width, unsigned scale>
621 bool isSignedOffset() const {
622 if (!isImm()) return false;
623 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
624 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
625 int64_t Val = CE->getValue();
626 int64_t Align = 1LL << scale;
627 int64_t Max = Align * ((1LL << (width-1)) - 1);
628 int64_t Min = -Align * (1LL << (width-1));
629 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
634 // checks whether this operand is a memory operand computed as an offset
635 // applied to PC. the offset may have 8 bits of magnitude and is represented
636 // with two bits of shift. textually it may be either [pc, #imm], #imm or
637 // relocable expression...
638 bool isThumbMemPC() const {
641 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
642 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
643 if (!CE) return false;
644 Val = CE->getValue();
647 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
648 if(Memory.BaseRegNum != ARM::PC) return false;
649 Val = Memory.OffsetImm->getValue();
652 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
654 bool isFPImm() const {
655 if (!isImm()) return false;
656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
657 if (!CE) return false;
658 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
661 bool isFBits16() 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 return Value >= 0 && Value <= 16;
668 bool isFBits32() const {
669 if (!isImm()) return false;
670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
671 if (!CE) return false;
672 int64_t Value = CE->getValue();
673 return Value >= 1 && Value <= 32;
675 bool isImm8s4() const {
676 if (!isImm()) return false;
677 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
678 if (!CE) return false;
679 int64_t Value = CE->getValue();
680 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
682 bool isImm0_4() const {
683 if (!isImm()) return false;
684 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
685 if (!CE) return false;
686 int64_t Value = CE->getValue();
687 return Value >= 0 && Value < 5;
689 bool isImm0_1020s4() const {
690 if (!isImm()) return false;
691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
692 if (!CE) return false;
693 int64_t Value = CE->getValue();
694 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
696 bool isImm0_508s4() const {
697 if (!isImm()) return false;
698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
699 if (!CE) return false;
700 int64_t Value = CE->getValue();
701 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
703 bool isImm0_508s4Neg() const {
704 if (!isImm()) return false;
705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
706 if (!CE) return false;
707 int64_t Value = -CE->getValue();
708 // explicitly exclude zero. we want that to use the normal 0_508 version.
709 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
711 bool isImm0_255() 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 < 256;
718 bool isImm0_4095() 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 < 4096;
725 bool isImm0_4095Neg() 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 < 4096;
732 bool isImm0_1() 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();
737 return Value >= 0 && Value < 2;
739 bool isImm0_3() 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();
744 return Value >= 0 && Value < 4;
746 bool isImm0_7() 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();
751 return Value >= 0 && Value < 8;
753 bool isImm0_15() 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 < 16;
760 bool isImm0_31() 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 < 32;
767 bool isImm0_63() 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 < 64;
774 bool isImm8() 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();
781 bool isImm16() 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();
788 bool isImm32() 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();
795 bool isShrImm8() 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 <= 8;
802 bool isShrImm16() 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 <= 16;
809 bool isShrImm32() 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 <= 32;
816 bool isShrImm64() 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 <= 64;
823 bool isImm1_7() 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 < 8;
830 bool isImm1_15() const {
831 if (!isImm()) return false;
832 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
833 if (!CE) return false;
834 int64_t Value = CE->getValue();
835 return Value > 0 && Value < 16;
837 bool isImm1_31() const {
838 if (!isImm()) return false;
839 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
840 if (!CE) return false;
841 int64_t Value = CE->getValue();
842 return Value > 0 && Value < 32;
844 bool isImm1_16() const {
845 if (!isImm()) return false;
846 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
847 if (!CE) return false;
848 int64_t Value = CE->getValue();
849 return Value > 0 && Value < 17;
851 bool isImm1_32() const {
852 if (!isImm()) return false;
853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
854 if (!CE) return false;
855 int64_t Value = CE->getValue();
856 return Value > 0 && Value < 33;
858 bool isImm0_32() const {
859 if (!isImm()) return false;
860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
861 if (!CE) return false;
862 int64_t Value = CE->getValue();
863 return Value >= 0 && Value < 33;
865 bool isImm0_65535() const {
866 if (!isImm()) return false;
867 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
868 if (!CE) return false;
869 int64_t Value = CE->getValue();
870 return Value >= 0 && Value < 65536;
872 bool isImm256_65535Expr() const {
873 if (!isImm()) return false;
874 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
875 // If it's not a constant expression, it'll generate a fixup and be
877 if (!CE) return true;
878 int64_t Value = CE->getValue();
879 return Value >= 256 && Value < 65536;
881 bool isImm0_65535Expr() const {
882 if (!isImm()) return false;
883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
884 // If it's not a constant expression, it'll generate a fixup and be
886 if (!CE) return true;
887 int64_t Value = CE->getValue();
888 return Value >= 0 && Value < 65536;
890 bool isImm24bit() const {
891 if (!isImm()) return false;
892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
893 if (!CE) return false;
894 int64_t Value = CE->getValue();
895 return Value >= 0 && Value <= 0xffffff;
897 bool isImmThumbSR() 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 Value > 0 && Value < 33;
904 bool isPKHLSLImm() 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 Value >= 0 && Value < 32;
911 bool isPKHASRImm() 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 return Value > 0 && Value <= 32;
918 bool isAdrLabel() const {
919 // If we have an immediate that's not a constant, treat it as a label
920 // reference needing a fixup. If it is a constant, but it can't fit
921 // into shift immediate encoding, we reject it.
922 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
923 else return (isARMSOImm() || isARMSOImmNeg());
925 bool isARMSOImm() const {
926 if (!isImm()) return false;
927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
928 if (!CE) return false;
929 int64_t Value = CE->getValue();
930 return ARM_AM::getSOImmVal(Value) != -1;
932 bool isARMSOImmNot() const {
933 if (!isImm()) return false;
934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
935 if (!CE) return false;
936 int64_t Value = CE->getValue();
937 return ARM_AM::getSOImmVal(~Value) != -1;
939 bool isARMSOImmNeg() const {
940 if (!isImm()) return false;
941 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
942 if (!CE) return false;
943 int64_t Value = CE->getValue();
944 // Only use this when not representable as a plain so_imm.
945 return ARM_AM::getSOImmVal(Value) == -1 &&
946 ARM_AM::getSOImmVal(-Value) != -1;
948 bool isT2SOImm() const {
949 if (!isImm()) return false;
950 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
951 if (!CE) return false;
952 int64_t Value = CE->getValue();
953 return ARM_AM::getT2SOImmVal(Value) != -1;
955 bool isT2SOImmNot() const {
956 if (!isImm()) return false;
957 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
958 if (!CE) return false;
959 int64_t Value = CE->getValue();
960 return ARM_AM::getT2SOImmVal(Value) == -1 &&
961 ARM_AM::getT2SOImmVal(~Value) != -1;
963 bool isT2SOImmNeg() const {
964 if (!isImm()) return false;
965 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
966 if (!CE) return false;
967 int64_t Value = CE->getValue();
968 // Only use this when not representable as a plain so_imm.
969 return ARM_AM::getT2SOImmVal(Value) == -1 &&
970 ARM_AM::getT2SOImmVal(-Value) != -1;
972 bool isSetEndImm() const {
973 if (!isImm()) return false;
974 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
975 if (!CE) return false;
976 int64_t Value = CE->getValue();
977 return Value == 1 || Value == 0;
979 bool isReg() const { return Kind == k_Register; }
980 bool isRegList() const { return Kind == k_RegisterList; }
981 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
982 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
983 bool isToken() const { return Kind == k_Token; }
984 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
985 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
986 bool isMem() const { return Kind == k_Memory; }
987 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
988 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
989 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
990 bool isRotImm() const { return Kind == k_RotateImmediate; }
991 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
992 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
993 bool isPostIdxReg() const {
994 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
996 bool isMemNoOffset(bool alignOK = false) const {
999 // No offset of any kind.
1000 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1001 (alignOK || Memory.Alignment == 0);
1003 bool isMemPCRelImm12() const {
1004 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1006 // Base register must be PC.
1007 if (Memory.BaseRegNum != ARM::PC)
1009 // Immediate offset in range [-4095, 4095].
1010 if (!Memory.OffsetImm) return true;
1011 int64_t Val = Memory.OffsetImm->getValue();
1012 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1014 bool isAlignedMemory() const {
1015 return isMemNoOffset(true);
1017 bool isAddrMode2() const {
1018 if (!isMem() || Memory.Alignment != 0) return false;
1019 // Check for register offset.
1020 if (Memory.OffsetRegNum) return true;
1021 // Immediate offset in range [-4095, 4095].
1022 if (!Memory.OffsetImm) return true;
1023 int64_t Val = Memory.OffsetImm->getValue();
1024 return Val > -4096 && Val < 4096;
1026 bool isAM2OffsetImm() const {
1027 if (!isImm()) return false;
1028 // Immediate offset in range [-4095, 4095].
1029 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1030 if (!CE) return false;
1031 int64_t Val = CE->getValue();
1032 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1034 bool isAddrMode3() const {
1035 // If we have an immediate that's not a constant, treat it as a label
1036 // reference needing a fixup. If it is a constant, it's something else
1037 // and we reject it.
1038 if (isImm() && !isa<MCConstantExpr>(getImm()))
1040 if (!isMem() || Memory.Alignment != 0) return false;
1041 // No shifts are legal for AM3.
1042 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1043 // Check for register offset.
1044 if (Memory.OffsetRegNum) return true;
1045 // Immediate offset in range [-255, 255].
1046 if (!Memory.OffsetImm) return true;
1047 int64_t Val = Memory.OffsetImm->getValue();
1048 // The #-0 offset is encoded as INT32_MIN, and we have to check
1050 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1052 bool isAM3Offset() const {
1053 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1055 if (Kind == k_PostIndexRegister)
1056 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1057 // Immediate offset in range [-255, 255].
1058 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1059 if (!CE) return false;
1060 int64_t Val = CE->getValue();
1061 // Special case, #-0 is INT32_MIN.
1062 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1064 bool isAddrMode5() const {
1065 // If we have an immediate that's not a constant, treat it as a label
1066 // reference needing a fixup. If it is a constant, it's something else
1067 // and we reject it.
1068 if (isImm() && !isa<MCConstantExpr>(getImm()))
1070 if (!isMem() || Memory.Alignment != 0) return false;
1071 // Check for register offset.
1072 if (Memory.OffsetRegNum) return false;
1073 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1074 if (!Memory.OffsetImm) return true;
1075 int64_t Val = Memory.OffsetImm->getValue();
1076 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1079 bool isMemTBB() const {
1080 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1081 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1085 bool isMemTBH() const {
1086 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1087 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1088 Memory.Alignment != 0 )
1092 bool isMemRegOffset() const {
1093 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1097 bool isT2MemRegOffset() const {
1098 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1099 Memory.Alignment != 0)
1101 // Only lsl #{0, 1, 2, 3} allowed.
1102 if (Memory.ShiftType == ARM_AM::no_shift)
1104 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1108 bool isMemThumbRR() const {
1109 // Thumb reg+reg addressing is simple. Just two registers, a base and
1110 // an offset. No shifts, negations or any other complicating factors.
1111 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1112 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1114 return isARMLowRegister(Memory.BaseRegNum) &&
1115 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1117 bool isMemThumbRIs4() const {
1118 if (!isMem() || Memory.OffsetRegNum != 0 ||
1119 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1121 // Immediate offset, multiple of 4 in range [0, 124].
1122 if (!Memory.OffsetImm) return true;
1123 int64_t Val = Memory.OffsetImm->getValue();
1124 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1126 bool isMemThumbRIs2() const {
1127 if (!isMem() || Memory.OffsetRegNum != 0 ||
1128 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1130 // Immediate offset, multiple of 4 in range [0, 62].
1131 if (!Memory.OffsetImm) return true;
1132 int64_t Val = Memory.OffsetImm->getValue();
1133 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1135 bool isMemThumbRIs1() const {
1136 if (!isMem() || Memory.OffsetRegNum != 0 ||
1137 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1139 // Immediate offset in range [0, 31].
1140 if (!Memory.OffsetImm) return true;
1141 int64_t Val = Memory.OffsetImm->getValue();
1142 return Val >= 0 && Val <= 31;
1144 bool isMemThumbSPI() const {
1145 if (!isMem() || Memory.OffsetRegNum != 0 ||
1146 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1148 // Immediate offset, multiple of 4 in range [0, 1020].
1149 if (!Memory.OffsetImm) return true;
1150 int64_t Val = Memory.OffsetImm->getValue();
1151 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1153 bool isMemImm8s4Offset() const {
1154 // If we have an immediate that's not a constant, treat it as a label
1155 // reference needing a fixup. If it is a constant, it's something else
1156 // and we reject it.
1157 if (isImm() && !isa<MCConstantExpr>(getImm()))
1159 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1161 // Immediate offset a multiple of 4 in range [-1020, 1020].
1162 if (!Memory.OffsetImm) return true;
1163 int64_t Val = Memory.OffsetImm->getValue();
1164 // Special case, #-0 is INT32_MIN.
1165 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1167 bool isMemImm0_1020s4Offset() const {
1168 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1170 // Immediate offset a multiple of 4 in range [0, 1020].
1171 if (!Memory.OffsetImm) return true;
1172 int64_t Val = Memory.OffsetImm->getValue();
1173 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1175 bool isMemImm8Offset() const {
1176 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1178 // Base reg of PC isn't allowed for these encodings.
1179 if (Memory.BaseRegNum == ARM::PC) return false;
1180 // Immediate offset in range [-255, 255].
1181 if (!Memory.OffsetImm) return true;
1182 int64_t Val = Memory.OffsetImm->getValue();
1183 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1185 bool isMemPosImm8Offset() const {
1186 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1188 // Immediate offset in range [0, 255].
1189 if (!Memory.OffsetImm) return true;
1190 int64_t Val = Memory.OffsetImm->getValue();
1191 return Val >= 0 && Val < 256;
1193 bool isMemNegImm8Offset() const {
1194 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1196 // Base reg of PC isn't allowed for these encodings.
1197 if (Memory.BaseRegNum == ARM::PC) return false;
1198 // Immediate offset in range [-255, -1].
1199 if (!Memory.OffsetImm) return false;
1200 int64_t Val = Memory.OffsetImm->getValue();
1201 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1203 bool isMemUImm12Offset() const {
1204 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1206 // Immediate offset in range [0, 4095].
1207 if (!Memory.OffsetImm) return true;
1208 int64_t Val = Memory.OffsetImm->getValue();
1209 return (Val >= 0 && Val < 4096);
1211 bool isMemImm12Offset() const {
1212 // If we have an immediate that's not a constant, treat it as a label
1213 // reference needing a fixup. If it is a constant, it's something else
1214 // and we reject it.
1215 if (isImm() && !isa<MCConstantExpr>(getImm()))
1218 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1220 // Immediate offset in range [-4095, 4095].
1221 if (!Memory.OffsetImm) return true;
1222 int64_t Val = Memory.OffsetImm->getValue();
1223 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1225 bool isPostIdxImm8() const {
1226 if (!isImm()) return false;
1227 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1228 if (!CE) return false;
1229 int64_t Val = CE->getValue();
1230 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1232 bool isPostIdxImm8s4() const {
1233 if (!isImm()) return false;
1234 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1235 if (!CE) return false;
1236 int64_t Val = CE->getValue();
1237 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1241 bool isMSRMask() const { return Kind == k_MSRMask; }
1242 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1245 bool isSingleSpacedVectorList() const {
1246 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1248 bool isDoubleSpacedVectorList() const {
1249 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1251 bool isVecListOneD() const {
1252 if (!isSingleSpacedVectorList()) return false;
1253 return VectorList.Count == 1;
1256 bool isVecListDPair() const {
1257 if (!isSingleSpacedVectorList()) return false;
1258 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1259 .contains(VectorList.RegNum));
1262 bool isVecListThreeD() const {
1263 if (!isSingleSpacedVectorList()) return false;
1264 return VectorList.Count == 3;
1267 bool isVecListFourD() const {
1268 if (!isSingleSpacedVectorList()) return false;
1269 return VectorList.Count == 4;
1272 bool isVecListDPairSpaced() const {
1273 if (isSingleSpacedVectorList()) return false;
1274 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1275 .contains(VectorList.RegNum));
1278 bool isVecListThreeQ() const {
1279 if (!isDoubleSpacedVectorList()) return false;
1280 return VectorList.Count == 3;
1283 bool isVecListFourQ() const {
1284 if (!isDoubleSpacedVectorList()) return false;
1285 return VectorList.Count == 4;
1288 bool isSingleSpacedVectorAllLanes() const {
1289 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1291 bool isDoubleSpacedVectorAllLanes() const {
1292 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1294 bool isVecListOneDAllLanes() const {
1295 if (!isSingleSpacedVectorAllLanes()) return false;
1296 return VectorList.Count == 1;
1299 bool isVecListDPairAllLanes() const {
1300 if (!isSingleSpacedVectorAllLanes()) return false;
1301 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1302 .contains(VectorList.RegNum));
1305 bool isVecListDPairSpacedAllLanes() const {
1306 if (!isDoubleSpacedVectorAllLanes()) return false;
1307 return VectorList.Count == 2;
1310 bool isVecListThreeDAllLanes() const {
1311 if (!isSingleSpacedVectorAllLanes()) return false;
1312 return VectorList.Count == 3;
1315 bool isVecListThreeQAllLanes() const {
1316 if (!isDoubleSpacedVectorAllLanes()) return false;
1317 return VectorList.Count == 3;
1320 bool isVecListFourDAllLanes() const {
1321 if (!isSingleSpacedVectorAllLanes()) return false;
1322 return VectorList.Count == 4;
1325 bool isVecListFourQAllLanes() const {
1326 if (!isDoubleSpacedVectorAllLanes()) return false;
1327 return VectorList.Count == 4;
1330 bool isSingleSpacedVectorIndexed() const {
1331 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1333 bool isDoubleSpacedVectorIndexed() const {
1334 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1336 bool isVecListOneDByteIndexed() const {
1337 if (!isSingleSpacedVectorIndexed()) return false;
1338 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1341 bool isVecListOneDHWordIndexed() const {
1342 if (!isSingleSpacedVectorIndexed()) return false;
1343 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1346 bool isVecListOneDWordIndexed() const {
1347 if (!isSingleSpacedVectorIndexed()) return false;
1348 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1351 bool isVecListTwoDByteIndexed() const {
1352 if (!isSingleSpacedVectorIndexed()) return false;
1353 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1356 bool isVecListTwoDHWordIndexed() const {
1357 if (!isSingleSpacedVectorIndexed()) return false;
1358 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1361 bool isVecListTwoQWordIndexed() const {
1362 if (!isDoubleSpacedVectorIndexed()) return false;
1363 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1366 bool isVecListTwoQHWordIndexed() const {
1367 if (!isDoubleSpacedVectorIndexed()) return false;
1368 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1371 bool isVecListTwoDWordIndexed() const {
1372 if (!isSingleSpacedVectorIndexed()) return false;
1373 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1376 bool isVecListThreeDByteIndexed() const {
1377 if (!isSingleSpacedVectorIndexed()) return false;
1378 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1381 bool isVecListThreeDHWordIndexed() const {
1382 if (!isSingleSpacedVectorIndexed()) return false;
1383 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1386 bool isVecListThreeQWordIndexed() const {
1387 if (!isDoubleSpacedVectorIndexed()) return false;
1388 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1391 bool isVecListThreeQHWordIndexed() const {
1392 if (!isDoubleSpacedVectorIndexed()) return false;
1393 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1396 bool isVecListThreeDWordIndexed() const {
1397 if (!isSingleSpacedVectorIndexed()) return false;
1398 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1401 bool isVecListFourDByteIndexed() const {
1402 if (!isSingleSpacedVectorIndexed()) return false;
1403 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1406 bool isVecListFourDHWordIndexed() const {
1407 if (!isSingleSpacedVectorIndexed()) return false;
1408 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1411 bool isVecListFourQWordIndexed() const {
1412 if (!isDoubleSpacedVectorIndexed()) return false;
1413 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1416 bool isVecListFourQHWordIndexed() const {
1417 if (!isDoubleSpacedVectorIndexed()) return false;
1418 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1421 bool isVecListFourDWordIndexed() const {
1422 if (!isSingleSpacedVectorIndexed()) return false;
1423 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1426 bool isVectorIndex8() const {
1427 if (Kind != k_VectorIndex) return false;
1428 return VectorIndex.Val < 8;
1430 bool isVectorIndex16() const {
1431 if (Kind != k_VectorIndex) return false;
1432 return VectorIndex.Val < 4;
1434 bool isVectorIndex32() const {
1435 if (Kind != k_VectorIndex) return false;
1436 return VectorIndex.Val < 2;
1439 bool isNEONi8splat() const {
1440 if (!isImm()) return false;
1441 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1442 // Must be a constant.
1443 if (!CE) return false;
1444 int64_t Value = CE->getValue();
1445 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1447 return Value >= 0 && Value < 256;
1450 bool isNEONi16splat() const {
1451 if (!isImm()) return false;
1452 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1453 // Must be a constant.
1454 if (!CE) return false;
1455 int64_t Value = CE->getValue();
1456 // i16 value in the range [0,255] or [0x0100, 0xff00]
1457 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1460 bool isNEONi32splat() const {
1461 if (!isImm()) return false;
1462 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1463 // Must be a constant.
1464 if (!CE) return false;
1465 int64_t Value = CE->getValue();
1466 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1467 return (Value >= 0 && Value < 256) ||
1468 (Value >= 0x0100 && Value <= 0xff00) ||
1469 (Value >= 0x010000 && Value <= 0xff0000) ||
1470 (Value >= 0x01000000 && Value <= 0xff000000);
1473 bool isNEONi32vmov() const {
1474 if (!isImm()) return false;
1475 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1476 // Must be a constant.
1477 if (!CE) return false;
1478 int64_t Value = CE->getValue();
1479 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1480 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1481 return (Value >= 0 && Value < 256) ||
1482 (Value >= 0x0100 && Value <= 0xff00) ||
1483 (Value >= 0x010000 && Value <= 0xff0000) ||
1484 (Value >= 0x01000000 && Value <= 0xff000000) ||
1485 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1486 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1488 bool isNEONi32vmovNeg() const {
1489 if (!isImm()) return false;
1490 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1491 // Must be a constant.
1492 if (!CE) return false;
1493 int64_t Value = ~CE->getValue();
1494 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1495 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1496 return (Value >= 0 && Value < 256) ||
1497 (Value >= 0x0100 && Value <= 0xff00) ||
1498 (Value >= 0x010000 && Value <= 0xff0000) ||
1499 (Value >= 0x01000000 && Value <= 0xff000000) ||
1500 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1501 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1504 bool isNEONi64splat() const {
1505 if (!isImm()) return false;
1506 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1507 // Must be a constant.
1508 if (!CE) return false;
1509 uint64_t Value = CE->getValue();
1510 // i64 value with each byte being either 0 or 0xff.
1511 for (unsigned i = 0; i < 8; ++i)
1512 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1516 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1517 // Add as immediates when possible. Null MCExpr = 0.
1519 Inst.addOperand(MCOperand::CreateImm(0));
1520 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1521 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1523 Inst.addOperand(MCOperand::CreateExpr(Expr));
1526 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1527 assert(N == 2 && "Invalid number of operands!");
1528 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1529 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1530 Inst.addOperand(MCOperand::CreateReg(RegNum));
1533 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1534 assert(N == 1 && "Invalid number of operands!");
1535 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1538 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1539 assert(N == 1 && "Invalid number of operands!");
1540 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1543 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1544 assert(N == 1 && "Invalid number of operands!");
1545 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1548 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1549 assert(N == 1 && "Invalid number of operands!");
1550 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1553 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1558 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1559 assert(N == 1 && "Invalid number of operands!");
1560 Inst.addOperand(MCOperand::CreateReg(getReg()));
1563 void addRegOperands(MCInst &Inst, unsigned N) const {
1564 assert(N == 1 && "Invalid number of operands!");
1565 Inst.addOperand(MCOperand::CreateReg(getReg()));
1568 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1569 assert(N == 3 && "Invalid number of operands!");
1570 assert(isRegShiftedReg() &&
1571 "addRegShiftedRegOperands() on non RegShiftedReg!");
1572 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1573 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1574 Inst.addOperand(MCOperand::CreateImm(
1575 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1578 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1579 assert(N == 2 && "Invalid number of operands!");
1580 assert(isRegShiftedImm() &&
1581 "addRegShiftedImmOperands() on non RegShiftedImm!");
1582 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1583 // Shift of #32 is encoded as 0 where permitted
1584 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1585 Inst.addOperand(MCOperand::CreateImm(
1586 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1589 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1590 assert(N == 1 && "Invalid number of operands!");
1591 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1595 void addRegListOperands(MCInst &Inst, unsigned N) const {
1596 assert(N == 1 && "Invalid number of operands!");
1597 const SmallVectorImpl<unsigned> &RegList = getRegList();
1598 for (SmallVectorImpl<unsigned>::const_iterator
1599 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1600 Inst.addOperand(MCOperand::CreateReg(*I));
1603 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1604 addRegListOperands(Inst, N);
1607 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1608 addRegListOperands(Inst, N);
1611 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1612 assert(N == 1 && "Invalid number of operands!");
1613 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1614 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1617 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1618 assert(N == 1 && "Invalid number of operands!");
1619 // Munge the lsb/width into a bitfield mask.
1620 unsigned lsb = Bitfield.LSB;
1621 unsigned width = Bitfield.Width;
1622 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1623 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1624 (32 - (lsb + width)));
1625 Inst.addOperand(MCOperand::CreateImm(Mask));
1628 void addImmOperands(MCInst &Inst, unsigned N) const {
1629 assert(N == 1 && "Invalid number of operands!");
1630 addExpr(Inst, getImm());
1633 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1634 assert(N == 1 && "Invalid number of operands!");
1635 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1636 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1639 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1640 assert(N == 1 && "Invalid number of operands!");
1641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1642 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1645 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1646 assert(N == 1 && "Invalid number of operands!");
1647 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1648 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1649 Inst.addOperand(MCOperand::CreateImm(Val));
1652 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1653 assert(N == 1 && "Invalid number of operands!");
1654 // FIXME: We really want to scale the value here, but the LDRD/STRD
1655 // instruction don't encode operands that way yet.
1656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1657 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1660 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1661 assert(N == 1 && "Invalid number of operands!");
1662 // The immediate is scaled by four in the encoding and is stored
1663 // in the MCInst as such. Lop off the low two bits here.
1664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1665 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1668 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1669 assert(N == 1 && "Invalid number of operands!");
1670 // The immediate is scaled by four in the encoding and is stored
1671 // in the MCInst as such. Lop off the low two bits here.
1672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1673 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1676 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1677 assert(N == 1 && "Invalid number of operands!");
1678 // The immediate is scaled by four in the encoding and is stored
1679 // in the MCInst as such. Lop off the low two bits here.
1680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1681 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1684 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1685 assert(N == 1 && "Invalid number of operands!");
1686 // The constant encodes as the immediate-1, and we store in the instruction
1687 // the bits as encoded, so subtract off one here.
1688 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1689 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1692 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1693 assert(N == 1 && "Invalid number of operands!");
1694 // The constant encodes as the immediate-1, and we store in the instruction
1695 // the bits as encoded, so subtract off one here.
1696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1697 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1700 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1701 assert(N == 1 && "Invalid number of operands!");
1702 // The constant encodes as the immediate, except for 32, which encodes as
1704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1705 unsigned Imm = CE->getValue();
1706 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1709 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1710 assert(N == 1 && "Invalid number of operands!");
1711 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1712 // the instruction as well.
1713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1714 int Val = CE->getValue();
1715 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1718 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1719 assert(N == 1 && "Invalid number of operands!");
1720 // The operand is actually a t2_so_imm, but we have its bitwise
1721 // negation in the assembly source, so twiddle it here.
1722 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1723 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1726 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1727 assert(N == 1 && "Invalid number of operands!");
1728 // The operand is actually a t2_so_imm, but we have its
1729 // negation in the assembly source, so twiddle it here.
1730 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1731 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1734 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1735 assert(N == 1 && "Invalid number of operands!");
1736 // The operand is actually an imm0_4095, but we have its
1737 // negation in the assembly source, so twiddle it here.
1738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1739 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1742 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1743 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1744 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1748 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1749 assert(SR && "Unknown value type!");
1750 Inst.addOperand(MCOperand::CreateExpr(SR));
1753 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1754 assert(N == 1 && "Invalid number of operands!");
1756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1758 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1762 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1763 assert(SR && "Unknown value type!");
1764 Inst.addOperand(MCOperand::CreateExpr(SR));
1768 assert(isMem() && "Unknown value type!");
1769 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1770 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1773 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1774 assert(N == 1 && "Invalid number of operands!");
1775 // The operand is actually a so_imm, but we have its bitwise
1776 // negation in the assembly source, so twiddle it here.
1777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1778 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1781 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1782 assert(N == 1 && "Invalid number of operands!");
1783 // The operand is actually a so_imm, but we have its
1784 // negation in the assembly source, so twiddle it here.
1785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1786 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1789 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1790 assert(N == 1 && "Invalid number of operands!");
1791 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1794 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 1 && "Invalid number of operands!");
1796 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1799 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1800 assert(N == 1 && "Invalid number of operands!");
1801 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1804 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1805 assert(N == 1 && "Invalid number of operands!");
1806 int32_t Imm = Memory.OffsetImm->getValue();
1807 Inst.addOperand(MCOperand::CreateImm(Imm));
1810 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1811 assert(N == 1 && "Invalid number of operands!");
1812 assert(isImm() && "Not an immediate!");
1814 // If we have an immediate that's not a constant, treat it as a label
1815 // reference needing a fixup.
1816 if (!isa<MCConstantExpr>(getImm())) {
1817 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1821 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1822 int Val = CE->getValue();
1823 Inst.addOperand(MCOperand::CreateImm(Val));
1826 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1827 assert(N == 2 && "Invalid number of operands!");
1828 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1829 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1832 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1833 assert(N == 3 && "Invalid number of operands!");
1834 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1835 if (!Memory.OffsetRegNum) {
1836 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1837 // Special case for #-0
1838 if (Val == INT32_MIN) Val = 0;
1839 if (Val < 0) Val = -Val;
1840 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1842 // For register offset, we encode the shift type and negation flag
1844 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1845 Memory.ShiftImm, Memory.ShiftType);
1847 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1848 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1849 Inst.addOperand(MCOperand::CreateImm(Val));
1852 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1853 assert(N == 2 && "Invalid number of operands!");
1854 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1855 assert(CE && "non-constant AM2OffsetImm operand!");
1856 int32_t Val = CE->getValue();
1857 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1858 // Special case for #-0
1859 if (Val == INT32_MIN) Val = 0;
1860 if (Val < 0) Val = -Val;
1861 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1862 Inst.addOperand(MCOperand::CreateReg(0));
1863 Inst.addOperand(MCOperand::CreateImm(Val));
1866 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1867 assert(N == 3 && "Invalid number of operands!");
1868 // If we have an immediate that's not a constant, treat it as a label
1869 // reference needing a fixup. If it is a constant, it's something else
1870 // and we reject it.
1872 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1873 Inst.addOperand(MCOperand::CreateReg(0));
1874 Inst.addOperand(MCOperand::CreateImm(0));
1878 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1879 if (!Memory.OffsetRegNum) {
1880 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1881 // Special case for #-0
1882 if (Val == INT32_MIN) Val = 0;
1883 if (Val < 0) Val = -Val;
1884 Val = ARM_AM::getAM3Opc(AddSub, Val);
1886 // For register offset, we encode the shift type and negation flag
1888 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1890 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1891 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1892 Inst.addOperand(MCOperand::CreateImm(Val));
1895 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1896 assert(N == 2 && "Invalid number of operands!");
1897 if (Kind == k_PostIndexRegister) {
1899 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1900 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1901 Inst.addOperand(MCOperand::CreateImm(Val));
1906 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1907 int32_t Val = CE->getValue();
1908 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1909 // Special case for #-0
1910 if (Val == INT32_MIN) Val = 0;
1911 if (Val < 0) Val = -Val;
1912 Val = ARM_AM::getAM3Opc(AddSub, Val);
1913 Inst.addOperand(MCOperand::CreateReg(0));
1914 Inst.addOperand(MCOperand::CreateImm(Val));
1917 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1918 assert(N == 2 && "Invalid number of operands!");
1919 // If we have an immediate that's not a constant, treat it as a label
1920 // reference needing a fixup. If it is a constant, it's something else
1921 // and we reject it.
1923 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1924 Inst.addOperand(MCOperand::CreateImm(0));
1928 // The lower two bits are always zero and as such are not encoded.
1929 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1930 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1931 // Special case for #-0
1932 if (Val == INT32_MIN) Val = 0;
1933 if (Val < 0) Val = -Val;
1934 Val = ARM_AM::getAM5Opc(AddSub, Val);
1935 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1936 Inst.addOperand(MCOperand::CreateImm(Val));
1939 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1940 assert(N == 2 && "Invalid number of operands!");
1941 // If we have an immediate that's not a constant, treat it as a label
1942 // reference needing a fixup. If it is a constant, it's something else
1943 // and we reject it.
1945 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1946 Inst.addOperand(MCOperand::CreateImm(0));
1950 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1951 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1952 Inst.addOperand(MCOperand::CreateImm(Val));
1955 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1956 assert(N == 2 && "Invalid number of operands!");
1957 // The lower two bits are always zero and as such are not encoded.
1958 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1959 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1960 Inst.addOperand(MCOperand::CreateImm(Val));
1963 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1964 assert(N == 2 && "Invalid number of operands!");
1965 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1966 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1967 Inst.addOperand(MCOperand::CreateImm(Val));
1970 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1971 addMemImm8OffsetOperands(Inst, N);
1974 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1975 addMemImm8OffsetOperands(Inst, N);
1978 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1979 assert(N == 2 && "Invalid number of operands!");
1980 // If this is an immediate, it's a label reference.
1982 addExpr(Inst, getImm());
1983 Inst.addOperand(MCOperand::CreateImm(0));
1987 // Otherwise, it's a normal memory reg+offset.
1988 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1989 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1990 Inst.addOperand(MCOperand::CreateImm(Val));
1993 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1994 assert(N == 2 && "Invalid number of operands!");
1995 // If this is an immediate, it's a label reference.
1997 addExpr(Inst, getImm());
1998 Inst.addOperand(MCOperand::CreateImm(0));
2002 // Otherwise, it's a normal memory reg+offset.
2003 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2004 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2005 Inst.addOperand(MCOperand::CreateImm(Val));
2008 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2009 assert(N == 2 && "Invalid number of operands!");
2010 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2011 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2014 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2015 assert(N == 2 && "Invalid number of operands!");
2016 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2017 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2020 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2021 assert(N == 3 && "Invalid number of operands!");
2023 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2024 Memory.ShiftImm, Memory.ShiftType);
2025 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2026 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2027 Inst.addOperand(MCOperand::CreateImm(Val));
2030 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2031 assert(N == 3 && "Invalid number of operands!");
2032 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2033 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2034 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2037 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2038 assert(N == 2 && "Invalid number of operands!");
2039 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2040 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2043 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2044 assert(N == 2 && "Invalid number of operands!");
2045 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2046 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2047 Inst.addOperand(MCOperand::CreateImm(Val));
2050 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2051 assert(N == 2 && "Invalid number of operands!");
2052 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2053 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2054 Inst.addOperand(MCOperand::CreateImm(Val));
2057 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2058 assert(N == 2 && "Invalid number of operands!");
2059 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2060 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2061 Inst.addOperand(MCOperand::CreateImm(Val));
2064 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2065 assert(N == 2 && "Invalid number of operands!");
2066 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2067 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2068 Inst.addOperand(MCOperand::CreateImm(Val));
2071 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2072 assert(N == 1 && "Invalid number of operands!");
2073 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2074 assert(CE && "non-constant post-idx-imm8 operand!");
2075 int Imm = CE->getValue();
2076 bool isAdd = Imm >= 0;
2077 if (Imm == INT32_MIN) Imm = 0;
2078 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2079 Inst.addOperand(MCOperand::CreateImm(Imm));
2082 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2083 assert(N == 1 && "Invalid number of operands!");
2084 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2085 assert(CE && "non-constant post-idx-imm8s4 operand!");
2086 int Imm = CE->getValue();
2087 bool isAdd = Imm >= 0;
2088 if (Imm == INT32_MIN) Imm = 0;
2089 // Immediate is scaled by 4.
2090 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2091 Inst.addOperand(MCOperand::CreateImm(Imm));
2094 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2095 assert(N == 2 && "Invalid number of operands!");
2096 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2097 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2100 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2101 assert(N == 2 && "Invalid number of operands!");
2102 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2103 // The sign, shift type, and shift amount are encoded in a single operand
2104 // using the AM2 encoding helpers.
2105 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2106 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2107 PostIdxReg.ShiftTy);
2108 Inst.addOperand(MCOperand::CreateImm(Imm));
2111 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2112 assert(N == 1 && "Invalid number of operands!");
2113 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2116 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2117 assert(N == 1 && "Invalid number of operands!");
2118 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2121 void addVecListOperands(MCInst &Inst, unsigned N) const {
2122 assert(N == 1 && "Invalid number of operands!");
2123 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2126 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2127 assert(N == 2 && "Invalid number of operands!");
2128 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2129 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2132 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2133 assert(N == 1 && "Invalid number of operands!");
2134 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2137 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2138 assert(N == 1 && "Invalid number of operands!");
2139 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2142 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2143 assert(N == 1 && "Invalid number of operands!");
2144 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2147 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2148 assert(N == 1 && "Invalid number of operands!");
2149 // The immediate encodes the type of constant as well as the value.
2150 // Mask in that this is an i8 splat.
2151 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2152 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2155 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2156 assert(N == 1 && "Invalid number of operands!");
2157 // The immediate encodes the type of constant as well as the value.
2158 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2159 unsigned Value = CE->getValue();
2161 Value = (Value >> 8) | 0xa00;
2164 Inst.addOperand(MCOperand::CreateImm(Value));
2167 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2168 assert(N == 1 && "Invalid number of operands!");
2169 // The immediate encodes the type of constant as well as the value.
2170 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2171 unsigned Value = CE->getValue();
2172 if (Value >= 256 && Value <= 0xff00)
2173 Value = (Value >> 8) | 0x200;
2174 else if (Value > 0xffff && Value <= 0xff0000)
2175 Value = (Value >> 16) | 0x400;
2176 else if (Value > 0xffffff)
2177 Value = (Value >> 24) | 0x600;
2178 Inst.addOperand(MCOperand::CreateImm(Value));
2181 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2182 assert(N == 1 && "Invalid number of operands!");
2183 // The immediate encodes the type of constant as well as the value.
2184 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2185 unsigned Value = CE->getValue();
2186 if (Value >= 256 && Value <= 0xffff)
2187 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2188 else if (Value > 0xffff && Value <= 0xffffff)
2189 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2190 else if (Value > 0xffffff)
2191 Value = (Value >> 24) | 0x600;
2192 Inst.addOperand(MCOperand::CreateImm(Value));
2195 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2196 assert(N == 1 && "Invalid number of operands!");
2197 // The immediate encodes the type of constant as well as the value.
2198 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2199 unsigned Value = ~CE->getValue();
2200 if (Value >= 256 && Value <= 0xffff)
2201 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2202 else if (Value > 0xffff && Value <= 0xffffff)
2203 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2204 else if (Value > 0xffffff)
2205 Value = (Value >> 24) | 0x600;
2206 Inst.addOperand(MCOperand::CreateImm(Value));
2209 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2210 assert(N == 1 && "Invalid number of operands!");
2211 // The immediate encodes the type of constant as well as the value.
2212 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2213 uint64_t Value = CE->getValue();
2215 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2216 Imm |= (Value & 1) << i;
2218 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2221 virtual void print(raw_ostream &OS) const;
2223 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2224 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2225 Op->ITMask.Mask = Mask;
2231 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2232 ARMOperand *Op = new ARMOperand(k_CondCode);
2239 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2240 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2241 Op->Cop.Val = CopVal;
2247 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2248 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2249 Op->Cop.Val = CopVal;
2255 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2256 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2263 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2264 ARMOperand *Op = new ARMOperand(k_CCOut);
2265 Op->Reg.RegNum = RegNum;
2271 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2272 ARMOperand *Op = new ARMOperand(k_Token);
2273 Op->Tok.Data = Str.data();
2274 Op->Tok.Length = Str.size();
2280 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2281 ARMOperand *Op = new ARMOperand(k_Register);
2282 Op->Reg.RegNum = RegNum;
2288 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2293 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2294 Op->RegShiftedReg.ShiftTy = ShTy;
2295 Op->RegShiftedReg.SrcReg = SrcReg;
2296 Op->RegShiftedReg.ShiftReg = ShiftReg;
2297 Op->RegShiftedReg.ShiftImm = ShiftImm;
2303 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2307 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2308 Op->RegShiftedImm.ShiftTy = ShTy;
2309 Op->RegShiftedImm.SrcReg = SrcReg;
2310 Op->RegShiftedImm.ShiftImm = ShiftImm;
2316 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2318 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2319 Op->ShifterImm.isASR = isASR;
2320 Op->ShifterImm.Imm = Imm;
2326 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2327 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2328 Op->RotImm.Imm = Imm;
2334 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2336 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2337 Op->Bitfield.LSB = LSB;
2338 Op->Bitfield.Width = Width;
2345 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2346 SMLoc StartLoc, SMLoc EndLoc) {
2347 assert (Regs.size() > 0 && "RegList contains no registers?");
2348 KindTy Kind = k_RegisterList;
2350 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2351 Kind = k_DPRRegisterList;
2352 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2353 contains(Regs.front().second))
2354 Kind = k_SPRRegisterList;
2356 // Sort based on the register encoding values.
2357 array_pod_sort(Regs.begin(), Regs.end());
2359 ARMOperand *Op = new ARMOperand(Kind);
2360 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2361 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2362 Op->Registers.push_back(I->second);
2363 Op->StartLoc = StartLoc;
2364 Op->EndLoc = EndLoc;
2368 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2369 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2370 ARMOperand *Op = new ARMOperand(k_VectorList);
2371 Op->VectorList.RegNum = RegNum;
2372 Op->VectorList.Count = Count;
2373 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2379 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2380 bool isDoubleSpaced,
2382 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2383 Op->VectorList.RegNum = RegNum;
2384 Op->VectorList.Count = Count;
2385 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2391 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2393 bool isDoubleSpaced,
2395 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2396 Op->VectorList.RegNum = RegNum;
2397 Op->VectorList.Count = Count;
2398 Op->VectorList.LaneIndex = Index;
2399 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2405 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2407 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2408 Op->VectorIndex.Val = Idx;
2414 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2415 ARMOperand *Op = new ARMOperand(k_Immediate);
2422 static ARMOperand *CreateMem(unsigned BaseRegNum,
2423 const MCConstantExpr *OffsetImm,
2424 unsigned OffsetRegNum,
2425 ARM_AM::ShiftOpc ShiftType,
2430 ARMOperand *Op = new ARMOperand(k_Memory);
2431 Op->Memory.BaseRegNum = BaseRegNum;
2432 Op->Memory.OffsetImm = OffsetImm;
2433 Op->Memory.OffsetRegNum = OffsetRegNum;
2434 Op->Memory.ShiftType = ShiftType;
2435 Op->Memory.ShiftImm = ShiftImm;
2436 Op->Memory.Alignment = Alignment;
2437 Op->Memory.isNegative = isNegative;
2443 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2444 ARM_AM::ShiftOpc ShiftTy,
2447 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2448 Op->PostIdxReg.RegNum = RegNum;
2449 Op->PostIdxReg.isAdd = isAdd;
2450 Op->PostIdxReg.ShiftTy = ShiftTy;
2451 Op->PostIdxReg.ShiftImm = ShiftImm;
2457 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2458 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2459 Op->MBOpt.Val = Opt;
2465 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2467 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2468 Op->ISBOpt.Val = Opt;
2474 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2475 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2476 Op->IFlags.Val = IFlags;
2482 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2483 ARMOperand *Op = new ARMOperand(k_MSRMask);
2484 Op->MMask.Val = MMask;
2491 } // end anonymous namespace.
2493 void ARMOperand::print(raw_ostream &OS) const {
2496 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2499 OS << "<ccout " << getReg() << ">";
2501 case k_ITCondMask: {
2502 static const char *const MaskStr[] = {
2503 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2504 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2506 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2507 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2511 OS << "<coprocessor number: " << getCoproc() << ">";
2514 OS << "<coprocessor register: " << getCoproc() << ">";
2516 case k_CoprocOption:
2517 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2520 OS << "<mask: " << getMSRMask() << ">";
2523 getImm()->print(OS);
2525 case k_MemBarrierOpt:
2526 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2528 case k_InstSyncBarrierOpt:
2529 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2533 << " base:" << Memory.BaseRegNum;
2536 case k_PostIndexRegister:
2537 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2538 << PostIdxReg.RegNum;
2539 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2540 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2541 << PostIdxReg.ShiftImm;
2544 case k_ProcIFlags: {
2545 OS << "<ARM_PROC::";
2546 unsigned IFlags = getProcIFlags();
2547 for (int i=2; i >= 0; --i)
2548 if (IFlags & (1 << i))
2549 OS << ARM_PROC::IFlagsToString(1 << i);
2554 OS << "<register " << getReg() << ">";
2556 case k_ShifterImmediate:
2557 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2558 << " #" << ShifterImm.Imm << ">";
2560 case k_ShiftedRegister:
2561 OS << "<so_reg_reg "
2562 << RegShiftedReg.SrcReg << " "
2563 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2564 << " " << RegShiftedReg.ShiftReg << ">";
2566 case k_ShiftedImmediate:
2567 OS << "<so_reg_imm "
2568 << RegShiftedImm.SrcReg << " "
2569 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2570 << " #" << RegShiftedImm.ShiftImm << ">";
2572 case k_RotateImmediate:
2573 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2575 case k_BitfieldDescriptor:
2576 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2577 << ", width: " << Bitfield.Width << ">";
2579 case k_RegisterList:
2580 case k_DPRRegisterList:
2581 case k_SPRRegisterList: {
2582 OS << "<register_list ";
2584 const SmallVectorImpl<unsigned> &RegList = getRegList();
2585 for (SmallVectorImpl<unsigned>::const_iterator
2586 I = RegList.begin(), E = RegList.end(); I != E; ) {
2588 if (++I < E) OS << ", ";
2595 OS << "<vector_list " << VectorList.Count << " * "
2596 << VectorList.RegNum << ">";
2598 case k_VectorListAllLanes:
2599 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2600 << VectorList.RegNum << ">";
2602 case k_VectorListIndexed:
2603 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2604 << VectorList.Count << " * " << VectorList.RegNum << ">";
2607 OS << "'" << getToken() << "'";
2610 OS << "<vectorindex " << getVectorIndex() << ">";
2615 /// @name Auto-generated Match Functions
2618 static unsigned MatchRegisterName(StringRef Name);
2622 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2623 SMLoc &StartLoc, SMLoc &EndLoc) {
2624 StartLoc = Parser.getTok().getLoc();
2625 EndLoc = Parser.getTok().getEndLoc();
2626 RegNo = tryParseRegister();
2628 return (RegNo == (unsigned)-1);
2631 /// Try to parse a register name. The token must be an Identifier when called,
2632 /// and if it is a register name the token is eaten and the register number is
2633 /// returned. Otherwise return -1.
2635 int ARMAsmParser::tryParseRegister() {
2636 const AsmToken &Tok = Parser.getTok();
2637 if (Tok.isNot(AsmToken::Identifier)) return -1;
2639 std::string lowerCase = Tok.getString().lower();
2640 unsigned RegNum = MatchRegisterName(lowerCase);
2642 RegNum = StringSwitch<unsigned>(lowerCase)
2643 .Case("r13", ARM::SP)
2644 .Case("r14", ARM::LR)
2645 .Case("r15", ARM::PC)
2646 .Case("ip", ARM::R12)
2647 // Additional register name aliases for 'gas' compatibility.
2648 .Case("a1", ARM::R0)
2649 .Case("a2", ARM::R1)
2650 .Case("a3", ARM::R2)
2651 .Case("a4", ARM::R3)
2652 .Case("v1", ARM::R4)
2653 .Case("v2", ARM::R5)
2654 .Case("v3", ARM::R6)
2655 .Case("v4", ARM::R7)
2656 .Case("v5", ARM::R8)
2657 .Case("v6", ARM::R9)
2658 .Case("v7", ARM::R10)
2659 .Case("v8", ARM::R11)
2660 .Case("sb", ARM::R9)
2661 .Case("sl", ARM::R10)
2662 .Case("fp", ARM::R11)
2666 // Check for aliases registered via .req. Canonicalize to lower case.
2667 // That's more consistent since register names are case insensitive, and
2668 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2669 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2670 // If no match, return failure.
2671 if (Entry == RegisterReqs.end())
2673 Parser.Lex(); // Eat identifier token.
2674 return Entry->getValue();
2677 Parser.Lex(); // Eat identifier token.
2682 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2683 // If a recoverable error occurs, return 1. If an irrecoverable error
2684 // occurs, return -1. An irrecoverable error is one where tokens have been
2685 // consumed in the process of trying to parse the shifter (i.e., when it is
2686 // indeed a shifter operand, but malformed).
2687 int ARMAsmParser::tryParseShiftRegister(
2688 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2689 SMLoc S = Parser.getTok().getLoc();
2690 const AsmToken &Tok = Parser.getTok();
2691 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2693 std::string lowerCase = Tok.getString().lower();
2694 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2695 .Case("asl", ARM_AM::lsl)
2696 .Case("lsl", ARM_AM::lsl)
2697 .Case("lsr", ARM_AM::lsr)
2698 .Case("asr", ARM_AM::asr)
2699 .Case("ror", ARM_AM::ror)
2700 .Case("rrx", ARM_AM::rrx)
2701 .Default(ARM_AM::no_shift);
2703 if (ShiftTy == ARM_AM::no_shift)
2706 Parser.Lex(); // Eat the operator.
2708 // The source register for the shift has already been added to the
2709 // operand list, so we need to pop it off and combine it into the shifted
2710 // register operand instead.
2711 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2712 if (!PrevOp->isReg())
2713 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2714 int SrcReg = PrevOp->getReg();
2719 if (ShiftTy == ARM_AM::rrx) {
2720 // RRX Doesn't have an explicit shift amount. The encoder expects
2721 // the shift register to be the same as the source register. Seems odd,
2725 // Figure out if this is shifted by a constant or a register (for non-RRX).
2726 if (Parser.getTok().is(AsmToken::Hash) ||
2727 Parser.getTok().is(AsmToken::Dollar)) {
2728 Parser.Lex(); // Eat hash.
2729 SMLoc ImmLoc = Parser.getTok().getLoc();
2730 const MCExpr *ShiftExpr = 0;
2731 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2732 Error(ImmLoc, "invalid immediate shift value");
2735 // The expression must be evaluatable as an immediate.
2736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2738 Error(ImmLoc, "invalid immediate shift value");
2741 // Range check the immediate.
2742 // lsl, ror: 0 <= imm <= 31
2743 // lsr, asr: 0 <= imm <= 32
2744 Imm = CE->getValue();
2746 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2747 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2748 Error(ImmLoc, "immediate shift value out of range");
2751 // shift by zero is a nop. Always send it through as lsl.
2752 // ('as' compatibility)
2754 ShiftTy = ARM_AM::lsl;
2755 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2756 SMLoc L = Parser.getTok().getLoc();
2757 EndLoc = Parser.getTok().getEndLoc();
2758 ShiftReg = tryParseRegister();
2759 if (ShiftReg == -1) {
2760 Error (L, "expected immediate or register in shift operand");
2764 Error (Parser.getTok().getLoc(),
2765 "expected immediate or register in shift operand");
2770 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2771 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2775 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2782 /// Try to parse a register name. The token must be an Identifier when called.
2783 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2784 /// if there is a "writeback". 'true' if it's not a register.
2786 /// TODO this is likely to change to allow different register types and or to
2787 /// parse for a specific register type.
2789 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2790 const AsmToken &RegTok = Parser.getTok();
2791 int RegNo = tryParseRegister();
2795 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2796 RegTok.getEndLoc()));
2798 const AsmToken &ExclaimTok = Parser.getTok();
2799 if (ExclaimTok.is(AsmToken::Exclaim)) {
2800 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2801 ExclaimTok.getLoc()));
2802 Parser.Lex(); // Eat exclaim token
2806 // Also check for an index operand. This is only legal for vector registers,
2807 // but that'll get caught OK in operand matching, so we don't need to
2808 // explicitly filter everything else out here.
2809 if (Parser.getTok().is(AsmToken::LBrac)) {
2810 SMLoc SIdx = Parser.getTok().getLoc();
2811 Parser.Lex(); // Eat left bracket token.
2813 const MCExpr *ImmVal;
2814 if (getParser().parseExpression(ImmVal))
2816 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2818 return TokError("immediate value expected for vector index");
2820 if (Parser.getTok().isNot(AsmToken::RBrac))
2821 return Error(Parser.getTok().getLoc(), "']' expected");
2823 SMLoc E = Parser.getTok().getEndLoc();
2824 Parser.Lex(); // Eat right bracket token.
2826 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2834 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2835 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2837 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2838 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2840 switch (Name.size()) {
2843 if (Name[0] != CoprocOp)
2859 if (Name[0] != CoprocOp || Name[1] != '1')
2863 case '0': return 10;
2864 case '1': return 11;
2865 case '2': return 12;
2866 case '3': return 13;
2867 case '4': return 14;
2868 case '5': return 15;
2873 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2874 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2875 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2876 SMLoc S = Parser.getTok().getLoc();
2877 const AsmToken &Tok = Parser.getTok();
2878 if (!Tok.is(AsmToken::Identifier))
2879 return MatchOperand_NoMatch;
2880 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2881 .Case("eq", ARMCC::EQ)
2882 .Case("ne", ARMCC::NE)
2883 .Case("hs", ARMCC::HS)
2884 .Case("cs", ARMCC::HS)
2885 .Case("lo", ARMCC::LO)
2886 .Case("cc", ARMCC::LO)
2887 .Case("mi", ARMCC::MI)
2888 .Case("pl", ARMCC::PL)
2889 .Case("vs", ARMCC::VS)
2890 .Case("vc", ARMCC::VC)
2891 .Case("hi", ARMCC::HI)
2892 .Case("ls", ARMCC::LS)
2893 .Case("ge", ARMCC::GE)
2894 .Case("lt", ARMCC::LT)
2895 .Case("gt", ARMCC::GT)
2896 .Case("le", ARMCC::LE)
2897 .Case("al", ARMCC::AL)
2900 return MatchOperand_NoMatch;
2901 Parser.Lex(); // Eat the token.
2903 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2905 return MatchOperand_Success;
2908 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2909 /// token must be an Identifier when called, and if it is a coprocessor
2910 /// number, the token is eaten and the operand is added to the operand list.
2911 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2912 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2913 SMLoc S = Parser.getTok().getLoc();
2914 const AsmToken &Tok = Parser.getTok();
2915 if (Tok.isNot(AsmToken::Identifier))
2916 return MatchOperand_NoMatch;
2918 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2920 return MatchOperand_NoMatch;
2922 Parser.Lex(); // Eat identifier token.
2923 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2924 return MatchOperand_Success;
2927 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2928 /// token must be an Identifier when called, and if it is a coprocessor
2929 /// number, the token is eaten and the operand is added to the operand list.
2930 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2931 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2932 SMLoc S = Parser.getTok().getLoc();
2933 const AsmToken &Tok = Parser.getTok();
2934 if (Tok.isNot(AsmToken::Identifier))
2935 return MatchOperand_NoMatch;
2937 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2939 return MatchOperand_NoMatch;
2941 Parser.Lex(); // Eat identifier token.
2942 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2943 return MatchOperand_Success;
2946 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2947 /// coproc_option : '{' imm0_255 '}'
2948 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2949 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2950 SMLoc S = Parser.getTok().getLoc();
2952 // If this isn't a '{', this isn't a coprocessor immediate operand.
2953 if (Parser.getTok().isNot(AsmToken::LCurly))
2954 return MatchOperand_NoMatch;
2955 Parser.Lex(); // Eat the '{'
2958 SMLoc Loc = Parser.getTok().getLoc();
2959 if (getParser().parseExpression(Expr)) {
2960 Error(Loc, "illegal expression");
2961 return MatchOperand_ParseFail;
2963 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2964 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2965 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2966 return MatchOperand_ParseFail;
2968 int Val = CE->getValue();
2970 // Check for and consume the closing '}'
2971 if (Parser.getTok().isNot(AsmToken::RCurly))
2972 return MatchOperand_ParseFail;
2973 SMLoc E = Parser.getTok().getEndLoc();
2974 Parser.Lex(); // Eat the '}'
2976 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2977 return MatchOperand_Success;
2980 // For register list parsing, we need to map from raw GPR register numbering
2981 // to the enumeration values. The enumeration values aren't sorted by
2982 // register number due to our using "sp", "lr" and "pc" as canonical names.
2983 static unsigned getNextRegister(unsigned Reg) {
2984 // If this is a GPR, we need to do it manually, otherwise we can rely
2985 // on the sort ordering of the enumeration since the other reg-classes
2987 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2990 default: llvm_unreachable("Invalid GPR number!");
2991 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2992 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2993 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2994 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2995 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2996 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2997 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2998 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3002 // Return the low-subreg of a given Q register.
3003 static unsigned getDRegFromQReg(unsigned QReg) {
3005 default: llvm_unreachable("expected a Q register!");
3006 case ARM::Q0: return ARM::D0;
3007 case ARM::Q1: return ARM::D2;
3008 case ARM::Q2: return ARM::D4;
3009 case ARM::Q3: return ARM::D6;
3010 case ARM::Q4: return ARM::D8;
3011 case ARM::Q5: return ARM::D10;
3012 case ARM::Q6: return ARM::D12;
3013 case ARM::Q7: return ARM::D14;
3014 case ARM::Q8: return ARM::D16;
3015 case ARM::Q9: return ARM::D18;
3016 case ARM::Q10: return ARM::D20;
3017 case ARM::Q11: return ARM::D22;
3018 case ARM::Q12: return ARM::D24;
3019 case ARM::Q13: return ARM::D26;
3020 case ARM::Q14: return ARM::D28;
3021 case ARM::Q15: return ARM::D30;
3025 /// Parse a register list.
3027 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3028 assert(Parser.getTok().is(AsmToken::LCurly) &&
3029 "Token is not a Left Curly Brace");
3030 SMLoc S = Parser.getTok().getLoc();
3031 Parser.Lex(); // Eat '{' token.
3032 SMLoc RegLoc = Parser.getTok().getLoc();
3034 // Check the first register in the list to see what register class
3035 // this is a list of.
3036 int Reg = tryParseRegister();
3038 return Error(RegLoc, "register expected");
3040 // The reglist instructions have at most 16 registers, so reserve
3041 // space for that many.
3043 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3045 // Allow Q regs and just interpret them as the two D sub-registers.
3046 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3047 Reg = getDRegFromQReg(Reg);
3048 EReg = MRI->getEncodingValue(Reg);
3049 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3052 const MCRegisterClass *RC;
3053 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3054 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3055 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3056 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3057 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3058 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3060 return Error(RegLoc, "invalid register in register list");
3062 // Store the register.
3063 EReg = MRI->getEncodingValue(Reg);
3064 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3066 // This starts immediately after the first register token in the list,
3067 // so we can see either a comma or a minus (range separator) as a legal
3069 while (Parser.getTok().is(AsmToken::Comma) ||
3070 Parser.getTok().is(AsmToken::Minus)) {
3071 if (Parser.getTok().is(AsmToken::Minus)) {
3072 Parser.Lex(); // Eat the minus.
3073 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3074 int EndReg = tryParseRegister();
3076 return Error(AfterMinusLoc, "register expected");
3077 // Allow Q regs and just interpret them as the two D sub-registers.
3078 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3079 EndReg = getDRegFromQReg(EndReg) + 1;
3080 // If the register is the same as the start reg, there's nothing
3084 // The register must be in the same register class as the first.
3085 if (!RC->contains(EndReg))
3086 return Error(AfterMinusLoc, "invalid register in register list");
3087 // Ranges must go from low to high.
3088 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3089 return Error(AfterMinusLoc, "bad range in register list");
3091 // Add all the registers in the range to the register list.
3092 while (Reg != EndReg) {
3093 Reg = getNextRegister(Reg);
3094 EReg = MRI->getEncodingValue(Reg);
3095 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3099 Parser.Lex(); // Eat the comma.
3100 RegLoc = Parser.getTok().getLoc();
3102 const AsmToken RegTok = Parser.getTok();
3103 Reg = tryParseRegister();
3105 return Error(RegLoc, "register expected");
3106 // Allow Q regs and just interpret them as the two D sub-registers.
3107 bool isQReg = false;
3108 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3109 Reg = getDRegFromQReg(Reg);
3112 // The register must be in the same register class as the first.
3113 if (!RC->contains(Reg))
3114 return Error(RegLoc, "invalid register in register list");
3115 // List must be monotonically increasing.
3116 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3117 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3118 Warning(RegLoc, "register list not in ascending order");
3120 return Error(RegLoc, "register list not in ascending order");
3122 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3123 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3124 ") in register list");
3127 // VFP register lists must also be contiguous.
3128 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3130 return Error(RegLoc, "non-contiguous register range");
3131 EReg = MRI->getEncodingValue(Reg);
3132 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3134 EReg = MRI->getEncodingValue(++Reg);
3135 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3139 if (Parser.getTok().isNot(AsmToken::RCurly))
3140 return Error(Parser.getTok().getLoc(), "'}' expected");
3141 SMLoc E = Parser.getTok().getEndLoc();
3142 Parser.Lex(); // Eat '}' token.
3144 // Push the register list operand.
3145 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3147 // The ARM system instruction variants for LDM/STM have a '^' token here.
3148 if (Parser.getTok().is(AsmToken::Caret)) {
3149 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3150 Parser.Lex(); // Eat '^' token.
3156 // Helper function to parse the lane index for vector lists.
3157 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3158 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3159 Index = 0; // Always return a defined index value.
3160 if (Parser.getTok().is(AsmToken::LBrac)) {
3161 Parser.Lex(); // Eat the '['.
3162 if (Parser.getTok().is(AsmToken::RBrac)) {
3163 // "Dn[]" is the 'all lanes' syntax.
3164 LaneKind = AllLanes;
3165 EndLoc = Parser.getTok().getEndLoc();
3166 Parser.Lex(); // Eat the ']'.
3167 return MatchOperand_Success;
3170 // There's an optional '#' token here. Normally there wouldn't be, but
3171 // inline assemble puts one in, and it's friendly to accept that.
3172 if (Parser.getTok().is(AsmToken::Hash))
3173 Parser.Lex(); // Eat '#' or '$'.
3175 const MCExpr *LaneIndex;
3176 SMLoc Loc = Parser.getTok().getLoc();
3177 if (getParser().parseExpression(LaneIndex)) {
3178 Error(Loc, "illegal expression");
3179 return MatchOperand_ParseFail;
3181 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3183 Error(Loc, "lane index must be empty or an integer");
3184 return MatchOperand_ParseFail;
3186 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3187 Error(Parser.getTok().getLoc(), "']' expected");
3188 return MatchOperand_ParseFail;
3190 EndLoc = Parser.getTok().getEndLoc();
3191 Parser.Lex(); // Eat the ']'.
3192 int64_t Val = CE->getValue();
3194 // FIXME: Make this range check context sensitive for .8, .16, .32.
3195 if (Val < 0 || Val > 7) {
3196 Error(Parser.getTok().getLoc(), "lane index out of range");
3197 return MatchOperand_ParseFail;
3200 LaneKind = IndexedLane;
3201 return MatchOperand_Success;
3204 return MatchOperand_Success;
3207 // parse a vector register list
3208 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3209 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3210 VectorLaneTy LaneKind;
3212 SMLoc S = Parser.getTok().getLoc();
3213 // As an extension (to match gas), support a plain D register or Q register
3214 // (without encosing curly braces) as a single or double entry list,
3216 if (Parser.getTok().is(AsmToken::Identifier)) {
3217 SMLoc E = Parser.getTok().getEndLoc();
3218 int Reg = tryParseRegister();
3220 return MatchOperand_NoMatch;
3221 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3222 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3223 if (Res != MatchOperand_Success)
3227 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3230 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3234 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3239 return MatchOperand_Success;
3241 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3242 Reg = getDRegFromQReg(Reg);
3243 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3244 if (Res != MatchOperand_Success)
3248 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3249 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3250 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3253 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3254 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3255 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3259 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3264 return MatchOperand_Success;
3266 Error(S, "vector register expected");
3267 return MatchOperand_ParseFail;
3270 if (Parser.getTok().isNot(AsmToken::LCurly))
3271 return MatchOperand_NoMatch;
3273 Parser.Lex(); // Eat '{' token.
3274 SMLoc RegLoc = Parser.getTok().getLoc();
3276 int Reg = tryParseRegister();
3278 Error(RegLoc, "register expected");
3279 return MatchOperand_ParseFail;
3283 unsigned FirstReg = Reg;
3284 // The list is of D registers, but we also allow Q regs and just interpret
3285 // them as the two D sub-registers.
3286 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3287 FirstReg = Reg = getDRegFromQReg(Reg);
3288 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3289 // it's ambiguous with four-register single spaced.
3295 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3296 return MatchOperand_ParseFail;
3298 while (Parser.getTok().is(AsmToken::Comma) ||
3299 Parser.getTok().is(AsmToken::Minus)) {
3300 if (Parser.getTok().is(AsmToken::Minus)) {
3302 Spacing = 1; // Register range implies a single spaced list.
3303 else if (Spacing == 2) {
3304 Error(Parser.getTok().getLoc(),
3305 "sequential registers in double spaced list");
3306 return MatchOperand_ParseFail;
3308 Parser.Lex(); // Eat the minus.
3309 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3310 int EndReg = tryParseRegister();
3312 Error(AfterMinusLoc, "register expected");
3313 return MatchOperand_ParseFail;
3315 // Allow Q regs and just interpret them as the two D sub-registers.
3316 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3317 EndReg = getDRegFromQReg(EndReg) + 1;
3318 // If the register is the same as the start reg, there's nothing
3322 // The register must be in the same register class as the first.
3323 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3324 Error(AfterMinusLoc, "invalid register in register list");
3325 return MatchOperand_ParseFail;
3327 // Ranges must go from low to high.
3329 Error(AfterMinusLoc, "bad range in register list");
3330 return MatchOperand_ParseFail;
3332 // Parse the lane specifier if present.
3333 VectorLaneTy NextLaneKind;
3334 unsigned NextLaneIndex;
3335 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3336 MatchOperand_Success)
3337 return MatchOperand_ParseFail;
3338 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3339 Error(AfterMinusLoc, "mismatched lane index in register list");
3340 return MatchOperand_ParseFail;
3343 // Add all the registers in the range to the register list.
3344 Count += EndReg - Reg;
3348 Parser.Lex(); // Eat the comma.
3349 RegLoc = Parser.getTok().getLoc();
3351 Reg = tryParseRegister();
3353 Error(RegLoc, "register expected");
3354 return MatchOperand_ParseFail;
3356 // vector register lists must be contiguous.
3357 // It's OK to use the enumeration values directly here rather, as the
3358 // VFP register classes have the enum sorted properly.
3360 // The list is of D registers, but we also allow Q regs and just interpret
3361 // them as the two D sub-registers.
3362 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3364 Spacing = 1; // Register range implies a single spaced list.
3365 else if (Spacing == 2) {
3367 "invalid register in double-spaced list (must be 'D' register')");
3368 return MatchOperand_ParseFail;
3370 Reg = getDRegFromQReg(Reg);
3371 if (Reg != OldReg + 1) {
3372 Error(RegLoc, "non-contiguous register range");
3373 return MatchOperand_ParseFail;
3377 // Parse the lane specifier if present.
3378 VectorLaneTy NextLaneKind;
3379 unsigned NextLaneIndex;
3380 SMLoc LaneLoc = Parser.getTok().getLoc();
3381 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3382 MatchOperand_Success)
3383 return MatchOperand_ParseFail;
3384 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3385 Error(LaneLoc, "mismatched lane index in register list");
3386 return MatchOperand_ParseFail;
3390 // Normal D register.
3391 // Figure out the register spacing (single or double) of the list if
3392 // we don't know it already.
3394 Spacing = 1 + (Reg == OldReg + 2);
3396 // Just check that it's contiguous and keep going.
3397 if (Reg != OldReg + Spacing) {
3398 Error(RegLoc, "non-contiguous register range");
3399 return MatchOperand_ParseFail;
3402 // Parse the lane specifier if present.
3403 VectorLaneTy NextLaneKind;
3404 unsigned NextLaneIndex;
3405 SMLoc EndLoc = Parser.getTok().getLoc();
3406 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3407 return MatchOperand_ParseFail;
3408 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3409 Error(EndLoc, "mismatched lane index in register list");
3410 return MatchOperand_ParseFail;
3414 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3415 Error(Parser.getTok().getLoc(), "'}' expected");
3416 return MatchOperand_ParseFail;
3418 E = Parser.getTok().getEndLoc();
3419 Parser.Lex(); // Eat '}' token.
3423 // Two-register operands have been converted to the
3424 // composite register classes.
3426 const MCRegisterClass *RC = (Spacing == 1) ?
3427 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3428 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3429 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3432 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3433 (Spacing == 2), S, E));
3436 // Two-register operands have been converted to the
3437 // composite register classes.
3439 const MCRegisterClass *RC = (Spacing == 1) ?
3440 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3441 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3442 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3444 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3449 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3455 return MatchOperand_Success;
3458 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3459 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3460 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3461 SMLoc S = Parser.getTok().getLoc();
3462 const AsmToken &Tok = Parser.getTok();
3465 if (Tok.is(AsmToken::Identifier)) {
3466 StringRef OptStr = Tok.getString();
3468 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3469 .Case("sy", ARM_MB::SY)
3470 .Case("st", ARM_MB::ST)
3471 .Case("ld", ARM_MB::LD)
3472 .Case("sh", ARM_MB::ISH)
3473 .Case("ish", ARM_MB::ISH)
3474 .Case("shst", ARM_MB::ISHST)
3475 .Case("ishst", ARM_MB::ISHST)
3476 .Case("ishld", ARM_MB::ISHLD)
3477 .Case("nsh", ARM_MB::NSH)
3478 .Case("un", ARM_MB::NSH)
3479 .Case("nshst", ARM_MB::NSHST)
3480 .Case("nshld", ARM_MB::NSHLD)
3481 .Case("unst", ARM_MB::NSHST)
3482 .Case("osh", ARM_MB::OSH)
3483 .Case("oshst", ARM_MB::OSHST)
3484 .Case("oshld", ARM_MB::OSHLD)
3487 // ishld, oshld, nshld and ld are only available from ARMv8.
3488 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3489 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3493 return MatchOperand_NoMatch;
3495 Parser.Lex(); // Eat identifier token.
3496 } else if (Tok.is(AsmToken::Hash) ||
3497 Tok.is(AsmToken::Dollar) ||
3498 Tok.is(AsmToken::Integer)) {
3499 if (Parser.getTok().isNot(AsmToken::Integer))
3500 Parser.Lex(); // Eat '#' or '$'.
3501 SMLoc Loc = Parser.getTok().getLoc();
3503 const MCExpr *MemBarrierID;
3504 if (getParser().parseExpression(MemBarrierID)) {
3505 Error(Loc, "illegal expression");
3506 return MatchOperand_ParseFail;
3509 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3511 Error(Loc, "constant expression expected");
3512 return MatchOperand_ParseFail;
3515 int Val = CE->getValue();
3517 Error(Loc, "immediate value out of range");
3518 return MatchOperand_ParseFail;
3521 Opt = ARM_MB::RESERVED_0 + Val;
3523 return MatchOperand_ParseFail;
3525 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3526 return MatchOperand_Success;
3529 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3530 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3531 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3532 SMLoc S = Parser.getTok().getLoc();
3533 const AsmToken &Tok = Parser.getTok();
3536 if (Tok.is(AsmToken::Identifier)) {
3537 StringRef OptStr = Tok.getString();
3539 if (OptStr.lower() == "sy")
3542 return MatchOperand_NoMatch;
3544 Parser.Lex(); // Eat identifier token.
3545 } else if (Tok.is(AsmToken::Hash) ||
3546 Tok.is(AsmToken::Dollar) ||
3547 Tok.is(AsmToken::Integer)) {
3548 if (Parser.getTok().isNot(AsmToken::Integer))
3549 Parser.Lex(); // Eat '#' or '$'.
3550 SMLoc Loc = Parser.getTok().getLoc();
3552 const MCExpr *ISBarrierID;
3553 if (getParser().parseExpression(ISBarrierID)) {
3554 Error(Loc, "illegal expression");
3555 return MatchOperand_ParseFail;
3558 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3560 Error(Loc, "constant expression expected");
3561 return MatchOperand_ParseFail;
3564 int Val = CE->getValue();
3566 Error(Loc, "immediate value out of range");
3567 return MatchOperand_ParseFail;
3570 Opt = ARM_ISB::RESERVED_0 + Val;
3572 return MatchOperand_ParseFail;
3574 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3575 (ARM_ISB::InstSyncBOpt)Opt, S));
3576 return MatchOperand_Success;
3580 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3581 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3582 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3583 SMLoc S = Parser.getTok().getLoc();
3584 const AsmToken &Tok = Parser.getTok();
3585 if (!Tok.is(AsmToken::Identifier))
3586 return MatchOperand_NoMatch;
3587 StringRef IFlagsStr = Tok.getString();
3589 // An iflags string of "none" is interpreted to mean that none of the AIF
3590 // bits are set. Not a terribly useful instruction, but a valid encoding.
3591 unsigned IFlags = 0;
3592 if (IFlagsStr != "none") {
3593 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3594 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3595 .Case("a", ARM_PROC::A)
3596 .Case("i", ARM_PROC::I)
3597 .Case("f", ARM_PROC::F)
3600 // If some specific iflag is already set, it means that some letter is
3601 // present more than once, this is not acceptable.
3602 if (Flag == ~0U || (IFlags & Flag))
3603 return MatchOperand_NoMatch;
3609 Parser.Lex(); // Eat identifier token.
3610 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3611 return MatchOperand_Success;
3614 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3615 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3616 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3617 SMLoc S = Parser.getTok().getLoc();
3618 const AsmToken &Tok = Parser.getTok();
3619 if (!Tok.is(AsmToken::Identifier))
3620 return MatchOperand_NoMatch;
3621 StringRef Mask = Tok.getString();
3624 // See ARMv6-M 10.1.1
3625 std::string Name = Mask.lower();
3626 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3627 // Note: in the documentation:
3628 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3629 // for MSR APSR_nzcvq.
3630 // but we do make it an alias here. This is so to get the "mask encoding"
3631 // bits correct on MSR APSR writes.
3633 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3634 // should really only be allowed when writing a special register. Note
3635 // they get dropped in the MRS instruction reading a special register as
3636 // the SYSm field is only 8 bits.
3638 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3639 // includes the DSP extension but that is not checked.
3640 .Case("apsr", 0x800)
3641 .Case("apsr_nzcvq", 0x800)
3642 .Case("apsr_g", 0x400)
3643 .Case("apsr_nzcvqg", 0xc00)
3644 .Case("iapsr", 0x801)
3645 .Case("iapsr_nzcvq", 0x801)
3646 .Case("iapsr_g", 0x401)
3647 .Case("iapsr_nzcvqg", 0xc01)
3648 .Case("eapsr", 0x802)
3649 .Case("eapsr_nzcvq", 0x802)
3650 .Case("eapsr_g", 0x402)
3651 .Case("eapsr_nzcvqg", 0xc02)
3652 .Case("xpsr", 0x803)
3653 .Case("xpsr_nzcvq", 0x803)
3654 .Case("xpsr_g", 0x403)
3655 .Case("xpsr_nzcvqg", 0xc03)
3656 .Case("ipsr", 0x805)
3657 .Case("epsr", 0x806)
3658 .Case("iepsr", 0x807)
3661 .Case("primask", 0x810)
3662 .Case("basepri", 0x811)
3663 .Case("basepri_max", 0x812)
3664 .Case("faultmask", 0x813)
3665 .Case("control", 0x814)
3668 if (FlagsVal == ~0U)
3669 return MatchOperand_NoMatch;
3671 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3672 // basepri, basepri_max and faultmask only valid for V7m.
3673 return MatchOperand_NoMatch;
3675 Parser.Lex(); // Eat identifier token.
3676 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3677 return MatchOperand_Success;
3680 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3681 size_t Start = 0, Next = Mask.find('_');
3682 StringRef Flags = "";
3683 std::string SpecReg = Mask.slice(Start, Next).lower();
3684 if (Next != StringRef::npos)
3685 Flags = Mask.slice(Next+1, Mask.size());
3687 // FlagsVal contains the complete mask:
3689 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3690 unsigned FlagsVal = 0;
3692 if (SpecReg == "apsr") {
3693 FlagsVal = StringSwitch<unsigned>(Flags)
3694 .Case("nzcvq", 0x8) // same as CPSR_f
3695 .Case("g", 0x4) // same as CPSR_s
3696 .Case("nzcvqg", 0xc) // same as CPSR_fs
3699 if (FlagsVal == ~0U) {
3701 return MatchOperand_NoMatch;
3703 FlagsVal = 8; // No flag
3705 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3706 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3707 if (Flags == "all" || Flags == "")
3709 for (int i = 0, e = Flags.size(); i != e; ++i) {
3710 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3717 // If some specific flag is already set, it means that some letter is
3718 // present more than once, this is not acceptable.
3719 if (FlagsVal == ~0U || (FlagsVal & Flag))
3720 return MatchOperand_NoMatch;
3723 } else // No match for special register.
3724 return MatchOperand_NoMatch;
3726 // Special register without flags is NOT equivalent to "fc" flags.
3727 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3728 // two lines would enable gas compatibility at the expense of breaking
3734 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3735 if (SpecReg == "spsr")
3738 Parser.Lex(); // Eat identifier token.
3739 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3740 return MatchOperand_Success;
3743 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3744 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3745 int Low, int High) {
3746 const AsmToken &Tok = Parser.getTok();
3747 if (Tok.isNot(AsmToken::Identifier)) {
3748 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3749 return MatchOperand_ParseFail;
3751 StringRef ShiftName = Tok.getString();
3752 std::string LowerOp = Op.lower();
3753 std::string UpperOp = Op.upper();
3754 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3755 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3756 return MatchOperand_ParseFail;
3758 Parser.Lex(); // Eat shift type token.
3760 // There must be a '#' and a shift amount.
3761 if (Parser.getTok().isNot(AsmToken::Hash) &&
3762 Parser.getTok().isNot(AsmToken::Dollar)) {
3763 Error(Parser.getTok().getLoc(), "'#' expected");
3764 return MatchOperand_ParseFail;
3766 Parser.Lex(); // Eat hash token.
3768 const MCExpr *ShiftAmount;
3769 SMLoc Loc = Parser.getTok().getLoc();
3771 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3772 Error(Loc, "illegal expression");
3773 return MatchOperand_ParseFail;
3775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3777 Error(Loc, "constant expression expected");
3778 return MatchOperand_ParseFail;
3780 int Val = CE->getValue();
3781 if (Val < Low || Val > High) {
3782 Error(Loc, "immediate value out of range");
3783 return MatchOperand_ParseFail;
3786 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3788 return MatchOperand_Success;
3791 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3792 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3793 const AsmToken &Tok = Parser.getTok();
3794 SMLoc S = Tok.getLoc();
3795 if (Tok.isNot(AsmToken::Identifier)) {
3796 Error(S, "'be' or 'le' operand expected");
3797 return MatchOperand_ParseFail;
3799 int Val = StringSwitch<int>(Tok.getString().lower())
3803 Parser.Lex(); // Eat the token.
3806 Error(S, "'be' or 'le' operand expected");
3807 return MatchOperand_ParseFail;
3809 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3811 S, Tok.getEndLoc()));
3812 return MatchOperand_Success;
3815 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3816 /// instructions. Legal values are:
3817 /// lsl #n 'n' in [0,31]
3818 /// asr #n 'n' in [1,32]
3819 /// n == 32 encoded as n == 0.
3820 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3821 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3822 const AsmToken &Tok = Parser.getTok();
3823 SMLoc S = Tok.getLoc();
3824 if (Tok.isNot(AsmToken::Identifier)) {
3825 Error(S, "shift operator 'asr' or 'lsl' expected");
3826 return MatchOperand_ParseFail;
3828 StringRef ShiftName = Tok.getString();
3830 if (ShiftName == "lsl" || ShiftName == "LSL")
3832 else if (ShiftName == "asr" || ShiftName == "ASR")
3835 Error(S, "shift operator 'asr' or 'lsl' expected");
3836 return MatchOperand_ParseFail;
3838 Parser.Lex(); // Eat the operator.
3840 // A '#' and a shift amount.
3841 if (Parser.getTok().isNot(AsmToken::Hash) &&
3842 Parser.getTok().isNot(AsmToken::Dollar)) {
3843 Error(Parser.getTok().getLoc(), "'#' expected");
3844 return MatchOperand_ParseFail;
3846 Parser.Lex(); // Eat hash token.
3847 SMLoc ExLoc = Parser.getTok().getLoc();
3849 const MCExpr *ShiftAmount;
3851 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3852 Error(ExLoc, "malformed shift expression");
3853 return MatchOperand_ParseFail;
3855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3857 Error(ExLoc, "shift amount must be an immediate");
3858 return MatchOperand_ParseFail;
3861 int64_t Val = CE->getValue();
3863 // Shift amount must be in [1,32]
3864 if (Val < 1 || Val > 32) {
3865 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3866 return MatchOperand_ParseFail;
3868 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3869 if (isThumb() && Val == 32) {
3870 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3871 return MatchOperand_ParseFail;
3873 if (Val == 32) Val = 0;
3875 // Shift amount must be in [1,32]
3876 if (Val < 0 || Val > 31) {
3877 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3878 return MatchOperand_ParseFail;
3882 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3884 return MatchOperand_Success;
3887 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3888 /// of instructions. Legal values are:
3889 /// ror #n 'n' in {0, 8, 16, 24}
3890 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3891 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3892 const AsmToken &Tok = Parser.getTok();
3893 SMLoc S = Tok.getLoc();
3894 if (Tok.isNot(AsmToken::Identifier))
3895 return MatchOperand_NoMatch;
3896 StringRef ShiftName = Tok.getString();
3897 if (ShiftName != "ror" && ShiftName != "ROR")
3898 return MatchOperand_NoMatch;
3899 Parser.Lex(); // Eat the operator.
3901 // A '#' and a rotate amount.
3902 if (Parser.getTok().isNot(AsmToken::Hash) &&
3903 Parser.getTok().isNot(AsmToken::Dollar)) {
3904 Error(Parser.getTok().getLoc(), "'#' expected");
3905 return MatchOperand_ParseFail;
3907 Parser.Lex(); // Eat hash token.
3908 SMLoc ExLoc = Parser.getTok().getLoc();
3910 const MCExpr *ShiftAmount;
3912 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3913 Error(ExLoc, "malformed rotate expression");
3914 return MatchOperand_ParseFail;
3916 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3918 Error(ExLoc, "rotate amount must be an immediate");
3919 return MatchOperand_ParseFail;
3922 int64_t Val = CE->getValue();
3923 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3924 // normally, zero is represented in asm by omitting the rotate operand
3926 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3927 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
3928 return MatchOperand_ParseFail;
3931 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
3933 return MatchOperand_Success;
3936 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3937 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3938 SMLoc S = Parser.getTok().getLoc();
3939 // The bitfield descriptor is really two operands, the LSB and the width.
3940 if (Parser.getTok().isNot(AsmToken::Hash) &&
3941 Parser.getTok().isNot(AsmToken::Dollar)) {
3942 Error(Parser.getTok().getLoc(), "'#' expected");
3943 return MatchOperand_ParseFail;
3945 Parser.Lex(); // Eat hash token.
3947 const MCExpr *LSBExpr;
3948 SMLoc E = Parser.getTok().getLoc();
3949 if (getParser().parseExpression(LSBExpr)) {
3950 Error(E, "malformed immediate expression");
3951 return MatchOperand_ParseFail;
3953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3955 Error(E, "'lsb' operand must be an immediate");
3956 return MatchOperand_ParseFail;
3959 int64_t LSB = CE->getValue();
3960 // The LSB must be in the range [0,31]
3961 if (LSB < 0 || LSB > 31) {
3962 Error(E, "'lsb' operand must be in the range [0,31]");
3963 return MatchOperand_ParseFail;
3965 E = Parser.getTok().getLoc();
3967 // Expect another immediate operand.
3968 if (Parser.getTok().isNot(AsmToken::Comma)) {
3969 Error(Parser.getTok().getLoc(), "too few operands");
3970 return MatchOperand_ParseFail;
3972 Parser.Lex(); // Eat hash token.
3973 if (Parser.getTok().isNot(AsmToken::Hash) &&
3974 Parser.getTok().isNot(AsmToken::Dollar)) {
3975 Error(Parser.getTok().getLoc(), "'#' expected");
3976 return MatchOperand_ParseFail;
3978 Parser.Lex(); // Eat hash token.
3980 const MCExpr *WidthExpr;
3982 if (getParser().parseExpression(WidthExpr, EndLoc)) {
3983 Error(E, "malformed immediate expression");
3984 return MatchOperand_ParseFail;
3986 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3988 Error(E, "'width' operand must be an immediate");
3989 return MatchOperand_ParseFail;
3992 int64_t Width = CE->getValue();
3993 // The LSB must be in the range [1,32-lsb]
3994 if (Width < 1 || Width > 32 - LSB) {
3995 Error(E, "'width' operand must be in the range [1,32-lsb]");
3996 return MatchOperand_ParseFail;
3999 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
4001 return MatchOperand_Success;
4004 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4005 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4006 // Check for a post-index addressing register operand. Specifically:
4007 // postidx_reg := '+' register {, shift}
4008 // | '-' register {, shift}
4009 // | register {, shift}
4011 // This method must return MatchOperand_NoMatch without consuming any tokens
4012 // in the case where there is no match, as other alternatives take other
4014 AsmToken Tok = Parser.getTok();
4015 SMLoc S = Tok.getLoc();
4016 bool haveEaten = false;
4018 if (Tok.is(AsmToken::Plus)) {
4019 Parser.Lex(); // Eat the '+' token.
4021 } else if (Tok.is(AsmToken::Minus)) {
4022 Parser.Lex(); // Eat the '-' token.
4027 SMLoc E = Parser.getTok().getEndLoc();
4028 int Reg = tryParseRegister();
4031 return MatchOperand_NoMatch;
4032 Error(Parser.getTok().getLoc(), "register expected");
4033 return MatchOperand_ParseFail;
4036 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4037 unsigned ShiftImm = 0;
4038 if (Parser.getTok().is(AsmToken::Comma)) {
4039 Parser.Lex(); // Eat the ','.
4040 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4041 return MatchOperand_ParseFail;
4043 // FIXME: Only approximates end...may include intervening whitespace.
4044 E = Parser.getTok().getLoc();
4047 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4050 return MatchOperand_Success;
4053 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4054 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4055 // Check for a post-index addressing register operand. Specifically:
4056 // am3offset := '+' register
4063 // This method must return MatchOperand_NoMatch without consuming any tokens
4064 // in the case where there is no match, as other alternatives take other
4066 AsmToken Tok = Parser.getTok();
4067 SMLoc S = Tok.getLoc();
4069 // Do immediates first, as we always parse those if we have a '#'.
4070 if (Parser.getTok().is(AsmToken::Hash) ||
4071 Parser.getTok().is(AsmToken::Dollar)) {
4072 Parser.Lex(); // Eat '#' or '$'.
4073 // Explicitly look for a '-', as we need to encode negative zero
4075 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4076 const MCExpr *Offset;
4078 if (getParser().parseExpression(Offset, E))
4079 return MatchOperand_ParseFail;
4080 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4082 Error(S, "constant expression expected");
4083 return MatchOperand_ParseFail;
4085 // Negative zero is encoded as the flag value INT32_MIN.
4086 int32_t Val = CE->getValue();
4087 if (isNegative && Val == 0)
4091 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4093 return MatchOperand_Success;
4097 bool haveEaten = false;
4099 if (Tok.is(AsmToken::Plus)) {
4100 Parser.Lex(); // Eat the '+' token.
4102 } else if (Tok.is(AsmToken::Minus)) {
4103 Parser.Lex(); // Eat the '-' token.
4108 Tok = Parser.getTok();
4109 int Reg = tryParseRegister();
4112 return MatchOperand_NoMatch;
4113 Error(Tok.getLoc(), "register expected");
4114 return MatchOperand_ParseFail;
4117 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4118 0, S, Tok.getEndLoc()));
4120 return MatchOperand_Success;
4123 /// Convert parsed operands to MCInst. Needed here because this instruction
4124 /// only has two register operands, but multiplication is commutative so
4125 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4127 cvtThumbMultiply(MCInst &Inst,
4128 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4129 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4130 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4131 // If we have a three-operand form, make sure to set Rn to be the operand
4132 // that isn't the same as Rd.
4134 if (Operands.size() == 6 &&
4135 ((ARMOperand*)Operands[4])->getReg() ==
4136 ((ARMOperand*)Operands[3])->getReg())
4138 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4139 Inst.addOperand(Inst.getOperand(0));
4140 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4144 cvtThumbBranches(MCInst &Inst,
4145 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4146 int CondOp = -1, ImmOp = -1;
4147 switch(Inst.getOpcode()) {
4149 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4152 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4154 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4156 // first decide whether or not the branch should be conditional
4157 // by looking at it's location relative to an IT block
4159 // inside an IT block we cannot have any conditional branches. any
4160 // such instructions needs to be converted to unconditional form
4161 switch(Inst.getOpcode()) {
4162 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4163 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4166 // outside IT blocks we can only have unconditional branches with AL
4167 // condition code or conditional branches with non-AL condition code
4168 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4169 switch(Inst.getOpcode()) {
4172 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4176 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4181 // now decide on encoding size based on branch target range
4182 switch(Inst.getOpcode()) {
4183 // classify tB as either t2B or t1B based on range of immediate operand
4185 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4186 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4187 Inst.setOpcode(ARM::t2B);
4190 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4192 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4193 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4194 Inst.setOpcode(ARM::t2Bcc);
4198 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4199 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4202 /// Parse an ARM memory expression, return false if successful else return true
4203 /// or an error. The first token must be a '[' when called.
4205 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4207 assert(Parser.getTok().is(AsmToken::LBrac) &&
4208 "Token is not a Left Bracket");
4209 S = Parser.getTok().getLoc();
4210 Parser.Lex(); // Eat left bracket token.
4212 const AsmToken &BaseRegTok = Parser.getTok();
4213 int BaseRegNum = tryParseRegister();
4214 if (BaseRegNum == -1)
4215 return Error(BaseRegTok.getLoc(), "register expected");
4217 // The next token must either be a comma, a colon or a closing bracket.
4218 const AsmToken &Tok = Parser.getTok();
4219 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4220 !Tok.is(AsmToken::RBrac))
4221 return Error(Tok.getLoc(), "malformed memory operand");
4223 if (Tok.is(AsmToken::RBrac)) {
4224 E = Tok.getEndLoc();
4225 Parser.Lex(); // Eat right bracket token.
4227 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4228 0, 0, false, S, E));
4230 // If there's a pre-indexing writeback marker, '!', just add it as a token
4231 // operand. It's rather odd, but syntactically valid.
4232 if (Parser.getTok().is(AsmToken::Exclaim)) {
4233 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4234 Parser.Lex(); // Eat the '!'.
4240 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4241 "Lost colon or comma in memory operand?!");
4242 if (Tok.is(AsmToken::Comma)) {
4243 Parser.Lex(); // Eat the comma.
4246 // If we have a ':', it's an alignment specifier.
4247 if (Parser.getTok().is(AsmToken::Colon)) {
4248 Parser.Lex(); // Eat the ':'.
4249 E = Parser.getTok().getLoc();
4252 if (getParser().parseExpression(Expr))
4255 // The expression has to be a constant. Memory references with relocations
4256 // don't come through here, as they use the <label> forms of the relevant
4258 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4260 return Error (E, "constant expression expected");
4263 switch (CE->getValue()) {
4266 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4267 case 16: Align = 2; break;
4268 case 32: Align = 4; break;
4269 case 64: Align = 8; break;
4270 case 128: Align = 16; break;
4271 case 256: Align = 32; break;
4274 // Now we should have the closing ']'
4275 if (Parser.getTok().isNot(AsmToken::RBrac))
4276 return Error(Parser.getTok().getLoc(), "']' expected");
4277 E = Parser.getTok().getEndLoc();
4278 Parser.Lex(); // Eat right bracket token.
4280 // Don't worry about range checking the value here. That's handled by
4281 // the is*() predicates.
4282 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4283 ARM_AM::no_shift, 0, Align,
4286 // If there's a pre-indexing writeback marker, '!', just add it as a token
4288 if (Parser.getTok().is(AsmToken::Exclaim)) {
4289 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4290 Parser.Lex(); // Eat the '!'.
4296 // If we have a '#', it's an immediate offset, else assume it's a register
4297 // offset. Be friendly and also accept a plain integer (without a leading
4298 // hash) for gas compatibility.
4299 if (Parser.getTok().is(AsmToken::Hash) ||
4300 Parser.getTok().is(AsmToken::Dollar) ||
4301 Parser.getTok().is(AsmToken::Integer)) {
4302 if (Parser.getTok().isNot(AsmToken::Integer))
4303 Parser.Lex(); // Eat '#' or '$'.
4304 E = Parser.getTok().getLoc();
4306 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4307 const MCExpr *Offset;
4308 if (getParser().parseExpression(Offset))
4311 // The expression has to be a constant. Memory references with relocations
4312 // don't come through here, as they use the <label> forms of the relevant
4314 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4316 return Error (E, "constant expression expected");
4318 // If the constant was #-0, represent it as INT32_MIN.
4319 int32_t Val = CE->getValue();
4320 if (isNegative && Val == 0)
4321 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4323 // Now we should have the closing ']'
4324 if (Parser.getTok().isNot(AsmToken::RBrac))
4325 return Error(Parser.getTok().getLoc(), "']' expected");
4326 E = Parser.getTok().getEndLoc();
4327 Parser.Lex(); // Eat right bracket token.
4329 // Don't worry about range checking the value here. That's handled by
4330 // the is*() predicates.
4331 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4332 ARM_AM::no_shift, 0, 0,
4335 // If there's a pre-indexing writeback marker, '!', just add it as a token
4337 if (Parser.getTok().is(AsmToken::Exclaim)) {
4338 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4339 Parser.Lex(); // Eat the '!'.
4345 // The register offset is optionally preceded by a '+' or '-'
4346 bool isNegative = false;
4347 if (Parser.getTok().is(AsmToken::Minus)) {
4349 Parser.Lex(); // Eat the '-'.
4350 } else if (Parser.getTok().is(AsmToken::Plus)) {
4352 Parser.Lex(); // Eat the '+'.
4355 E = Parser.getTok().getLoc();
4356 int OffsetRegNum = tryParseRegister();
4357 if (OffsetRegNum == -1)
4358 return Error(E, "register expected");
4360 // If there's a shift operator, handle it.
4361 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4362 unsigned ShiftImm = 0;
4363 if (Parser.getTok().is(AsmToken::Comma)) {
4364 Parser.Lex(); // Eat the ','.
4365 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4369 // Now we should have the closing ']'
4370 if (Parser.getTok().isNot(AsmToken::RBrac))
4371 return Error(Parser.getTok().getLoc(), "']' expected");
4372 E = Parser.getTok().getEndLoc();
4373 Parser.Lex(); // Eat right bracket token.
4375 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4376 ShiftType, ShiftImm, 0, isNegative,
4379 // If there's a pre-indexing writeback marker, '!', just add it as a token
4381 if (Parser.getTok().is(AsmToken::Exclaim)) {
4382 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4383 Parser.Lex(); // Eat the '!'.
4389 /// parseMemRegOffsetShift - one of these two:
4390 /// ( lsl | lsr | asr | ror ) , # shift_amount
4392 /// return true if it parses a shift otherwise it returns false.
4393 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4395 SMLoc Loc = Parser.getTok().getLoc();
4396 const AsmToken &Tok = Parser.getTok();
4397 if (Tok.isNot(AsmToken::Identifier))
4399 StringRef ShiftName = Tok.getString();
4400 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4401 ShiftName == "asl" || ShiftName == "ASL")
4403 else if (ShiftName == "lsr" || ShiftName == "LSR")
4405 else if (ShiftName == "asr" || ShiftName == "ASR")
4407 else if (ShiftName == "ror" || ShiftName == "ROR")
4409 else if (ShiftName == "rrx" || ShiftName == "RRX")
4412 return Error(Loc, "illegal shift operator");
4413 Parser.Lex(); // Eat shift type token.
4415 // rrx stands alone.
4417 if (St != ARM_AM::rrx) {
4418 Loc = Parser.getTok().getLoc();
4419 // A '#' and a shift amount.
4420 const AsmToken &HashTok = Parser.getTok();
4421 if (HashTok.isNot(AsmToken::Hash) &&
4422 HashTok.isNot(AsmToken::Dollar))
4423 return Error(HashTok.getLoc(), "'#' expected");
4424 Parser.Lex(); // Eat hash token.
4427 if (getParser().parseExpression(Expr))
4429 // Range check the immediate.
4430 // lsl, ror: 0 <= imm <= 31
4431 // lsr, asr: 0 <= imm <= 32
4432 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4434 return Error(Loc, "shift amount must be an immediate");
4435 int64_t Imm = CE->getValue();
4437 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4438 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4439 return Error(Loc, "immediate shift value out of range");
4440 // If <ShiftTy> #0, turn it into a no_shift.
4443 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4452 /// parseFPImm - A floating point immediate expression operand.
4453 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4454 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4455 // Anything that can accept a floating point constant as an operand
4456 // needs to go through here, as the regular parseExpression is
4459 // This routine still creates a generic Immediate operand, containing
4460 // a bitcast of the 64-bit floating point value. The various operands
4461 // that accept floats can check whether the value is valid for them
4462 // via the standard is*() predicates.
4464 SMLoc S = Parser.getTok().getLoc();
4466 if (Parser.getTok().isNot(AsmToken::Hash) &&
4467 Parser.getTok().isNot(AsmToken::Dollar))
4468 return MatchOperand_NoMatch;
4470 // Disambiguate the VMOV forms that can accept an FP immediate.
4471 // vmov.f32 <sreg>, #imm
4472 // vmov.f64 <dreg>, #imm
4473 // vmov.f32 <dreg>, #imm @ vector f32x2
4474 // vmov.f32 <qreg>, #imm @ vector f32x4
4476 // There are also the NEON VMOV instructions which expect an
4477 // integer constant. Make sure we don't try to parse an FPImm
4479 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4480 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4481 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4482 TyOp->getToken() != ".f64"))
4483 return MatchOperand_NoMatch;
4485 Parser.Lex(); // Eat '#' or '$'.
4487 // Handle negation, as that still comes through as a separate token.
4488 bool isNegative = false;
4489 if (Parser.getTok().is(AsmToken::Minus)) {
4493 const AsmToken &Tok = Parser.getTok();
4494 SMLoc Loc = Tok.getLoc();
4495 if (Tok.is(AsmToken::Real)) {
4496 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4497 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4498 // If we had a '-' in front, toggle the sign bit.
4499 IntVal ^= (uint64_t)isNegative << 31;
4500 Parser.Lex(); // Eat the token.
4501 Operands.push_back(ARMOperand::CreateImm(
4502 MCConstantExpr::Create(IntVal, getContext()),
4503 S, Parser.getTok().getLoc()));
4504 return MatchOperand_Success;
4506 // Also handle plain integers. Instructions which allow floating point
4507 // immediates also allow a raw encoded 8-bit value.
4508 if (Tok.is(AsmToken::Integer)) {
4509 int64_t Val = Tok.getIntVal();
4510 Parser.Lex(); // Eat the token.
4511 if (Val > 255 || Val < 0) {
4512 Error(Loc, "encoded floating point value out of range");
4513 return MatchOperand_ParseFail;
4515 double RealVal = ARM_AM::getFPImmFloat(Val);
4516 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4517 Operands.push_back(ARMOperand::CreateImm(
4518 MCConstantExpr::Create(Val, getContext()), S,
4519 Parser.getTok().getLoc()));
4520 return MatchOperand_Success;
4523 Error(Loc, "invalid floating point immediate");
4524 return MatchOperand_ParseFail;
4527 /// Parse a arm instruction operand. For now this parses the operand regardless
4528 /// of the mnemonic.
4529 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4530 StringRef Mnemonic) {
4533 // Check if the current operand has a custom associated parser, if so, try to
4534 // custom parse the operand, or fallback to the general approach.
4535 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4536 if (ResTy == MatchOperand_Success)
4538 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4539 // there was a match, but an error occurred, in which case, just return that
4540 // the operand parsing failed.
4541 if (ResTy == MatchOperand_ParseFail)
4544 switch (getLexer().getKind()) {
4546 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4548 case AsmToken::Identifier: {
4549 // If we've seen a branch mnemonic, the next operand must be a label. This
4550 // is true even if the label is a register name. So "br r1" means branch to
4552 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4554 if (!tryParseRegisterWithWriteBack(Operands))
4556 int Res = tryParseShiftRegister(Operands);
4557 if (Res == 0) // success
4559 else if (Res == -1) // irrecoverable error
4561 // If this is VMRS, check for the apsr_nzcv operand.
4562 if (Mnemonic == "vmrs" &&
4563 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4564 S = Parser.getTok().getLoc();
4566 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4571 // Fall though for the Identifier case that is not a register or a
4574 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4575 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4576 case AsmToken::String: // quoted label names.
4577 case AsmToken::Dot: { // . as a branch target
4578 // This was not a register so parse other operands that start with an
4579 // identifier (like labels) as expressions and create them as immediates.
4580 const MCExpr *IdVal;
4581 S = Parser.getTok().getLoc();
4582 if (getParser().parseExpression(IdVal))
4584 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4585 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4588 case AsmToken::LBrac:
4589 return parseMemory(Operands);
4590 case AsmToken::LCurly:
4591 return parseRegisterList(Operands);
4592 case AsmToken::Dollar:
4593 case AsmToken::Hash: {
4594 // #42 -> immediate.
4595 S = Parser.getTok().getLoc();
4598 if (Parser.getTok().isNot(AsmToken::Colon)) {
4599 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4600 const MCExpr *ImmVal;
4601 if (getParser().parseExpression(ImmVal))
4603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4605 int32_t Val = CE->getValue();
4606 if (isNegative && Val == 0)
4607 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4609 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4610 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4612 // There can be a trailing '!' on operands that we want as a separate
4613 // '!' Token operand. Handle that here. For example, the compatibilty
4614 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4615 if (Parser.getTok().is(AsmToken::Exclaim)) {
4616 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4617 Parser.getTok().getLoc()));
4618 Parser.Lex(); // Eat exclaim token
4622 // w/ a ':' after the '#', it's just like a plain ':'.
4625 case AsmToken::Colon: {
4626 // ":lower16:" and ":upper16:" expression prefixes
4627 // FIXME: Check it's an expression prefix,
4628 // e.g. (FOO - :lower16:BAR) isn't legal.
4629 ARMMCExpr::VariantKind RefKind;
4630 if (parsePrefix(RefKind))
4633 const MCExpr *SubExprVal;
4634 if (getParser().parseExpression(SubExprVal))
4637 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4639 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4640 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4646 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4647 // :lower16: and :upper16:.
4648 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4649 RefKind = ARMMCExpr::VK_ARM_None;
4651 // :lower16: and :upper16: modifiers
4652 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4653 Parser.Lex(); // Eat ':'
4655 if (getLexer().isNot(AsmToken::Identifier)) {
4656 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4660 StringRef IDVal = Parser.getTok().getIdentifier();
4661 if (IDVal == "lower16") {
4662 RefKind = ARMMCExpr::VK_ARM_LO16;
4663 } else if (IDVal == "upper16") {
4664 RefKind = ARMMCExpr::VK_ARM_HI16;
4666 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4671 if (getLexer().isNot(AsmToken::Colon)) {
4672 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4675 Parser.Lex(); // Eat the last ':'
4679 /// \brief Given a mnemonic, split out possible predication code and carry
4680 /// setting letters to form a canonical mnemonic and flags.
4682 // FIXME: Would be nice to autogen this.
4683 // FIXME: This is a bit of a maze of special cases.
4684 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4685 unsigned &PredicationCode,
4687 unsigned &ProcessorIMod,
4688 StringRef &ITMask) {
4689 PredicationCode = ARMCC::AL;
4690 CarrySetting = false;
4693 // Ignore some mnemonics we know aren't predicated forms.
4695 // FIXME: Would be nice to autogen this.
4696 if ((Mnemonic == "movs" && isThumb()) ||
4697 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4698 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4699 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4700 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4701 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
4702 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4703 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4704 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4705 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
4706 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4707 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4708 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
4711 // First, split out any predication code. Ignore mnemonics we know aren't
4712 // predicated but do have a carry-set and so weren't caught above.
4713 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4714 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4715 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4716 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4717 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4718 .Case("eq", ARMCC::EQ)
4719 .Case("ne", ARMCC::NE)
4720 .Case("hs", ARMCC::HS)
4721 .Case("cs", ARMCC::HS)
4722 .Case("lo", ARMCC::LO)
4723 .Case("cc", ARMCC::LO)
4724 .Case("mi", ARMCC::MI)
4725 .Case("pl", ARMCC::PL)
4726 .Case("vs", ARMCC::VS)
4727 .Case("vc", ARMCC::VC)
4728 .Case("hi", ARMCC::HI)
4729 .Case("ls", ARMCC::LS)
4730 .Case("ge", ARMCC::GE)
4731 .Case("lt", ARMCC::LT)
4732 .Case("gt", ARMCC::GT)
4733 .Case("le", ARMCC::LE)
4734 .Case("al", ARMCC::AL)
4737 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4738 PredicationCode = CC;
4742 // Next, determine if we have a carry setting bit. We explicitly ignore all
4743 // the instructions we know end in 's'.
4744 if (Mnemonic.endswith("s") &&
4745 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4746 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4747 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4748 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4749 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4750 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4751 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4752 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4753 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4754 (Mnemonic == "movs" && isThumb()))) {
4755 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4756 CarrySetting = true;
4759 // The "cps" instruction can have a interrupt mode operand which is glued into
4760 // the mnemonic. Check if this is the case, split it and parse the imod op
4761 if (Mnemonic.startswith("cps")) {
4762 // Split out any imod code.
4764 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4765 .Case("ie", ARM_PROC::IE)
4766 .Case("id", ARM_PROC::ID)
4769 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4770 ProcessorIMod = IMod;
4774 // The "it" instruction has the condition mask on the end of the mnemonic.
4775 if (Mnemonic.startswith("it")) {
4776 ITMask = Mnemonic.slice(2, Mnemonic.size());
4777 Mnemonic = Mnemonic.slice(0, 2);
4783 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4784 /// inclusion of carry set or predication code operands.
4786 // FIXME: It would be nice to autogen this.
4788 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4789 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
4790 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4791 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4792 Mnemonic == "add" || Mnemonic == "adc" ||
4793 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4794 Mnemonic == "orr" || Mnemonic == "mvn" ||
4795 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4796 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4797 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4798 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4799 Mnemonic == "mla" || Mnemonic == "smlal" ||
4800 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4801 CanAcceptCarrySet = true;
4803 CanAcceptCarrySet = false;
4805 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4806 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4807 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
4808 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4809 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
4810 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4811 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4812 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4813 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4814 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
4815 // These mnemonics are never predicable
4816 CanAcceptPredicationCode = false;
4817 } else if (!isThumb()) {
4818 // Some instructions are only predicable in Thumb mode
4819 CanAcceptPredicationCode
4820 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4821 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4822 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4823 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4824 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4825 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4826 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4827 } else if (isThumbOne()) {
4828 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4830 CanAcceptPredicationCode = true;
4833 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4834 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4835 // FIXME: This is all horribly hacky. We really need a better way to deal
4836 // with optional operands like this in the matcher table.
4838 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4839 // another does not. Specifically, the MOVW instruction does not. So we
4840 // special case it here and remove the defaulted (non-setting) cc_out
4841 // operand if that's the instruction we're trying to match.
4843 // We do this as post-processing of the explicit operands rather than just
4844 // conditionally adding the cc_out in the first place because we need
4845 // to check the type of the parsed immediate operand.
4846 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4847 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4848 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4849 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4852 // Register-register 'add' for thumb does not have a cc_out operand
4853 // when there are only two register operands.
4854 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4855 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4856 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4857 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4859 // Register-register 'add' for thumb does not have a cc_out operand
4860 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4861 // have to check the immediate range here since Thumb2 has a variant
4862 // that can handle a different range and has a cc_out operand.
4863 if (((isThumb() && Mnemonic == "add") ||
4864 (isThumbTwo() && Mnemonic == "sub")) &&
4865 Operands.size() == 6 &&
4866 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4867 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4868 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4869 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4870 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4871 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4873 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4874 // imm0_4095 variant. That's the least-preferred variant when
4875 // selecting via the generic "add" mnemonic, so to know that we
4876 // should remove the cc_out operand, we have to explicitly check that
4877 // it's not one of the other variants. Ugh.
4878 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4879 Operands.size() == 6 &&
4880 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4881 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4882 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4883 // Nest conditions rather than one big 'if' statement for readability.
4885 // If both registers are low, we're in an IT block, and the immediate is
4886 // in range, we should use encoding T1 instead, which has a cc_out.
4888 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4889 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4890 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4892 // Check against T3. If the second register is the PC, this is an
4893 // alternate form of ADR, which uses encoding T4, so check for that too.
4894 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4895 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4898 // Otherwise, we use encoding T4, which does not have a cc_out
4903 // The thumb2 multiply instruction doesn't have a CCOut register, so
4904 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4905 // use the 16-bit encoding or not.
4906 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4907 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4908 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4909 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4910 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4911 // If the registers aren't low regs, the destination reg isn't the
4912 // same as one of the source regs, or the cc_out operand is zero
4913 // outside of an IT block, we have to use the 32-bit encoding, so
4914 // remove the cc_out operand.
4915 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4916 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4917 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4919 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4920 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4921 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4922 static_cast<ARMOperand*>(Operands[4])->getReg())))
4925 // Also check the 'mul' syntax variant that doesn't specify an explicit
4926 // destination register.
4927 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4928 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4929 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4930 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4931 // If the registers aren't low regs or the cc_out operand is zero
4932 // outside of an IT block, we have to use the 32-bit encoding, so
4933 // remove the cc_out operand.
4934 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4935 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4941 // Register-register 'add/sub' for thumb does not have a cc_out operand
4942 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4943 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4944 // right, this will result in better diagnostics (which operand is off)
4946 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4947 (Operands.size() == 5 || Operands.size() == 6) &&
4948 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4949 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4950 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4951 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4952 (Operands.size() == 6 &&
4953 static_cast<ARMOperand*>(Operands[5])->isImm())))
4959 bool ARMAsmParser::shouldOmitPredicateOperand(
4960 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4961 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4962 unsigned RegIdx = 3;
4963 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4964 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4965 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4966 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4969 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4970 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4971 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4972 ARMMCRegisterClasses[ARM::QPRRegClassID]
4973 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4979 static bool isDataTypeToken(StringRef Tok) {
4980 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4981 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4982 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4983 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4984 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4985 Tok == ".f" || Tok == ".d";
4988 // FIXME: This bit should probably be handled via an explicit match class
4989 // in the .td files that matches the suffix instead of having it be
4990 // a literal string token the way it is now.
4991 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4992 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4994 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
4995 unsigned VariantID);
4996 /// Parse an arm instruction mnemonic followed by its operands.
4997 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4999 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5000 // Apply mnemonic aliases before doing anything else, as the destination
5001 // mnemnonic may include suffices and we want to handle them normally.
5002 // The generic tblgen'erated code does this later, at the start of
5003 // MatchInstructionImpl(), but that's too late for aliases that include
5004 // any sort of suffix.
5005 unsigned AvailableFeatures = getAvailableFeatures();
5006 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5007 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5009 // First check for the ARM-specific .req directive.
5010 if (Parser.getTok().is(AsmToken::Identifier) &&
5011 Parser.getTok().getIdentifier() == ".req") {
5012 parseDirectiveReq(Name, NameLoc);
5013 // We always return 'error' for this, as we're done with this
5014 // statement and don't need to match the 'instruction."
5018 // Create the leading tokens for the mnemonic, split by '.' characters.
5019 size_t Start = 0, Next = Name.find('.');
5020 StringRef Mnemonic = Name.slice(Start, Next);
5022 // Split out the predication code and carry setting flag from the mnemonic.
5023 unsigned PredicationCode;
5024 unsigned ProcessorIMod;
5027 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5028 ProcessorIMod, ITMask);
5030 // In Thumb1, only the branch (B) instruction can be predicated.
5031 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5032 Parser.eatToEndOfStatement();
5033 return Error(NameLoc, "conditional execution not supported in Thumb1");
5036 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5038 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5039 // is the mask as it will be for the IT encoding if the conditional
5040 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5041 // where the conditional bit0 is zero, the instruction post-processing
5042 // will adjust the mask accordingly.
5043 if (Mnemonic == "it") {
5044 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5045 if (ITMask.size() > 3) {
5046 Parser.eatToEndOfStatement();
5047 return Error(Loc, "too many conditions on IT instruction");
5050 for (unsigned i = ITMask.size(); i != 0; --i) {
5051 char pos = ITMask[i - 1];
5052 if (pos != 't' && pos != 'e') {
5053 Parser.eatToEndOfStatement();
5054 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5057 if (ITMask[i - 1] == 't')
5060 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5063 // FIXME: This is all a pretty gross hack. We should automatically handle
5064 // optional operands like this via tblgen.
5066 // Next, add the CCOut and ConditionCode operands, if needed.
5068 // For mnemonics which can ever incorporate a carry setting bit or predication
5069 // code, our matching model involves us always generating CCOut and
5070 // ConditionCode operands to match the mnemonic "as written" and then we let
5071 // the matcher deal with finding the right instruction or generating an
5072 // appropriate error.
5073 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5074 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5076 // If we had a carry-set on an instruction that can't do that, issue an
5078 if (!CanAcceptCarrySet && CarrySetting) {
5079 Parser.eatToEndOfStatement();
5080 return Error(NameLoc, "instruction '" + Mnemonic +
5081 "' can not set flags, but 's' suffix specified");
5083 // If we had a predication code on an instruction that can't do that, issue an
5085 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5086 Parser.eatToEndOfStatement();
5087 return Error(NameLoc, "instruction '" + Mnemonic +
5088 "' is not predicable, but condition code specified");
5091 // Add the carry setting operand, if necessary.
5092 if (CanAcceptCarrySet) {
5093 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5094 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5098 // Add the predication code operand, if necessary.
5099 if (CanAcceptPredicationCode) {
5100 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5102 Operands.push_back(ARMOperand::CreateCondCode(
5103 ARMCC::CondCodes(PredicationCode), Loc));
5106 // Add the processor imod operand, if necessary.
5107 if (ProcessorIMod) {
5108 Operands.push_back(ARMOperand::CreateImm(
5109 MCConstantExpr::Create(ProcessorIMod, getContext()),
5113 // Add the remaining tokens in the mnemonic.
5114 while (Next != StringRef::npos) {
5116 Next = Name.find('.', Start + 1);
5117 StringRef ExtraToken = Name.slice(Start, Next);
5119 // Some NEON instructions have an optional datatype suffix that is
5120 // completely ignored. Check for that.
5121 if (isDataTypeToken(ExtraToken) &&
5122 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5125 // For for ARM mode generate an error if the .n qualifier is used.
5126 if (ExtraToken == ".n" && !isThumb()) {
5127 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5128 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5132 // The .n qualifier is always discarded as that is what the tables
5133 // and matcher expect. In ARM mode the .w qualifier has no effect,
5134 // so discard it to avoid errors that can be caused by the matcher.
5135 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5136 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5137 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5141 // Read the remaining operands.
5142 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5143 // Read the first operand.
5144 if (parseOperand(Operands, Mnemonic)) {
5145 Parser.eatToEndOfStatement();
5149 while (getLexer().is(AsmToken::Comma)) {
5150 Parser.Lex(); // Eat the comma.
5152 // Parse and remember the operand.
5153 if (parseOperand(Operands, Mnemonic)) {
5154 Parser.eatToEndOfStatement();
5160 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5161 SMLoc Loc = getLexer().getLoc();
5162 Parser.eatToEndOfStatement();
5163 return Error(Loc, "unexpected token in argument list");
5166 Parser.Lex(); // Consume the EndOfStatement
5168 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5169 // do and don't have a cc_out optional-def operand. With some spot-checks
5170 // of the operand list, we can figure out which variant we're trying to
5171 // parse and adjust accordingly before actually matching. We shouldn't ever
5172 // try to remove a cc_out operand that was explicitly set on the the
5173 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5174 // table driven matcher doesn't fit well with the ARM instruction set.
5175 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5176 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5177 Operands.erase(Operands.begin() + 1);
5181 // Some instructions have the same mnemonic, but don't always
5182 // have a predicate. Distinguish them here and delete the
5183 // predicate if needed.
5184 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5185 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5186 Operands.erase(Operands.begin() + 1);
5190 // ARM mode 'blx' need special handling, as the register operand version
5191 // is predicable, but the label operand version is not. So, we can't rely
5192 // on the Mnemonic based checking to correctly figure out when to put
5193 // a k_CondCode operand in the list. If we're trying to match the label
5194 // version, remove the k_CondCode operand here.
5195 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5196 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5197 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5198 Operands.erase(Operands.begin() + 1);
5202 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5203 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5204 // a single GPRPair reg operand is used in the .td file to replace the two
5205 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5206 // expressed as a GPRPair, so we have to manually merge them.
5207 // FIXME: We would really like to be able to tablegen'erate this.
5208 if (!isThumb() && Operands.size() > 4 &&
5209 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5210 Mnemonic == "stlexd")) {
5211 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5212 unsigned Idx = isLoad ? 2 : 3;
5213 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5214 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5216 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5217 // Adjust only if Op1 and Op2 are GPRs.
5218 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5219 MRC.contains(Op2->getReg())) {
5220 unsigned Reg1 = Op1->getReg();
5221 unsigned Reg2 = Op2->getReg();
5222 unsigned Rt = MRI->getEncodingValue(Reg1);
5223 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5225 // Rt2 must be Rt + 1 and Rt must be even.
5226 if (Rt + 1 != Rt2 || (Rt & 1)) {
5227 Error(Op2->getStartLoc(), isLoad ?
5228 "destination operands must be sequential" :
5229 "source operands must be sequential");
5232 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5233 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5234 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5235 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5236 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5242 // FIXME: As said above, this is all a pretty gross hack. This instruction
5243 // does not fit with other "subs" and tblgen.
5244 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5245 // so the Mnemonic is the original name "subs" and delete the predicate
5246 // operand so it will match the table entry.
5247 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5248 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5249 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5250 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5251 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5252 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5253 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5254 Operands.erase(Operands.begin());
5256 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5258 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5259 Operands.erase(Operands.begin() + 1);
5265 // Validate context-sensitive operand constraints.
5267 // return 'true' if register list contains non-low GPR registers,
5268 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5269 // 'containsReg' to true.
5270 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5271 unsigned HiReg, bool &containsReg) {
5272 containsReg = false;
5273 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5274 unsigned OpReg = Inst.getOperand(i).getReg();
5277 // Anything other than a low register isn't legal here.
5278 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5284 // Check if the specified regisgter is in the register list of the inst,
5285 // starting at the indicated operand number.
5286 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5287 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5288 unsigned OpReg = Inst.getOperand(i).getReg();
5295 // Return true if instruction has the interesting property of being
5296 // allowed in IT blocks, but not being predicable.
5297 static bool instIsBreakpoint(const MCInst &Inst) {
5298 return Inst.getOpcode() == ARM::tBKPT ||
5299 Inst.getOpcode() == ARM::BKPT ||
5300 Inst.getOpcode() == ARM::tHLT ||
5301 Inst.getOpcode() == ARM::HLT;
5305 // FIXME: We would really like to be able to tablegen'erate this.
5307 validateInstruction(MCInst &Inst,
5308 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5309 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
5310 SMLoc Loc = Operands[0]->getStartLoc();
5312 // Check the IT block state first.
5313 // NOTE: BKPT and HLT instructions have the interesting property of being
5314 // allowed in IT blocks, but not being predicable. They just always
5316 if (inITBlock() && !instIsBreakpoint(Inst)) {
5318 if (ITState.FirstCond)
5319 ITState.FirstCond = false;
5321 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5322 // The instruction must be predicable.
5323 if (!MCID.isPredicable())
5324 return Error(Loc, "instructions in IT block must be predicable");
5325 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5326 unsigned ITCond = bit ? ITState.Cond :
5327 ARMCC::getOppositeCondition(ITState.Cond);
5328 if (Cond != ITCond) {
5329 // Find the condition code Operand to get its SMLoc information.
5331 for (unsigned i = 1; i < Operands.size(); ++i)
5332 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5333 CondLoc = Operands[i]->getStartLoc();
5334 return Error(CondLoc, "incorrect condition in IT block; got '" +
5335 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5336 "', but expected '" +
5337 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5339 // Check for non-'al' condition codes outside of the IT block.
5340 } else if (isThumbTwo() && MCID.isPredicable() &&
5341 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5342 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5343 Inst.getOpcode() != ARM::t2Bcc)
5344 return Error(Loc, "predicated instructions must be in IT block");
5346 switch (Inst.getOpcode()) {
5349 case ARM::LDRD_POST: {
5350 unsigned RtReg = Inst.getOperand(0).getReg();
5352 if (RtReg == ARM::LR)
5353 return Error(Operands[3]->getStartLoc(),
5355 unsigned Rt = MRI->getEncodingValue(RtReg);
5356 // Rt must be even-numbered.
5358 return Error(Operands[3]->getStartLoc(),
5359 "Rt must be even-numbered");
5360 // Rt2 must be Rt + 1.
5361 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5363 return Error(Operands[3]->getStartLoc(),
5364 "destination operands must be sequential");
5368 case ARM::t2LDRD_PRE:
5369 case ARM::t2LDRD_POST: {
5370 // Rt2 must be different from Rt.
5371 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5372 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5374 return Error(Operands[3]->getStartLoc(),
5375 "destination operands can't be identical");
5379 // Rt2 must be Rt + 1.
5380 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5381 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5383 return Error(Operands[3]->getStartLoc(),
5384 "source operands must be sequential");
5388 case ARM::STRD_POST: {
5389 // Rt2 must be Rt + 1.
5390 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5391 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5393 return Error(Operands[3]->getStartLoc(),
5394 "source operands must be sequential");
5399 // width must be in range [1, 32-lsb]
5400 unsigned lsb = Inst.getOperand(2).getImm();
5401 unsigned widthm1 = Inst.getOperand(3).getImm();
5402 if (widthm1 >= 32 - lsb)
5403 return Error(Operands[5]->getStartLoc(),
5404 "bitfield width must be in range [1,32-lsb]");
5408 // If we're parsing Thumb2, the .w variant is available and handles
5409 // most cases that are normally illegal for a Thumb1 LDM
5410 // instruction. We'll make the transformation in processInstruction()
5413 // Thumb LDM instructions are writeback iff the base register is not
5414 // in the register list.
5415 unsigned Rn = Inst.getOperand(0).getReg();
5416 bool hasWritebackToken =
5417 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5418 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5419 bool listContainsBase;
5420 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5421 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5422 "registers must be in range r0-r7");
5423 // If we should have writeback, then there should be a '!' token.
5424 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5425 return Error(Operands[2]->getStartLoc(),
5426 "writeback operator '!' expected");
5427 // If we should not have writeback, there must not be a '!'. This is
5428 // true even for the 32-bit wide encodings.
5429 if (listContainsBase && hasWritebackToken)
5430 return Error(Operands[3]->getStartLoc(),
5431 "writeback operator '!' not allowed when base register "
5432 "in register list");
5436 case ARM::t2LDMIA_UPD: {
5437 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5438 return Error(Operands[4]->getStartLoc(),
5439 "writeback operator '!' not allowed when base register "
5440 "in register list");
5444 // The second source operand must be the same register as the destination
5447 // In this case, we must directly check the parsed operands because the
5448 // cvtThumbMultiply() function is written in such a way that it guarantees
5449 // this first statement is always true for the new Inst. Essentially, the
5450 // destination is unconditionally copied into the second source operand
5451 // without checking to see if it matches what we actually parsed.
5452 if (Operands.size() == 6 &&
5453 (((ARMOperand*)Operands[3])->getReg() !=
5454 ((ARMOperand*)Operands[5])->getReg()) &&
5455 (((ARMOperand*)Operands[3])->getReg() !=
5456 ((ARMOperand*)Operands[4])->getReg())) {
5457 return Error(Operands[3]->getStartLoc(),
5458 "destination register must match source register");
5462 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5463 // so only issue a diagnostic for thumb1. The instructions will be
5464 // switched to the t2 encodings in processInstruction() if necessary.
5466 bool listContainsBase;
5467 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5469 return Error(Operands[2]->getStartLoc(),
5470 "registers must be in range r0-r7 or pc");
5474 bool listContainsBase;
5475 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5477 return Error(Operands[2]->getStartLoc(),
5478 "registers must be in range r0-r7 or lr");
5481 case ARM::tSTMIA_UPD: {
5482 bool listContainsBase;
5483 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5484 return Error(Operands[4]->getStartLoc(),
5485 "registers must be in range r0-r7");
5488 case ARM::tADDrSP: {
5489 // If the non-SP source operand and the destination operand are not the
5490 // same, we need thumb2 (for the wide encoding), or we have an error.
5491 if (!isThumbTwo() &&
5492 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5493 return Error(Operands[4]->getStartLoc(),
5494 "source register must be the same as destination");
5498 // final range checking for Thumb unconditional branch instructions
5500 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5501 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5504 int op = (Operands[2]->isImm()) ? 2 : 3;
5505 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5506 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5509 // final range checking for Thumb conditional branch instructions
5511 if(!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5512 return Error(Operands[2]->getStartLoc(), "Branch target out of range");
5515 int op = (Operands[2]->isImm()) ? 2 : 3;
5516 if(!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<20, 1>())
5517 return Error(Operands[op]->getStartLoc(), "Branch target out of range");
5525 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5527 default: llvm_unreachable("unexpected opcode!");
5529 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5530 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5531 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5532 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5533 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5534 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5535 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5536 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5537 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5540 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5541 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5542 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5543 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5544 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5546 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5547 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5548 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5549 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5550 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5552 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5553 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5554 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5555 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5556 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5559 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5560 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5561 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5562 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5563 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5564 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5565 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5566 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5567 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5568 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5569 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5570 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5571 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5572 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5573 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5576 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5577 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5578 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5579 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5580 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5581 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5582 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5583 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5584 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5585 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5586 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5587 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5588 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5589 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5590 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5591 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5592 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5593 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5596 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5597 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5598 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5599 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5600 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5601 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5602 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5603 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5604 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5605 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5606 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5607 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5608 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5609 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5610 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5613 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5614 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5615 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5616 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5617 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5618 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5619 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5620 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5621 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5622 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5623 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5624 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5625 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5626 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5627 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5628 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5629 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5630 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5634 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5636 default: llvm_unreachable("unexpected opcode!");
5638 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5639 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5640 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5641 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5642 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5643 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5644 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5645 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5646 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5649 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5650 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5651 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5652 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5653 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5654 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5655 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5656 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5657 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5658 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5659 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5660 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5661 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5662 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5663 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5666 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5667 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5668 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5669 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5670 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5671 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5672 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5673 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5674 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5675 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5676 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5677 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5678 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5679 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5680 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5681 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5682 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5683 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5686 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5687 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5688 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5689 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5690 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5691 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5692 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5693 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5694 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5695 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5696 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5697 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5698 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5699 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5700 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5703 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5704 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5705 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5706 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5707 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5708 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5709 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5710 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5711 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5712 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5713 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5714 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5715 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5716 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5717 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5718 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5719 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5720 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5723 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5724 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5725 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5726 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5727 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5728 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5729 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5730 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5731 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5732 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5733 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5734 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5735 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5736 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5737 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5740 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5741 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5742 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5743 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5744 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5745 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5746 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5747 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5748 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5749 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5750 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5751 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5752 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5753 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5754 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5755 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5756 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5757 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5760 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5761 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5762 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5763 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5764 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5765 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5766 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5767 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5768 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5769 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5770 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5771 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5772 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5773 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5774 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5775 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5776 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5777 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5782 processInstruction(MCInst &Inst,
5783 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5784 switch (Inst.getOpcode()) {
5785 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5787 if (Inst.getOperand(1).getReg() != ARM::PC ||
5788 Inst.getOperand(5).getReg() != 0)
5791 TmpInst.setOpcode(ARM::ADR);
5792 TmpInst.addOperand(Inst.getOperand(0));
5793 TmpInst.addOperand(Inst.getOperand(2));
5794 TmpInst.addOperand(Inst.getOperand(3));
5795 TmpInst.addOperand(Inst.getOperand(4));
5799 // Aliases for alternate PC+imm syntax of LDR instructions.
5800 case ARM::t2LDRpcrel:
5801 // Select the narrow version if the immediate will fit.
5802 if (Inst.getOperand(1).getImm() > 0 &&
5803 Inst.getOperand(1).getImm() <= 0xff &&
5804 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5805 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
5806 Inst.setOpcode(ARM::tLDRpci);
5808 Inst.setOpcode(ARM::t2LDRpci);
5810 case ARM::t2LDRBpcrel:
5811 Inst.setOpcode(ARM::t2LDRBpci);
5813 case ARM::t2LDRHpcrel:
5814 Inst.setOpcode(ARM::t2LDRHpci);
5816 case ARM::t2LDRSBpcrel:
5817 Inst.setOpcode(ARM::t2LDRSBpci);
5819 case ARM::t2LDRSHpcrel:
5820 Inst.setOpcode(ARM::t2LDRSHpci);
5822 // Handle NEON VST complex aliases.
5823 case ARM::VST1LNdWB_register_Asm_8:
5824 case ARM::VST1LNdWB_register_Asm_16:
5825 case ARM::VST1LNdWB_register_Asm_32: {
5827 // Shuffle the operands around so the lane index operand is in the
5830 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5831 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5832 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5833 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5834 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5835 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5836 TmpInst.addOperand(Inst.getOperand(1)); // lane
5837 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5838 TmpInst.addOperand(Inst.getOperand(6));
5843 case ARM::VST2LNdWB_register_Asm_8:
5844 case ARM::VST2LNdWB_register_Asm_16:
5845 case ARM::VST2LNdWB_register_Asm_32:
5846 case ARM::VST2LNqWB_register_Asm_16:
5847 case ARM::VST2LNqWB_register_Asm_32: {
5849 // Shuffle the operands around so the lane index operand is in the
5852 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5853 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5854 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5855 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5856 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5857 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5860 TmpInst.addOperand(Inst.getOperand(1)); // lane
5861 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5862 TmpInst.addOperand(Inst.getOperand(6));
5867 case ARM::VST3LNdWB_register_Asm_8:
5868 case ARM::VST3LNdWB_register_Asm_16:
5869 case ARM::VST3LNdWB_register_Asm_32:
5870 case ARM::VST3LNqWB_register_Asm_16:
5871 case ARM::VST3LNqWB_register_Asm_32: {
5873 // Shuffle the operands around so the lane index operand is in the
5876 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5877 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5878 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5879 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5880 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5881 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5886 TmpInst.addOperand(Inst.getOperand(1)); // lane
5887 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5888 TmpInst.addOperand(Inst.getOperand(6));
5893 case ARM::VST4LNdWB_register_Asm_8:
5894 case ARM::VST4LNdWB_register_Asm_16:
5895 case ARM::VST4LNdWB_register_Asm_32:
5896 case ARM::VST4LNqWB_register_Asm_16:
5897 case ARM::VST4LNqWB_register_Asm_32: {
5899 // Shuffle the operands around so the lane index operand is in the
5902 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5903 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5904 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5905 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5906 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5907 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5908 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5910 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5912 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5914 TmpInst.addOperand(Inst.getOperand(1)); // lane
5915 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5916 TmpInst.addOperand(Inst.getOperand(6));
5921 case ARM::VST1LNdWB_fixed_Asm_8:
5922 case ARM::VST1LNdWB_fixed_Asm_16:
5923 case ARM::VST1LNdWB_fixed_Asm_32: {
5925 // Shuffle the operands around so the lane index operand is in the
5928 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5929 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5930 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5931 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5932 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5933 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5934 TmpInst.addOperand(Inst.getOperand(1)); // lane
5935 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5936 TmpInst.addOperand(Inst.getOperand(5));
5941 case ARM::VST2LNdWB_fixed_Asm_8:
5942 case ARM::VST2LNdWB_fixed_Asm_16:
5943 case ARM::VST2LNdWB_fixed_Asm_32:
5944 case ARM::VST2LNqWB_fixed_Asm_16:
5945 case ARM::VST2LNqWB_fixed_Asm_32: {
5947 // Shuffle the operands around so the lane index operand is in the
5950 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5951 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5952 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5953 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5954 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5955 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5956 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5958 TmpInst.addOperand(Inst.getOperand(1)); // lane
5959 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5960 TmpInst.addOperand(Inst.getOperand(5));
5965 case ARM::VST3LNdWB_fixed_Asm_8:
5966 case ARM::VST3LNdWB_fixed_Asm_16:
5967 case ARM::VST3LNdWB_fixed_Asm_32:
5968 case ARM::VST3LNqWB_fixed_Asm_16:
5969 case ARM::VST3LNqWB_fixed_Asm_32: {
5971 // Shuffle the operands around so the lane index operand is in the
5974 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5975 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5976 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5977 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5978 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5979 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5980 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5982 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5984 TmpInst.addOperand(Inst.getOperand(1)); // lane
5985 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5986 TmpInst.addOperand(Inst.getOperand(5));
5991 case ARM::VST4LNdWB_fixed_Asm_8:
5992 case ARM::VST4LNdWB_fixed_Asm_16:
5993 case ARM::VST4LNdWB_fixed_Asm_32:
5994 case ARM::VST4LNqWB_fixed_Asm_16:
5995 case ARM::VST4LNqWB_fixed_Asm_32: {
5997 // Shuffle the operands around so the lane index operand is in the
6000 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6001 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6002 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6003 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6004 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6005 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6006 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6008 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6010 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6012 TmpInst.addOperand(Inst.getOperand(1)); // lane
6013 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6014 TmpInst.addOperand(Inst.getOperand(5));
6019 case ARM::VST1LNdAsm_8:
6020 case ARM::VST1LNdAsm_16:
6021 case ARM::VST1LNdAsm_32: {
6023 // Shuffle the operands around so the lane index operand is in the
6026 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6027 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6028 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6029 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6030 TmpInst.addOperand(Inst.getOperand(1)); // lane
6031 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6032 TmpInst.addOperand(Inst.getOperand(5));
6037 case ARM::VST2LNdAsm_8:
6038 case ARM::VST2LNdAsm_16:
6039 case ARM::VST2LNdAsm_32:
6040 case ARM::VST2LNqAsm_16:
6041 case ARM::VST2LNqAsm_32: {
6043 // Shuffle the operands around so the lane index operand is in the
6046 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6047 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6048 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6049 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6050 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6052 TmpInst.addOperand(Inst.getOperand(1)); // lane
6053 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6054 TmpInst.addOperand(Inst.getOperand(5));
6059 case ARM::VST3LNdAsm_8:
6060 case ARM::VST3LNdAsm_16:
6061 case ARM::VST3LNdAsm_32:
6062 case ARM::VST3LNqAsm_16:
6063 case ARM::VST3LNqAsm_32: {
6065 // Shuffle the operands around so the lane index operand is in the
6068 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6069 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6070 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6071 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6072 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6074 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6076 TmpInst.addOperand(Inst.getOperand(1)); // lane
6077 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6078 TmpInst.addOperand(Inst.getOperand(5));
6083 case ARM::VST4LNdAsm_8:
6084 case ARM::VST4LNdAsm_16:
6085 case ARM::VST4LNdAsm_32:
6086 case ARM::VST4LNqAsm_16:
6087 case ARM::VST4LNqAsm_32: {
6089 // Shuffle the operands around so the lane index operand is in the
6092 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6093 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6094 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6095 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6096 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6098 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6100 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6102 TmpInst.addOperand(Inst.getOperand(1)); // lane
6103 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6104 TmpInst.addOperand(Inst.getOperand(5));
6109 // Handle NEON VLD complex aliases.
6110 case ARM::VLD1LNdWB_register_Asm_8:
6111 case ARM::VLD1LNdWB_register_Asm_16:
6112 case ARM::VLD1LNdWB_register_Asm_32: {
6114 // Shuffle the operands around so the lane index operand is in the
6117 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6118 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6119 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6120 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6121 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6122 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6123 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6124 TmpInst.addOperand(Inst.getOperand(1)); // lane
6125 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6126 TmpInst.addOperand(Inst.getOperand(6));
6131 case ARM::VLD2LNdWB_register_Asm_8:
6132 case ARM::VLD2LNdWB_register_Asm_16:
6133 case ARM::VLD2LNdWB_register_Asm_32:
6134 case ARM::VLD2LNqWB_register_Asm_16:
6135 case ARM::VLD2LNqWB_register_Asm_32: {
6137 // Shuffle the operands around so the lane index operand is in the
6140 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6141 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6144 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6145 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6146 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6147 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6148 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6149 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6151 TmpInst.addOperand(Inst.getOperand(1)); // lane
6152 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6153 TmpInst.addOperand(Inst.getOperand(6));
6158 case ARM::VLD3LNdWB_register_Asm_8:
6159 case ARM::VLD3LNdWB_register_Asm_16:
6160 case ARM::VLD3LNdWB_register_Asm_32:
6161 case ARM::VLD3LNqWB_register_Asm_16:
6162 case ARM::VLD3LNqWB_register_Asm_32: {
6164 // Shuffle the operands around so the lane index operand is in the
6167 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6168 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6169 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6171 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6173 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6174 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6175 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6176 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6177 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6178 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6180 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6182 TmpInst.addOperand(Inst.getOperand(1)); // lane
6183 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6184 TmpInst.addOperand(Inst.getOperand(6));
6189 case ARM::VLD4LNdWB_register_Asm_8:
6190 case ARM::VLD4LNdWB_register_Asm_16:
6191 case ARM::VLD4LNdWB_register_Asm_32:
6192 case ARM::VLD4LNqWB_register_Asm_16:
6193 case ARM::VLD4LNqWB_register_Asm_32: {
6195 // Shuffle the operands around so the lane index operand is in the
6198 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6199 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6200 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6202 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6204 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6206 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6207 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6208 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6209 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6210 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6211 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6213 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6215 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6217 TmpInst.addOperand(Inst.getOperand(1)); // lane
6218 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6219 TmpInst.addOperand(Inst.getOperand(6));
6224 case ARM::VLD1LNdWB_fixed_Asm_8:
6225 case ARM::VLD1LNdWB_fixed_Asm_16:
6226 case ARM::VLD1LNdWB_fixed_Asm_32: {
6228 // Shuffle the operands around so the lane index operand is in the
6231 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6232 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6233 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6234 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6235 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6236 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6237 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6238 TmpInst.addOperand(Inst.getOperand(1)); // lane
6239 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6240 TmpInst.addOperand(Inst.getOperand(5));
6245 case ARM::VLD2LNdWB_fixed_Asm_8:
6246 case ARM::VLD2LNdWB_fixed_Asm_16:
6247 case ARM::VLD2LNdWB_fixed_Asm_32:
6248 case ARM::VLD2LNqWB_fixed_Asm_16:
6249 case ARM::VLD2LNqWB_fixed_Asm_32: {
6251 // Shuffle the operands around so the lane index operand is in the
6254 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6255 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6258 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6259 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6260 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6261 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6262 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6263 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6265 TmpInst.addOperand(Inst.getOperand(1)); // lane
6266 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6267 TmpInst.addOperand(Inst.getOperand(5));
6272 case ARM::VLD3LNdWB_fixed_Asm_8:
6273 case ARM::VLD3LNdWB_fixed_Asm_16:
6274 case ARM::VLD3LNdWB_fixed_Asm_32:
6275 case ARM::VLD3LNqWB_fixed_Asm_16:
6276 case ARM::VLD3LNqWB_fixed_Asm_32: {
6278 // Shuffle the operands around so the lane index operand is in the
6281 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6282 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6283 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6285 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6287 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6288 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6289 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6290 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6291 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6292 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6296 TmpInst.addOperand(Inst.getOperand(1)); // lane
6297 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6298 TmpInst.addOperand(Inst.getOperand(5));
6303 case ARM::VLD4LNdWB_fixed_Asm_8:
6304 case ARM::VLD4LNdWB_fixed_Asm_16:
6305 case ARM::VLD4LNdWB_fixed_Asm_32:
6306 case ARM::VLD4LNqWB_fixed_Asm_16:
6307 case ARM::VLD4LNqWB_fixed_Asm_32: {
6309 // Shuffle the operands around so the lane index operand is in the
6312 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6313 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6314 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6316 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6318 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6320 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6321 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6322 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6323 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6324 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6325 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6327 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6329 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6331 TmpInst.addOperand(Inst.getOperand(1)); // lane
6332 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6333 TmpInst.addOperand(Inst.getOperand(5));
6338 case ARM::VLD1LNdAsm_8:
6339 case ARM::VLD1LNdAsm_16:
6340 case ARM::VLD1LNdAsm_32: {
6342 // Shuffle the operands around so the lane index operand is in the
6345 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6346 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6347 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6348 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6349 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6350 TmpInst.addOperand(Inst.getOperand(1)); // lane
6351 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6352 TmpInst.addOperand(Inst.getOperand(5));
6357 case ARM::VLD2LNdAsm_8:
6358 case ARM::VLD2LNdAsm_16:
6359 case ARM::VLD2LNdAsm_32:
6360 case ARM::VLD2LNqAsm_16:
6361 case ARM::VLD2LNqAsm_32: {
6363 // Shuffle the operands around so the lane index operand is in the
6366 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6367 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6368 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6370 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6371 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6372 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6375 TmpInst.addOperand(Inst.getOperand(1)); // lane
6376 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6377 TmpInst.addOperand(Inst.getOperand(5));
6382 case ARM::VLD3LNdAsm_8:
6383 case ARM::VLD3LNdAsm_16:
6384 case ARM::VLD3LNdAsm_32:
6385 case ARM::VLD3LNqAsm_16:
6386 case ARM::VLD3LNqAsm_32: {
6388 // Shuffle the operands around so the lane index operand is in the
6391 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6392 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6393 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6395 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6397 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6398 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6399 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6400 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6404 TmpInst.addOperand(Inst.getOperand(1)); // lane
6405 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6406 TmpInst.addOperand(Inst.getOperand(5));
6411 case ARM::VLD4LNdAsm_8:
6412 case ARM::VLD4LNdAsm_16:
6413 case ARM::VLD4LNdAsm_32:
6414 case ARM::VLD4LNqAsm_16:
6415 case ARM::VLD4LNqAsm_32: {
6417 // Shuffle the operands around so the lane index operand is in the
6420 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6421 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6422 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6424 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6426 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6428 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6429 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6430 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6431 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6433 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6435 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6437 TmpInst.addOperand(Inst.getOperand(1)); // lane
6438 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6439 TmpInst.addOperand(Inst.getOperand(5));
6444 // VLD3DUP single 3-element structure to all lanes instructions.
6445 case ARM::VLD3DUPdAsm_8:
6446 case ARM::VLD3DUPdAsm_16:
6447 case ARM::VLD3DUPdAsm_32:
6448 case ARM::VLD3DUPqAsm_8:
6449 case ARM::VLD3DUPqAsm_16:
6450 case ARM::VLD3DUPqAsm_32: {
6453 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6454 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6455 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6457 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6459 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6460 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6461 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6462 TmpInst.addOperand(Inst.getOperand(4));
6467 case ARM::VLD3DUPdWB_fixed_Asm_8:
6468 case ARM::VLD3DUPdWB_fixed_Asm_16:
6469 case ARM::VLD3DUPdWB_fixed_Asm_32:
6470 case ARM::VLD3DUPqWB_fixed_Asm_8:
6471 case ARM::VLD3DUPqWB_fixed_Asm_16:
6472 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6475 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6476 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6477 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6479 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6481 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6482 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6483 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6484 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6485 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6486 TmpInst.addOperand(Inst.getOperand(4));
6491 case ARM::VLD3DUPdWB_register_Asm_8:
6492 case ARM::VLD3DUPdWB_register_Asm_16:
6493 case ARM::VLD3DUPdWB_register_Asm_32:
6494 case ARM::VLD3DUPqWB_register_Asm_8:
6495 case ARM::VLD3DUPqWB_register_Asm_16:
6496 case ARM::VLD3DUPqWB_register_Asm_32: {
6499 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6500 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6501 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6503 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6505 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6506 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6507 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6508 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6509 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6510 TmpInst.addOperand(Inst.getOperand(5));
6515 // VLD3 multiple 3-element structure instructions.
6516 case ARM::VLD3dAsm_8:
6517 case ARM::VLD3dAsm_16:
6518 case ARM::VLD3dAsm_32:
6519 case ARM::VLD3qAsm_8:
6520 case ARM::VLD3qAsm_16:
6521 case ARM::VLD3qAsm_32: {
6524 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6525 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6526 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6530 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6531 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6532 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6533 TmpInst.addOperand(Inst.getOperand(4));
6538 case ARM::VLD3dWB_fixed_Asm_8:
6539 case ARM::VLD3dWB_fixed_Asm_16:
6540 case ARM::VLD3dWB_fixed_Asm_32:
6541 case ARM::VLD3qWB_fixed_Asm_8:
6542 case ARM::VLD3qWB_fixed_Asm_16:
6543 case ARM::VLD3qWB_fixed_Asm_32: {
6546 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6547 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6550 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6552 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6553 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6554 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6555 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6556 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6557 TmpInst.addOperand(Inst.getOperand(4));
6562 case ARM::VLD3dWB_register_Asm_8:
6563 case ARM::VLD3dWB_register_Asm_16:
6564 case ARM::VLD3dWB_register_Asm_32:
6565 case ARM::VLD3qWB_register_Asm_8:
6566 case ARM::VLD3qWB_register_Asm_16:
6567 case ARM::VLD3qWB_register_Asm_32: {
6570 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6571 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6574 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6576 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6577 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6578 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6579 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6580 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6581 TmpInst.addOperand(Inst.getOperand(5));
6586 // VLD4DUP single 3-element structure to all lanes instructions.
6587 case ARM::VLD4DUPdAsm_8:
6588 case ARM::VLD4DUPdAsm_16:
6589 case ARM::VLD4DUPdAsm_32:
6590 case ARM::VLD4DUPqAsm_8:
6591 case ARM::VLD4DUPqAsm_16:
6592 case ARM::VLD4DUPqAsm_32: {
6595 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6596 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6599 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6601 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6603 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6604 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6605 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6606 TmpInst.addOperand(Inst.getOperand(4));
6611 case ARM::VLD4DUPdWB_fixed_Asm_8:
6612 case ARM::VLD4DUPdWB_fixed_Asm_16:
6613 case ARM::VLD4DUPdWB_fixed_Asm_32:
6614 case ARM::VLD4DUPqWB_fixed_Asm_8:
6615 case ARM::VLD4DUPqWB_fixed_Asm_16:
6616 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6619 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
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(1)); // Rn
6628 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6629 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6630 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6631 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6632 TmpInst.addOperand(Inst.getOperand(4));
6637 case ARM::VLD4DUPdWB_register_Asm_8:
6638 case ARM::VLD4DUPdWB_register_Asm_16:
6639 case ARM::VLD4DUPdWB_register_Asm_32:
6640 case ARM::VLD4DUPqWB_register_Asm_8:
6641 case ARM::VLD4DUPqWB_register_Asm_16:
6642 case ARM::VLD4DUPqWB_register_Asm_32: {
6645 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
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(1)); // Rn
6654 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6655 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6656 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6657 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6658 TmpInst.addOperand(Inst.getOperand(5));
6663 // VLD4 multiple 4-element structure instructions.
6664 case ARM::VLD4dAsm_8:
6665 case ARM::VLD4dAsm_16:
6666 case ARM::VLD4dAsm_32:
6667 case ARM::VLD4qAsm_8:
6668 case ARM::VLD4qAsm_16:
6669 case ARM::VLD4qAsm_32: {
6672 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6673 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6678 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6680 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6681 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6682 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6683 TmpInst.addOperand(Inst.getOperand(4));
6688 case ARM::VLD4dWB_fixed_Asm_8:
6689 case ARM::VLD4dWB_fixed_Asm_16:
6690 case ARM::VLD4dWB_fixed_Asm_32:
6691 case ARM::VLD4qWB_fixed_Asm_8:
6692 case ARM::VLD4qWB_fixed_Asm_16:
6693 case ARM::VLD4qWB_fixed_Asm_32: {
6696 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6697 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6700 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6702 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6704 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6705 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6706 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6707 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6708 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6709 TmpInst.addOperand(Inst.getOperand(4));
6714 case ARM::VLD4dWB_register_Asm_8:
6715 case ARM::VLD4dWB_register_Asm_16:
6716 case ARM::VLD4dWB_register_Asm_32:
6717 case ARM::VLD4qWB_register_Asm_8:
6718 case ARM::VLD4qWB_register_Asm_16:
6719 case ARM::VLD4qWB_register_Asm_32: {
6722 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6723 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6726 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6728 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6730 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6731 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6732 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6733 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6734 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6735 TmpInst.addOperand(Inst.getOperand(5));
6740 // VST3 multiple 3-element structure instructions.
6741 case ARM::VST3dAsm_8:
6742 case ARM::VST3dAsm_16:
6743 case ARM::VST3dAsm_32:
6744 case ARM::VST3qAsm_8:
6745 case ARM::VST3qAsm_16:
6746 case ARM::VST3qAsm_32: {
6749 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6750 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6751 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6752 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6755 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6757 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6758 TmpInst.addOperand(Inst.getOperand(4));
6763 case ARM::VST3dWB_fixed_Asm_8:
6764 case ARM::VST3dWB_fixed_Asm_16:
6765 case ARM::VST3dWB_fixed_Asm_32:
6766 case ARM::VST3qWB_fixed_Asm_8:
6767 case ARM::VST3qWB_fixed_Asm_16:
6768 case ARM::VST3qWB_fixed_Asm_32: {
6771 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6772 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6773 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6774 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6775 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6776 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6781 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6782 TmpInst.addOperand(Inst.getOperand(4));
6787 case ARM::VST3dWB_register_Asm_8:
6788 case ARM::VST3dWB_register_Asm_16:
6789 case ARM::VST3dWB_register_Asm_32:
6790 case ARM::VST3qWB_register_Asm_8:
6791 case ARM::VST3qWB_register_Asm_16:
6792 case ARM::VST3qWB_register_Asm_32: {
6795 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6796 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6797 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6798 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6799 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6800 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6801 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6803 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6805 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6806 TmpInst.addOperand(Inst.getOperand(5));
6811 // VST4 multiple 3-element structure instructions.
6812 case ARM::VST4dAsm_8:
6813 case ARM::VST4dAsm_16:
6814 case ARM::VST4dAsm_32:
6815 case ARM::VST4qAsm_8:
6816 case ARM::VST4qAsm_16:
6817 case ARM::VST4qAsm_32: {
6820 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6821 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6822 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6823 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6824 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6826 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6828 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6830 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6831 TmpInst.addOperand(Inst.getOperand(4));
6836 case ARM::VST4dWB_fixed_Asm_8:
6837 case ARM::VST4dWB_fixed_Asm_16:
6838 case ARM::VST4dWB_fixed_Asm_32:
6839 case ARM::VST4qWB_fixed_Asm_8:
6840 case ARM::VST4qWB_fixed_Asm_16:
6841 case ARM::VST4qWB_fixed_Asm_32: {
6844 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6845 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6846 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6847 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6848 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6849 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6850 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6852 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6854 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6856 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6857 TmpInst.addOperand(Inst.getOperand(4));
6862 case ARM::VST4dWB_register_Asm_8:
6863 case ARM::VST4dWB_register_Asm_16:
6864 case ARM::VST4dWB_register_Asm_32:
6865 case ARM::VST4qWB_register_Asm_8:
6866 case ARM::VST4qWB_register_Asm_16:
6867 case ARM::VST4qWB_register_Asm_32: {
6870 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6871 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6872 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6873 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6874 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6875 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6876 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6878 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6880 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6882 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6883 TmpInst.addOperand(Inst.getOperand(5));
6888 // Handle encoding choice for the shift-immediate instructions.
6891 case ARM::t2ASRri: {
6892 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6893 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6894 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6895 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6896 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6898 switch (Inst.getOpcode()) {
6899 default: llvm_unreachable("unexpected opcode");
6900 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6901 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6902 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6904 // The Thumb1 operands aren't in the same order. Awesome, eh?
6906 TmpInst.setOpcode(NewOpc);
6907 TmpInst.addOperand(Inst.getOperand(0));
6908 TmpInst.addOperand(Inst.getOperand(5));
6909 TmpInst.addOperand(Inst.getOperand(1));
6910 TmpInst.addOperand(Inst.getOperand(2));
6911 TmpInst.addOperand(Inst.getOperand(3));
6912 TmpInst.addOperand(Inst.getOperand(4));
6919 // Handle the Thumb2 mode MOV complex aliases.
6921 case ARM::t2MOVSsr: {
6922 // Which instruction to expand to depends on the CCOut operand and
6923 // whether we're in an IT block if the register operands are low
6925 bool isNarrow = false;
6926 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6927 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6928 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6929 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6930 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6934 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6935 default: llvm_unreachable("unexpected opcode!");
6936 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6937 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6938 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6939 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6941 TmpInst.setOpcode(newOpc);
6942 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6944 TmpInst.addOperand(MCOperand::CreateReg(
6945 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6946 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6947 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6948 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6949 TmpInst.addOperand(Inst.getOperand(5));
6951 TmpInst.addOperand(MCOperand::CreateReg(
6952 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6957 case ARM::t2MOVSsi: {
6958 // Which instruction to expand to depends on the CCOut operand and
6959 // whether we're in an IT block if the register operands are low
6961 bool isNarrow = false;
6962 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6963 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6964 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6968 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6969 default: llvm_unreachable("unexpected opcode!");
6970 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6971 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6972 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6973 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
6974 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
6976 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6977 if (Amount == 32) Amount = 0;
6978 TmpInst.setOpcode(newOpc);
6979 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6981 TmpInst.addOperand(MCOperand::CreateReg(
6982 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6983 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6984 if (newOpc != ARM::t2RRX)
6985 TmpInst.addOperand(MCOperand::CreateImm(Amount));
6986 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6987 TmpInst.addOperand(Inst.getOperand(4));
6989 TmpInst.addOperand(MCOperand::CreateReg(
6990 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6994 // Handle the ARM mode MOV complex aliases.
6999 ARM_AM::ShiftOpc ShiftTy;
7000 switch(Inst.getOpcode()) {
7001 default: llvm_unreachable("unexpected opcode!");
7002 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7003 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7004 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7005 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7007 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7009 TmpInst.setOpcode(ARM::MOVsr);
7010 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7011 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7012 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7013 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7014 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7015 TmpInst.addOperand(Inst.getOperand(4));
7016 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7024 ARM_AM::ShiftOpc ShiftTy;
7025 switch(Inst.getOpcode()) {
7026 default: llvm_unreachable("unexpected opcode!");
7027 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7028 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7029 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7030 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7032 // A shift by zero is a plain MOVr, not a MOVsi.
7033 unsigned Amt = Inst.getOperand(2).getImm();
7034 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7035 // A shift by 32 should be encoded as 0 when permitted
7036 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7038 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7040 TmpInst.setOpcode(Opc);
7041 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7042 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7043 if (Opc == ARM::MOVsi)
7044 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7045 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7046 TmpInst.addOperand(Inst.getOperand(4));
7047 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7052 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7054 TmpInst.setOpcode(ARM::MOVsi);
7055 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7056 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7057 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7058 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7059 TmpInst.addOperand(Inst.getOperand(3));
7060 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7064 case ARM::t2LDMIA_UPD: {
7065 // If this is a load of a single register, then we should use
7066 // a post-indexed LDR instruction instead, per the ARM ARM.
7067 if (Inst.getNumOperands() != 5)
7070 TmpInst.setOpcode(ARM::t2LDR_POST);
7071 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7072 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7073 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7074 TmpInst.addOperand(MCOperand::CreateImm(4));
7075 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7076 TmpInst.addOperand(Inst.getOperand(3));
7080 case ARM::t2STMDB_UPD: {
7081 // If this is a store of a single register, then we should use
7082 // a pre-indexed STR instruction instead, per the ARM ARM.
7083 if (Inst.getNumOperands() != 5)
7086 TmpInst.setOpcode(ARM::t2STR_PRE);
7087 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7088 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7089 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7090 TmpInst.addOperand(MCOperand::CreateImm(-4));
7091 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7092 TmpInst.addOperand(Inst.getOperand(3));
7096 case ARM::LDMIA_UPD:
7097 // If this is a load of a single register via a 'pop', then we should use
7098 // a post-indexed LDR instruction instead, per the ARM ARM.
7099 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7100 Inst.getNumOperands() == 5) {
7102 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7103 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7104 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7105 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7106 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7107 TmpInst.addOperand(MCOperand::CreateImm(4));
7108 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7109 TmpInst.addOperand(Inst.getOperand(3));
7114 case ARM::STMDB_UPD:
7115 // If this is a store of a single register via a 'push', then we should use
7116 // a pre-indexed STR instruction instead, per the ARM ARM.
7117 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7118 Inst.getNumOperands() == 5) {
7120 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7121 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7122 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7123 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7124 TmpInst.addOperand(MCOperand::CreateImm(-4));
7125 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7126 TmpInst.addOperand(Inst.getOperand(3));
7130 case ARM::t2ADDri12:
7131 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7132 // mnemonic was used (not "addw"), encoding T3 is preferred.
7133 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7134 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7136 Inst.setOpcode(ARM::t2ADDri);
7137 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7139 case ARM::t2SUBri12:
7140 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7141 // mnemonic was used (not "subw"), encoding T3 is preferred.
7142 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7143 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7145 Inst.setOpcode(ARM::t2SUBri);
7146 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7149 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7150 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7151 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7152 // to encoding T1 if <Rd> is omitted."
7153 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7154 Inst.setOpcode(ARM::tADDi3);
7159 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7160 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7161 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7162 // to encoding T1 if <Rd> is omitted."
7163 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7164 Inst.setOpcode(ARM::tSUBi3);
7169 case ARM::t2SUBri: {
7170 // If the destination and first source operand are the same, and
7171 // the flags are compatible with the current IT status, use encoding T2
7172 // instead of T3. For compatibility with the system 'as'. Make sure the
7173 // wide encoding wasn't explicit.
7174 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7175 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7176 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7177 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7178 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7179 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7180 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7183 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7184 ARM::tADDi8 : ARM::tSUBi8);
7185 TmpInst.addOperand(Inst.getOperand(0));
7186 TmpInst.addOperand(Inst.getOperand(5));
7187 TmpInst.addOperand(Inst.getOperand(0));
7188 TmpInst.addOperand(Inst.getOperand(2));
7189 TmpInst.addOperand(Inst.getOperand(3));
7190 TmpInst.addOperand(Inst.getOperand(4));
7194 case ARM::t2ADDrr: {
7195 // If the destination and first source operand are the same, and
7196 // there's no setting of the flags, use encoding T2 instead of T3.
7197 // Note that this is only for ADD, not SUB. This mirrors the system
7198 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7199 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7200 Inst.getOperand(5).getReg() != 0 ||
7201 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7202 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7205 TmpInst.setOpcode(ARM::tADDhirr);
7206 TmpInst.addOperand(Inst.getOperand(0));
7207 TmpInst.addOperand(Inst.getOperand(0));
7208 TmpInst.addOperand(Inst.getOperand(2));
7209 TmpInst.addOperand(Inst.getOperand(3));
7210 TmpInst.addOperand(Inst.getOperand(4));
7214 case ARM::tADDrSP: {
7215 // If the non-SP source operand and the destination operand are not the
7216 // same, we need to use the 32-bit encoding if it's available.
7217 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7218 Inst.setOpcode(ARM::t2ADDrr);
7219 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7225 // A Thumb conditional branch outside of an IT block is a tBcc.
7226 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7227 Inst.setOpcode(ARM::tBcc);
7232 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7233 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7234 Inst.setOpcode(ARM::t2Bcc);
7239 // If the conditional is AL or we're in an IT block, we really want t2B.
7240 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7241 Inst.setOpcode(ARM::t2B);
7246 // If the conditional is AL, we really want tB.
7247 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7248 Inst.setOpcode(ARM::tB);
7253 // If the register list contains any high registers, or if the writeback
7254 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7255 // instead if we're in Thumb2. Otherwise, this should have generated
7256 // an error in validateInstruction().
7257 unsigned Rn = Inst.getOperand(0).getReg();
7258 bool hasWritebackToken =
7259 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7260 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7261 bool listContainsBase;
7262 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7263 (!listContainsBase && !hasWritebackToken) ||
7264 (listContainsBase && hasWritebackToken)) {
7265 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7266 assert (isThumbTwo());
7267 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7268 // If we're switching to the updating version, we need to insert
7269 // the writeback tied operand.
7270 if (hasWritebackToken)
7271 Inst.insert(Inst.begin(),
7272 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7277 case ARM::tSTMIA_UPD: {
7278 // If the register list contains any high registers, we need to use
7279 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7280 // should have generated an error in validateInstruction().
7281 unsigned Rn = Inst.getOperand(0).getReg();
7282 bool listContainsBase;
7283 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7284 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7285 assert (isThumbTwo());
7286 Inst.setOpcode(ARM::t2STMIA_UPD);
7292 bool listContainsBase;
7293 // If the register list contains any high registers, we need to use
7294 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7295 // should have generated an error in validateInstruction().
7296 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7298 assert (isThumbTwo());
7299 Inst.setOpcode(ARM::t2LDMIA_UPD);
7300 // Add the base register and writeback operands.
7301 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7302 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7306 bool listContainsBase;
7307 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7309 assert (isThumbTwo());
7310 Inst.setOpcode(ARM::t2STMDB_UPD);
7311 // Add the base register and writeback operands.
7312 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7313 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7317 // If we can use the 16-bit encoding and the user didn't explicitly
7318 // request the 32-bit variant, transform it here.
7319 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7320 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7321 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7322 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7323 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7324 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7325 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7326 // The operands aren't in the same order for tMOVi8...
7328 TmpInst.setOpcode(ARM::tMOVi8);
7329 TmpInst.addOperand(Inst.getOperand(0));
7330 TmpInst.addOperand(Inst.getOperand(4));
7331 TmpInst.addOperand(Inst.getOperand(1));
7332 TmpInst.addOperand(Inst.getOperand(2));
7333 TmpInst.addOperand(Inst.getOperand(3));
7340 // If we can use the 16-bit encoding and the user didn't explicitly
7341 // request the 32-bit variant, transform it here.
7342 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7343 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7344 Inst.getOperand(2).getImm() == ARMCC::AL &&
7345 Inst.getOperand(4).getReg() == ARM::CPSR &&
7346 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7347 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7348 // The operands aren't the same for tMOV[S]r... (no cc_out)
7350 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7351 TmpInst.addOperand(Inst.getOperand(0));
7352 TmpInst.addOperand(Inst.getOperand(1));
7353 TmpInst.addOperand(Inst.getOperand(2));
7354 TmpInst.addOperand(Inst.getOperand(3));
7364 // If we can use the 16-bit encoding and the user didn't explicitly
7365 // request the 32-bit variant, transform it here.
7366 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7367 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7368 Inst.getOperand(2).getImm() == 0 &&
7369 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7370 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7372 switch (Inst.getOpcode()) {
7373 default: llvm_unreachable("Illegal opcode!");
7374 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7375 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7376 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7377 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7379 // The operands aren't the same for thumb1 (no rotate operand).
7381 TmpInst.setOpcode(NewOpc);
7382 TmpInst.addOperand(Inst.getOperand(0));
7383 TmpInst.addOperand(Inst.getOperand(1));
7384 TmpInst.addOperand(Inst.getOperand(3));
7385 TmpInst.addOperand(Inst.getOperand(4));
7392 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7393 // rrx shifts and asr/lsr of #32 is encoded as 0
7394 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7396 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7397 // Shifting by zero is accepted as a vanilla 'MOVr'
7399 TmpInst.setOpcode(ARM::MOVr);
7400 TmpInst.addOperand(Inst.getOperand(0));
7401 TmpInst.addOperand(Inst.getOperand(1));
7402 TmpInst.addOperand(Inst.getOperand(3));
7403 TmpInst.addOperand(Inst.getOperand(4));
7404 TmpInst.addOperand(Inst.getOperand(5));
7417 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7418 if (SOpc == ARM_AM::rrx) return false;
7419 switch (Inst.getOpcode()) {
7420 default: llvm_unreachable("unexpected opcode!");
7421 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7422 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7423 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7424 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7425 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7426 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7428 // If the shift is by zero, use the non-shifted instruction definition.
7429 // The exception is for right shifts, where 0 == 32
7430 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7431 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7433 TmpInst.setOpcode(newOpc);
7434 TmpInst.addOperand(Inst.getOperand(0));
7435 TmpInst.addOperand(Inst.getOperand(1));
7436 TmpInst.addOperand(Inst.getOperand(2));
7437 TmpInst.addOperand(Inst.getOperand(4));
7438 TmpInst.addOperand(Inst.getOperand(5));
7439 TmpInst.addOperand(Inst.getOperand(6));
7447 // The mask bits for all but the first condition are represented as
7448 // the low bit of the condition code value implies 't'. We currently
7449 // always have 1 implies 't', so XOR toggle the bits if the low bit
7450 // of the condition code is zero.
7451 MCOperand &MO = Inst.getOperand(1);
7452 unsigned Mask = MO.getImm();
7453 unsigned OrigMask = Mask;
7454 unsigned TZ = countTrailingZeros(Mask);
7455 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7456 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7457 Mask ^= (0xE << TZ) & 0xF;
7461 // Set up the IT block state according to the IT instruction we just
7463 assert(!inITBlock() && "nested IT blocks?!");
7464 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7465 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7466 ITState.CurPosition = 0;
7467 ITState.FirstCond = true;
7477 // Assemblers should use the narrow encodings of these instructions when permissible.
7478 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7479 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7480 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7481 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7482 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7483 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7484 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7486 switch (Inst.getOpcode()) {
7487 default: llvm_unreachable("unexpected opcode");
7488 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7489 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7490 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7491 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7492 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7493 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7496 TmpInst.setOpcode(NewOpc);
7497 TmpInst.addOperand(Inst.getOperand(0));
7498 TmpInst.addOperand(Inst.getOperand(5));
7499 TmpInst.addOperand(Inst.getOperand(1));
7500 TmpInst.addOperand(Inst.getOperand(2));
7501 TmpInst.addOperand(Inst.getOperand(3));
7502 TmpInst.addOperand(Inst.getOperand(4));
7513 // Assemblers should use the narrow encodings of these instructions when permissible.
7514 // These instructions are special in that they are commutable, so shorter encodings
7515 // are available more often.
7516 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7517 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7518 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7519 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7520 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7521 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7522 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7523 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7525 switch (Inst.getOpcode()) {
7526 default: llvm_unreachable("unexpected opcode");
7527 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7528 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7529 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7530 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7533 TmpInst.setOpcode(NewOpc);
7534 TmpInst.addOperand(Inst.getOperand(0));
7535 TmpInst.addOperand(Inst.getOperand(5));
7536 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7537 TmpInst.addOperand(Inst.getOperand(1));
7538 TmpInst.addOperand(Inst.getOperand(2));
7540 TmpInst.addOperand(Inst.getOperand(2));
7541 TmpInst.addOperand(Inst.getOperand(1));
7543 TmpInst.addOperand(Inst.getOperand(3));
7544 TmpInst.addOperand(Inst.getOperand(4));
7554 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7555 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7556 // suffix depending on whether they're in an IT block or not.
7557 unsigned Opc = Inst.getOpcode();
7558 const MCInstrDesc &MCID = MII.get(Opc);
7559 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7560 assert(MCID.hasOptionalDef() &&
7561 "optionally flag setting instruction missing optional def operand");
7562 assert(MCID.NumOperands == Inst.getNumOperands() &&
7563 "operand count mismatch!");
7564 // Find the optional-def operand (cc_out).
7567 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7570 // If we're parsing Thumb1, reject it completely.
7571 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7572 return Match_MnemonicFail;
7573 // If we're parsing Thumb2, which form is legal depends on whether we're
7575 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7577 return Match_RequiresITBlock;
7578 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7580 return Match_RequiresNotITBlock;
7582 // Some high-register supporting Thumb1 encodings only allow both registers
7583 // to be from r0-r7 when in Thumb2.
7584 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7585 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7586 isARMLowRegister(Inst.getOperand(2).getReg()))
7587 return Match_RequiresThumb2;
7588 // Others only require ARMv6 or later.
7589 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7590 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7591 isARMLowRegister(Inst.getOperand(1).getReg()))
7592 return Match_RequiresV6;
7593 return Match_Success;
7596 static const char *getSubtargetFeatureName(unsigned Val);
7598 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7599 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7600 MCStreamer &Out, unsigned &ErrorInfo,
7601 bool MatchingInlineAsm) {
7603 unsigned MatchResult;
7605 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7607 switch (MatchResult) {
7610 // Context sensitive operand constraints aren't handled by the matcher,
7611 // so check them here.
7612 if (validateInstruction(Inst, Operands)) {
7613 // Still progress the IT block, otherwise one wrong condition causes
7614 // nasty cascading errors.
7615 forwardITPosition();
7619 // Some instructions need post-processing to, for example, tweak which
7620 // encoding is selected. Loop on it while changes happen so the
7621 // individual transformations can chain off each other. E.g.,
7622 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7623 while (processInstruction(Inst, Operands))
7626 // Only move forward at the very end so that everything in validate
7627 // and process gets a consistent answer about whether we're in an IT
7629 forwardITPosition();
7631 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7632 // doesn't actually encode.
7633 if (Inst.getOpcode() == ARM::ITasm)
7637 Out.EmitInstruction(Inst);
7639 case Match_MissingFeature: {
7640 assert(ErrorInfo && "Unknown missing feature!");
7641 // Special case the error message for the very common case where only
7642 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7643 std::string Msg = "instruction requires:";
7645 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7646 if (ErrorInfo & Mask) {
7648 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7652 return Error(IDLoc, Msg);
7654 case Match_InvalidOperand: {
7655 SMLoc ErrorLoc = IDLoc;
7656 if (ErrorInfo != ~0U) {
7657 if (ErrorInfo >= Operands.size())
7658 return Error(IDLoc, "too few operands for instruction");
7660 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7661 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7664 return Error(ErrorLoc, "invalid operand for instruction");
7666 case Match_MnemonicFail:
7667 return Error(IDLoc, "invalid instruction",
7668 ((ARMOperand*)Operands[0])->getLocRange());
7669 case Match_RequiresNotITBlock:
7670 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7671 case Match_RequiresITBlock:
7672 return Error(IDLoc, "instruction only valid inside IT block");
7673 case Match_RequiresV6:
7674 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7675 case Match_RequiresThumb2:
7676 return Error(IDLoc, "instruction variant requires Thumb2");
7677 case Match_ImmRange0_4: {
7678 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7679 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7680 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7682 case Match_ImmRange0_15: {
7683 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7684 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7685 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7689 llvm_unreachable("Implement any new match types added!");
7692 /// parseDirective parses the arm specific directives
7693 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7694 StringRef IDVal = DirectiveID.getIdentifier();
7695 if (IDVal == ".word")
7696 return parseDirectiveWord(4, DirectiveID.getLoc());
7697 else if (IDVal == ".thumb")
7698 return parseDirectiveThumb(DirectiveID.getLoc());
7699 else if (IDVal == ".arm")
7700 return parseDirectiveARM(DirectiveID.getLoc());
7701 else if (IDVal == ".thumb_func")
7702 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7703 else if (IDVal == ".code")
7704 return parseDirectiveCode(DirectiveID.getLoc());
7705 else if (IDVal == ".syntax")
7706 return parseDirectiveSyntax(DirectiveID.getLoc());
7707 else if (IDVal == ".unreq")
7708 return parseDirectiveUnreq(DirectiveID.getLoc());
7709 else if (IDVal == ".arch")
7710 return parseDirectiveArch(DirectiveID.getLoc());
7711 else if (IDVal == ".eabi_attribute")
7712 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7713 else if (IDVal == ".fnstart")
7714 return parseDirectiveFnStart(DirectiveID.getLoc());
7715 else if (IDVal == ".fnend")
7716 return parseDirectiveFnEnd(DirectiveID.getLoc());
7717 else if (IDVal == ".cantunwind")
7718 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7719 else if (IDVal == ".personality")
7720 return parseDirectivePersonality(DirectiveID.getLoc());
7721 else if (IDVal == ".handlerdata")
7722 return parseDirectiveHandlerData(DirectiveID.getLoc());
7723 else if (IDVal == ".setfp")
7724 return parseDirectiveSetFP(DirectiveID.getLoc());
7725 else if (IDVal == ".pad")
7726 return parseDirectivePad(DirectiveID.getLoc());
7727 else if (IDVal == ".save")
7728 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7729 else if (IDVal == ".vsave")
7730 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7734 /// parseDirectiveWord
7735 /// ::= .word [ expression (, expression)* ]
7736 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7737 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7739 const MCExpr *Value;
7740 if (getParser().parseExpression(Value))
7743 getParser().getStreamer().EmitValue(Value, Size);
7745 if (getLexer().is(AsmToken::EndOfStatement))
7748 // FIXME: Improve diagnostic.
7749 if (getLexer().isNot(AsmToken::Comma))
7750 return Error(L, "unexpected token in directive");
7759 /// parseDirectiveThumb
7761 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7762 if (getLexer().isNot(AsmToken::EndOfStatement))
7763 return Error(L, "unexpected token in directive");
7767 return Error(L, "target does not support Thumb mode");
7771 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7775 /// parseDirectiveARM
7777 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7778 if (getLexer().isNot(AsmToken::EndOfStatement))
7779 return Error(L, "unexpected token in directive");
7783 return Error(L, "target does not support ARM mode");
7787 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7791 /// parseDirectiveThumbFunc
7792 /// ::= .thumbfunc symbol_name
7793 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7794 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7795 bool isMachO = MAI->hasSubsectionsViaSymbols();
7797 bool needFuncName = true;
7799 // Darwin asm has (optionally) function name after .thumb_func direction
7802 const AsmToken &Tok = Parser.getTok();
7803 if (Tok.isNot(AsmToken::EndOfStatement)) {
7804 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7805 return Error(L, "unexpected token in .thumb_func directive");
7806 Name = Tok.getIdentifier();
7807 Parser.Lex(); // Consume the identifier token.
7808 needFuncName = false;
7812 if (getLexer().isNot(AsmToken::EndOfStatement))
7813 return Error(L, "unexpected token in directive");
7815 // Eat the end of statement and any blank lines that follow.
7816 while (getLexer().is(AsmToken::EndOfStatement))
7819 // FIXME: assuming function name will be the line following .thumb_func
7820 // We really should be checking the next symbol definition even if there's
7821 // stuff in between.
7823 Name = Parser.getTok().getIdentifier();
7826 // Mark symbol as a thumb symbol.
7827 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7828 getParser().getStreamer().EmitThumbFunc(Func);
7832 /// parseDirectiveSyntax
7833 /// ::= .syntax unified | divided
7834 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7835 const AsmToken &Tok = Parser.getTok();
7836 if (Tok.isNot(AsmToken::Identifier))
7837 return Error(L, "unexpected token in .syntax directive");
7838 StringRef Mode = Tok.getString();
7839 if (Mode == "unified" || Mode == "UNIFIED")
7841 else if (Mode == "divided" || Mode == "DIVIDED")
7842 return Error(L, "'.syntax divided' arm asssembly not supported");
7844 return Error(L, "unrecognized syntax mode in .syntax directive");
7846 if (getLexer().isNot(AsmToken::EndOfStatement))
7847 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7850 // TODO tell the MC streamer the mode
7851 // getParser().getStreamer().Emit???();
7855 /// parseDirectiveCode
7856 /// ::= .code 16 | 32
7857 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7858 const AsmToken &Tok = Parser.getTok();
7859 if (Tok.isNot(AsmToken::Integer))
7860 return Error(L, "unexpected token in .code directive");
7861 int64_t Val = Parser.getTok().getIntVal();
7867 return Error(L, "invalid operand to .code directive");
7869 if (getLexer().isNot(AsmToken::EndOfStatement))
7870 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7875 return Error(L, "target does not support Thumb mode");
7879 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7882 return Error(L, "target does not support ARM mode");
7886 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7892 /// parseDirectiveReq
7893 /// ::= name .req registername
7894 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7895 Parser.Lex(); // Eat the '.req' token.
7897 SMLoc SRegLoc, ERegLoc;
7898 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7899 Parser.eatToEndOfStatement();
7900 return Error(SRegLoc, "register name expected");
7903 // Shouldn't be anything else.
7904 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7905 Parser.eatToEndOfStatement();
7906 return Error(Parser.getTok().getLoc(),
7907 "unexpected input in .req directive.");
7910 Parser.Lex(); // Consume the EndOfStatement
7912 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7913 return Error(SRegLoc, "redefinition of '" + Name +
7914 "' does not match original.");
7919 /// parseDirectiveUneq
7920 /// ::= .unreq registername
7921 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7922 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7923 Parser.eatToEndOfStatement();
7924 return Error(L, "unexpected input in .unreq directive.");
7926 RegisterReqs.erase(Parser.getTok().getIdentifier());
7927 Parser.Lex(); // Eat the identifier.
7931 /// parseDirectiveArch
7933 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7937 /// parseDirectiveEabiAttr
7938 /// ::= .eabi_attribute int, int
7939 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7943 /// parseDirectiveFnStart
7945 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7946 if (FnStartLoc.isValid()) {
7947 Error(L, ".fnstart starts before the end of previous one");
7948 Error(FnStartLoc, "previous .fnstart starts here");
7953 getParser().getStreamer().EmitFnStart();
7957 /// parseDirectiveFnEnd
7959 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7960 // Check the ordering of unwind directives
7961 if (!FnStartLoc.isValid())
7962 return Error(L, ".fnstart must precede .fnend directive");
7964 // Reset the unwind directives parser state
7965 resetUnwindDirectiveParserState();
7967 getParser().getStreamer().EmitFnEnd();
7971 /// parseDirectiveCantUnwind
7973 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7974 // Check the ordering of unwind directives
7976 if (!FnStartLoc.isValid())
7977 return Error(L, ".fnstart must precede .cantunwind directive");
7978 if (HandlerDataLoc.isValid()) {
7979 Error(L, ".cantunwind can't be used with .handlerdata directive");
7980 Error(HandlerDataLoc, ".handlerdata was specified here");
7983 if (PersonalityLoc.isValid()) {
7984 Error(L, ".cantunwind can't be used with .personality directive");
7985 Error(PersonalityLoc, ".personality was specified here");
7989 getParser().getStreamer().EmitCantUnwind();
7993 /// parseDirectivePersonality
7994 /// ::= .personality name
7995 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7996 // Check the ordering of unwind directives
7998 if (!FnStartLoc.isValid())
7999 return Error(L, ".fnstart must precede .personality directive");
8000 if (CantUnwindLoc.isValid()) {
8001 Error(L, ".personality can't be used with .cantunwind directive");
8002 Error(CantUnwindLoc, ".cantunwind was specified here");
8005 if (HandlerDataLoc.isValid()) {
8006 Error(L, ".personality must precede .handlerdata directive");
8007 Error(HandlerDataLoc, ".handlerdata was specified here");
8011 // Parse the name of the personality routine
8012 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8013 Parser.eatToEndOfStatement();
8014 return Error(L, "unexpected input in .personality directive.");
8016 StringRef Name(Parser.getTok().getIdentifier());
8019 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8020 getParser().getStreamer().EmitPersonality(PR);
8024 /// parseDirectiveHandlerData
8025 /// ::= .handlerdata
8026 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8027 // Check the ordering of unwind directives
8029 if (!FnStartLoc.isValid())
8030 return Error(L, ".fnstart must precede .personality directive");
8031 if (CantUnwindLoc.isValid()) {
8032 Error(L, ".handlerdata can't be used with .cantunwind directive");
8033 Error(CantUnwindLoc, ".cantunwind was specified here");
8037 getParser().getStreamer().EmitHandlerData();
8041 /// parseDirectiveSetFP
8042 /// ::= .setfp fpreg, spreg [, offset]
8043 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8044 // Check the ordering of unwind directives
8045 if (!FnStartLoc.isValid())
8046 return Error(L, ".fnstart must precede .setfp directive");
8047 if (HandlerDataLoc.isValid())
8048 return Error(L, ".setfp must precede .handlerdata directive");
8051 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8052 int NewFPReg = tryParseRegister();
8054 return Error(NewFPRegLoc, "frame pointer register expected");
8057 if (!Parser.getTok().is(AsmToken::Comma))
8058 return Error(Parser.getTok().getLoc(), "comma expected");
8059 Parser.Lex(); // skip comma
8062 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8063 int NewSPReg = tryParseRegister();
8065 return Error(NewSPRegLoc, "stack pointer register expected");
8067 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8068 return Error(NewSPRegLoc,
8069 "register should be either $sp or the latest fp register");
8071 // Update the frame pointer register
8076 if (Parser.getTok().is(AsmToken::Comma)) {
8077 Parser.Lex(); // skip comma
8079 if (Parser.getTok().isNot(AsmToken::Hash) &&
8080 Parser.getTok().isNot(AsmToken::Dollar)) {
8081 return Error(Parser.getTok().getLoc(), "'#' expected");
8083 Parser.Lex(); // skip hash token.
8085 const MCExpr *OffsetExpr;
8086 SMLoc ExLoc = Parser.getTok().getLoc();
8088 if (getParser().parseExpression(OffsetExpr, EndLoc))
8089 return Error(ExLoc, "malformed setfp offset");
8090 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8092 return Error(ExLoc, "setfp offset must be an immediate");
8094 Offset = CE->getValue();
8097 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8098 static_cast<unsigned>(NewSPReg),
8105 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8106 // Check the ordering of unwind directives
8107 if (!FnStartLoc.isValid())
8108 return Error(L, ".fnstart must precede .pad directive");
8109 if (HandlerDataLoc.isValid())
8110 return Error(L, ".pad must precede .handlerdata directive");
8113 if (Parser.getTok().isNot(AsmToken::Hash) &&
8114 Parser.getTok().isNot(AsmToken::Dollar)) {
8115 return Error(Parser.getTok().getLoc(), "'#' expected");
8117 Parser.Lex(); // skip hash token.
8119 const MCExpr *OffsetExpr;
8120 SMLoc ExLoc = Parser.getTok().getLoc();
8122 if (getParser().parseExpression(OffsetExpr, EndLoc))
8123 return Error(ExLoc, "malformed pad offset");
8124 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8126 return Error(ExLoc, "pad offset must be an immediate");
8128 getParser().getStreamer().EmitPad(CE->getValue());
8132 /// parseDirectiveRegSave
8133 /// ::= .save { registers }
8134 /// ::= .vsave { registers }
8135 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8136 // Check the ordering of unwind directives
8137 if (!FnStartLoc.isValid())
8138 return Error(L, ".fnstart must precede .save or .vsave directives");
8139 if (HandlerDataLoc.isValid())
8140 return Error(L, ".save or .vsave must precede .handlerdata directive");
8142 // RAII object to make sure parsed operands are deleted.
8143 struct CleanupObject {
8144 SmallVector<MCParsedAsmOperand *, 1> Operands;
8146 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8151 // Parse the register list
8152 if (parseRegisterList(CO.Operands))
8154 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
8155 if (!IsVector && !Op->isRegList())
8156 return Error(L, ".save expects GPR registers");
8157 if (IsVector && !Op->isDPRRegList())
8158 return Error(L, ".vsave expects DPR registers");
8160 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8164 /// Force static initialization.
8165 extern "C" void LLVMInitializeARMAsmParser() {
8166 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8167 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8170 #define GET_REGISTER_MATCHER
8171 #define GET_SUBTARGET_FEATURE_NAME
8172 #define GET_MATCHER_IMPLEMENTATION
8173 #include "ARMGenAsmMatcher.inc"
8175 // Define this matcher function after the auto-generated include so we
8176 // have the match class enum definitions.
8177 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8179 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8180 // If the kind is a token for a literal immediate, check if our asm
8181 // operand matches. This is for InstAliases which have a fixed-value
8182 // immediate in the syntax.
8183 if (Kind == MCK__35_0 && Op->isImm()) {
8184 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8186 return Match_InvalidOperand;
8187 if (CE->getValue() == 0)
8188 return Match_Success;
8190 return Match_InvalidOperand;