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 "ARMFeatures.h"
11 #include "llvm/MC/MCTargetAsmParser.h"
12 #include "MCTargetDesc/ARMAddressingModes.h"
13 #include "MCTargetDesc/ARMBaseInfo.h"
14 #include "MCTargetDesc/ARMMCExpr.h"
15 #include "llvm/ADT/BitVector.h"
16 #include "llvm/ADT/OwningPtr.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/ADT/Twine.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCAssembler.h"
23 #include "llvm/MC/MCContext.h"
24 #include "llvm/MC/MCELFStreamer.h"
25 #include "llvm/MC/MCExpr.h"
26 #include "llvm/MC/MCInst.h"
27 #include "llvm/MC/MCInstrDesc.h"
28 #include "llvm/MC/MCInstrInfo.h"
29 #include "llvm/MC/MCParser/MCAsmLexer.h"
30 #include "llvm/MC/MCParser/MCAsmParser.h"
31 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
32 #include "llvm/MC/MCRegisterInfo.h"
33 #include "llvm/MC/MCStreamer.h"
34 #include "llvm/MC/MCSubtargetInfo.h"
35 #include "llvm/Support/ELF.h"
36 #include "llvm/Support/MathExtras.h"
37 #include "llvm/Support/SourceMgr.h"
38 #include "llvm/Support/TargetRegistry.h"
39 #include "llvm/Support/raw_ostream.h"
47 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
49 class ARMAsmParser : public MCTargetAsmParser {
52 const MCInstrInfo &MII;
53 const MCRegisterInfo *MRI;
55 ARMTargetStreamer &getTargetStreamer() {
56 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
57 return static_cast<ARMTargetStreamer &>(TS);
60 // Unwind directives state
66 void resetUnwindDirectiveParserState() {
68 CantUnwindLoc = SMLoc();
69 PersonalityLoc = SMLoc();
70 HandlerDataLoc = SMLoc();
74 // Map of register aliases registers via the .req directive.
75 StringMap<unsigned> RegisterReqs;
78 ARMCC::CondCodes Cond; // Condition for IT block.
79 unsigned Mask:4; // Condition mask for instructions.
80 // Starting at first 1 (from lsb).
81 // '1' condition as indicated in IT.
82 // '0' inverse of condition (else).
83 // Count of instructions in IT block is
84 // 4 - trailingzeroes(mask)
86 bool FirstCond; // Explicit flag for when we're parsing the
87 // First instruction in the IT block. It's
88 // implied in the mask, so needs special
91 unsigned CurPosition; // Current position in parsing of IT
92 // block. In range [0,3]. Initialized
93 // according to count of instructions in block.
94 // ~0U if no active IT block.
96 bool inITBlock() { return ITState.CurPosition != ~0U;}
97 void forwardITPosition() {
98 if (!inITBlock()) return;
99 // Move to the next instruction in the IT block, if there is one. If not,
100 // mark the block as done.
101 unsigned TZ = countTrailingZeros(ITState.Mask);
102 if (++ITState.CurPosition == 5 - TZ)
103 ITState.CurPosition = ~0U; // Done with the IT block after this.
107 MCAsmParser &getParser() const { return Parser; }
108 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
110 bool Warning(SMLoc L, const Twine &Msg,
111 ArrayRef<SMRange> Ranges = None) {
112 return Parser.Warning(L, Msg, Ranges);
114 bool Error(SMLoc L, const Twine &Msg,
115 ArrayRef<SMRange> Ranges = None) {
116 return Parser.Error(L, Msg, Ranges);
119 int tryParseRegister();
120 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
121 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
122 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
123 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
124 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
125 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
126 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
127 unsigned &ShiftAmount);
128 bool parseDirectiveWord(unsigned Size, SMLoc L);
129 bool parseDirectiveThumb(SMLoc L);
130 bool parseDirectiveARM(SMLoc L);
131 bool parseDirectiveThumbFunc(SMLoc L);
132 bool parseDirectiveCode(SMLoc L);
133 bool parseDirectiveSyntax(SMLoc L);
134 bool parseDirectiveReq(StringRef Name, SMLoc L);
135 bool parseDirectiveUnreq(SMLoc L);
136 bool parseDirectiveArch(SMLoc L);
137 bool parseDirectiveEabiAttr(SMLoc L);
138 bool parseDirectiveFnStart(SMLoc L);
139 bool parseDirectiveFnEnd(SMLoc L);
140 bool parseDirectiveCantUnwind(SMLoc L);
141 bool parseDirectivePersonality(SMLoc L);
142 bool parseDirectiveHandlerData(SMLoc L);
143 bool parseDirectiveSetFP(SMLoc L);
144 bool parseDirectivePad(SMLoc L);
145 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
147 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
148 bool &CarrySetting, unsigned &ProcessorIMod,
150 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
151 bool &CanAcceptCarrySet,
152 bool &CanAcceptPredicationCode);
154 bool isThumb() const {
155 // FIXME: Can tablegen auto-generate this?
156 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
158 bool isThumbOne() const {
159 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
161 bool isThumbTwo() const {
162 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
164 bool hasThumb() const {
165 return STI.getFeatureBits() & ARM::HasV4TOps;
167 bool hasV6Ops() const {
168 return STI.getFeatureBits() & ARM::HasV6Ops;
170 bool hasV6MOps() const {
171 return STI.getFeatureBits() & ARM::HasV6MOps;
173 bool hasV7Ops() const {
174 return STI.getFeatureBits() & ARM::HasV7Ops;
176 bool hasV8Ops() const {
177 return STI.getFeatureBits() & ARM::HasV8Ops;
179 bool hasARM() const {
180 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
184 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
185 setAvailableFeatures(FB);
187 bool isMClass() const {
188 return STI.getFeatureBits() & ARM::FeatureMClass;
191 /// @name Auto-generated Match Functions
194 #define GET_ASSEMBLER_HEADER
195 #include "ARMGenAsmMatcher.inc"
199 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
200 OperandMatchResultTy parseCoprocNumOperand(
201 SmallVectorImpl<MCParsedAsmOperand*>&);
202 OperandMatchResultTy parseCoprocRegOperand(
203 SmallVectorImpl<MCParsedAsmOperand*>&);
204 OperandMatchResultTy parseCoprocOptionOperand(
205 SmallVectorImpl<MCParsedAsmOperand*>&);
206 OperandMatchResultTy parseMemBarrierOptOperand(
207 SmallVectorImpl<MCParsedAsmOperand*>&);
208 OperandMatchResultTy parseInstSyncBarrierOptOperand(
209 SmallVectorImpl<MCParsedAsmOperand*>&);
210 OperandMatchResultTy parseProcIFlagsOperand(
211 SmallVectorImpl<MCParsedAsmOperand*>&);
212 OperandMatchResultTy parseMSRMaskOperand(
213 SmallVectorImpl<MCParsedAsmOperand*>&);
214 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
215 StringRef Op, int Low, int High);
216 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
217 return parsePKHImm(O, "lsl", 0, 31);
219 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
220 return parsePKHImm(O, "asr", 1, 32);
222 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
223 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
224 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
225 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
226 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
227 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
228 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
229 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
230 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
233 // Asm Match Converter Methods
234 void cvtThumbMultiply(MCInst &Inst,
235 const SmallVectorImpl<MCParsedAsmOperand*> &);
236 void cvtThumbBranches(MCInst &Inst,
237 const SmallVectorImpl<MCParsedAsmOperand*> &);
239 bool validateInstruction(MCInst &Inst,
240 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
241 bool processInstruction(MCInst &Inst,
242 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
243 bool shouldOmitCCOutOperand(StringRef Mnemonic,
244 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
245 bool shouldOmitPredicateOperand(StringRef Mnemonic,
246 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
248 enum ARMMatchResultTy {
249 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
250 Match_RequiresNotITBlock,
252 Match_RequiresThumb2,
253 #define GET_OPERAND_DIAGNOSTIC_TYPES
254 #include "ARMGenAsmMatcher.inc"
258 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
259 const MCInstrInfo &MII)
260 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
261 MCAsmParserExtension::Initialize(_Parser);
263 // Cache the MCRegisterInfo.
264 MRI = getContext().getRegisterInfo();
266 // Initialize the set of available features.
267 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
269 // Not in an ITBlock to start with.
270 ITState.CurPosition = ~0U;
273 // Implementation of the MCTargetAsmParser interface:
274 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
275 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
277 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
278 bool ParseDirective(AsmToken DirectiveID);
280 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
281 unsigned checkTargetMatchPredicate(MCInst &Inst);
283 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
284 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
285 MCStreamer &Out, unsigned &ErrorInfo,
286 bool MatchingInlineAsm);
288 } // end anonymous namespace
292 /// ARMOperand - Instances of this class represent a parsed ARM machine
294 class ARMOperand : public MCParsedAsmOperand {
304 k_InstSyncBarrierOpt,
315 k_VectorListAllLanes,
321 k_BitfieldDescriptor,
325 SMLoc StartLoc, EndLoc;
326 SmallVector<unsigned, 8> Registers;
329 ARMCC::CondCodes Val;
336 struct CoprocOptionOp {
349 ARM_ISB::InstSyncBOpt Val;
353 ARM_PROC::IFlags Val;
369 // A vector register list is a sequential list of 1 to 4 registers.
370 struct VectorListOp {
377 struct VectorIndexOp {
385 /// Combined record for all forms of ARM address expressions.
388 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
390 const MCConstantExpr *OffsetImm; // Offset immediate value
391 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
392 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
393 unsigned ShiftImm; // shift for OffsetReg.
394 unsigned Alignment; // 0 = no alignment specified
395 // n = alignment in bytes (2, 4, 8, 16, or 32)
396 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
399 struct PostIdxRegOp {
402 ARM_AM::ShiftOpc ShiftTy;
406 struct ShifterImmOp {
411 struct RegShiftedRegOp {
412 ARM_AM::ShiftOpc ShiftTy;
418 struct RegShiftedImmOp {
419 ARM_AM::ShiftOpc ShiftTy;
436 struct CoprocOptionOp CoprocOption;
437 struct MBOptOp MBOpt;
438 struct ISBOptOp ISBOpt;
439 struct ITMaskOp ITMask;
440 struct IFlagsOp IFlags;
441 struct MMaskOp MMask;
444 struct VectorListOp VectorList;
445 struct VectorIndexOp VectorIndex;
447 struct MemoryOp Memory;
448 struct PostIdxRegOp PostIdxReg;
449 struct ShifterImmOp ShifterImm;
450 struct RegShiftedRegOp RegShiftedReg;
451 struct RegShiftedImmOp RegShiftedImm;
452 struct RotImmOp RotImm;
453 struct BitfieldOp Bitfield;
456 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
458 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
460 StartLoc = o.StartLoc;
477 case k_DPRRegisterList:
478 case k_SPRRegisterList:
479 Registers = o.Registers;
482 case k_VectorListAllLanes:
483 case k_VectorListIndexed:
484 VectorList = o.VectorList;
491 CoprocOption = o.CoprocOption;
496 case k_MemBarrierOpt:
499 case k_InstSyncBarrierOpt:
504 case k_PostIndexRegister:
505 PostIdxReg = o.PostIdxReg;
513 case k_ShifterImmediate:
514 ShifterImm = o.ShifterImm;
516 case k_ShiftedRegister:
517 RegShiftedReg = o.RegShiftedReg;
519 case k_ShiftedImmediate:
520 RegShiftedImm = o.RegShiftedImm;
522 case k_RotateImmediate:
525 case k_BitfieldDescriptor:
526 Bitfield = o.Bitfield;
529 VectorIndex = o.VectorIndex;
534 /// getStartLoc - Get the location of the first token of this operand.
535 SMLoc getStartLoc() const { return StartLoc; }
536 /// getEndLoc - Get the location of the last token of this operand.
537 SMLoc getEndLoc() const { return EndLoc; }
538 /// getLocRange - Get the range between the first and last token of this
540 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
542 ARMCC::CondCodes getCondCode() const {
543 assert(Kind == k_CondCode && "Invalid access!");
547 unsigned getCoproc() const {
548 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
552 StringRef getToken() const {
553 assert(Kind == k_Token && "Invalid access!");
554 return StringRef(Tok.Data, Tok.Length);
557 unsigned getReg() const {
558 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
562 const SmallVectorImpl<unsigned> &getRegList() const {
563 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
564 Kind == k_SPRRegisterList) && "Invalid access!");
568 const MCExpr *getImm() const {
569 assert(isImm() && "Invalid access!");
573 unsigned getVectorIndex() const {
574 assert(Kind == k_VectorIndex && "Invalid access!");
575 return VectorIndex.Val;
578 ARM_MB::MemBOpt getMemBarrierOpt() const {
579 assert(Kind == k_MemBarrierOpt && "Invalid access!");
583 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
584 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
588 ARM_PROC::IFlags getProcIFlags() const {
589 assert(Kind == k_ProcIFlags && "Invalid access!");
593 unsigned getMSRMask() const {
594 assert(Kind == k_MSRMask && "Invalid access!");
598 bool isCoprocNum() const { return Kind == k_CoprocNum; }
599 bool isCoprocReg() const { return Kind == k_CoprocReg; }
600 bool isCoprocOption() const { return Kind == k_CoprocOption; }
601 bool isCondCode() const { return Kind == k_CondCode; }
602 bool isCCOut() const { return Kind == k_CCOut; }
603 bool isITMask() const { return Kind == k_ITCondMask; }
604 bool isITCondCode() const { return Kind == k_CondCode; }
605 bool isImm() const { return Kind == k_Immediate; }
606 // checks whether this operand is an unsigned offset which fits is a field
607 // of specified width and scaled by a specific number of bits
608 template<unsigned width, unsigned scale>
609 bool isUnsignedOffset() const {
610 if (!isImm()) return false;
611 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
612 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
613 int64_t Val = CE->getValue();
614 int64_t Align = 1LL << scale;
615 int64_t Max = Align * ((1LL << width) - 1);
616 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
620 // checks whether this operand is an signed offset which fits is a field
621 // of specified width and scaled by a specific number of bits
622 template<unsigned width, unsigned scale>
623 bool isSignedOffset() const {
624 if (!isImm()) return false;
625 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
626 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
627 int64_t Val = CE->getValue();
628 int64_t Align = 1LL << scale;
629 int64_t Max = Align * ((1LL << (width-1)) - 1);
630 int64_t Min = -Align * (1LL << (width-1));
631 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
636 // checks whether this operand is a memory operand computed as an offset
637 // applied to PC. the offset may have 8 bits of magnitude and is represented
638 // with two bits of shift. textually it may be either [pc, #imm], #imm or
639 // relocable expression...
640 bool isThumbMemPC() const {
643 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
644 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
645 if (!CE) return false;
646 Val = CE->getValue();
649 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
650 if(Memory.BaseRegNum != ARM::PC) return false;
651 Val = Memory.OffsetImm->getValue();
654 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
656 bool isFPImm() const {
657 if (!isImm()) return false;
658 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
659 if (!CE) return false;
660 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
663 bool isFBits16() const {
664 if (!isImm()) return false;
665 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
666 if (!CE) return false;
667 int64_t Value = CE->getValue();
668 return Value >= 0 && Value <= 16;
670 bool isFBits32() const {
671 if (!isImm()) return false;
672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
673 if (!CE) return false;
674 int64_t Value = CE->getValue();
675 return Value >= 1 && Value <= 32;
677 bool isImm8s4() const {
678 if (!isImm()) return false;
679 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
680 if (!CE) return false;
681 int64_t Value = CE->getValue();
682 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
684 bool isImm0_1020s4() const {
685 if (!isImm()) return false;
686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
687 if (!CE) return false;
688 int64_t Value = CE->getValue();
689 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
691 bool isImm0_508s4() const {
692 if (!isImm()) return false;
693 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
694 if (!CE) return false;
695 int64_t Value = CE->getValue();
696 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
698 bool isImm0_508s4Neg() const {
699 if (!isImm()) return false;
700 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
701 if (!CE) return false;
702 int64_t Value = -CE->getValue();
703 // explicitly exclude zero. we want that to use the normal 0_508 version.
704 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
706 bool isImm0_239() const {
707 if (!isImm()) return false;
708 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
709 if (!CE) return false;
710 int64_t Value = CE->getValue();
711 return Value >= 0 && Value < 240;
713 bool isImm0_255() const {
714 if (!isImm()) return false;
715 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
716 if (!CE) return false;
717 int64_t Value = CE->getValue();
718 return Value >= 0 && Value < 256;
720 bool isImm0_4095() const {
721 if (!isImm()) return false;
722 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
723 if (!CE) return false;
724 int64_t Value = CE->getValue();
725 return Value >= 0 && Value < 4096;
727 bool isImm0_4095Neg() const {
728 if (!isImm()) return false;
729 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
730 if (!CE) return false;
731 int64_t Value = -CE->getValue();
732 return Value > 0 && Value < 4096;
734 bool isImm0_1() const {
735 if (!isImm()) return false;
736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
737 if (!CE) return false;
738 int64_t Value = CE->getValue();
739 return Value >= 0 && Value < 2;
741 bool isImm0_3() const {
742 if (!isImm()) return false;
743 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
744 if (!CE) return false;
745 int64_t Value = CE->getValue();
746 return Value >= 0 && Value < 4;
748 bool isImm0_7() const {
749 if (!isImm()) return false;
750 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
751 if (!CE) return false;
752 int64_t Value = CE->getValue();
753 return Value >= 0 && Value < 8;
755 bool isImm0_15() const {
756 if (!isImm()) return false;
757 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
758 if (!CE) return false;
759 int64_t Value = CE->getValue();
760 return Value >= 0 && Value < 16;
762 bool isImm0_31() const {
763 if (!isImm()) return false;
764 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
765 if (!CE) return false;
766 int64_t Value = CE->getValue();
767 return Value >= 0 && Value < 32;
769 bool isImm0_63() const {
770 if (!isImm()) return false;
771 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
772 if (!CE) return false;
773 int64_t Value = CE->getValue();
774 return Value >= 0 && Value < 64;
776 bool isImm8() const {
777 if (!isImm()) return false;
778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
779 if (!CE) return false;
780 int64_t Value = CE->getValue();
783 bool isImm16() const {
784 if (!isImm()) return false;
785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
786 if (!CE) return false;
787 int64_t Value = CE->getValue();
790 bool isImm32() const {
791 if (!isImm()) return false;
792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
793 if (!CE) return false;
794 int64_t Value = CE->getValue();
797 bool isShrImm8() const {
798 if (!isImm()) return false;
799 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
800 if (!CE) return false;
801 int64_t Value = CE->getValue();
802 return Value > 0 && Value <= 8;
804 bool isShrImm16() const {
805 if (!isImm()) return false;
806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
807 if (!CE) return false;
808 int64_t Value = CE->getValue();
809 return Value > 0 && Value <= 16;
811 bool isShrImm32() const {
812 if (!isImm()) return false;
813 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
814 if (!CE) return false;
815 int64_t Value = CE->getValue();
816 return Value > 0 && Value <= 32;
818 bool isShrImm64() const {
819 if (!isImm()) return false;
820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
821 if (!CE) return false;
822 int64_t Value = CE->getValue();
823 return Value > 0 && Value <= 64;
825 bool isImm1_7() const {
826 if (!isImm()) return false;
827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
828 if (!CE) return false;
829 int64_t Value = CE->getValue();
830 return Value > 0 && Value < 8;
832 bool isImm1_15() const {
833 if (!isImm()) return false;
834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
835 if (!CE) return false;
836 int64_t Value = CE->getValue();
837 return Value > 0 && Value < 16;
839 bool isImm1_31() const {
840 if (!isImm()) return false;
841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = CE->getValue();
844 return Value > 0 && Value < 32;
846 bool isImm1_16() const {
847 if (!isImm()) return false;
848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
849 if (!CE) return false;
850 int64_t Value = CE->getValue();
851 return Value > 0 && Value < 17;
853 bool isImm1_32() const {
854 if (!isImm()) return false;
855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
856 if (!CE) return false;
857 int64_t Value = CE->getValue();
858 return Value > 0 && Value < 33;
860 bool isImm0_32() const {
861 if (!isImm()) return false;
862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
863 if (!CE) return false;
864 int64_t Value = CE->getValue();
865 return Value >= 0 && Value < 33;
867 bool isImm0_65535() const {
868 if (!isImm()) return false;
869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
870 if (!CE) return false;
871 int64_t Value = CE->getValue();
872 return Value >= 0 && Value < 65536;
874 bool isImm256_65535Expr() const {
875 if (!isImm()) return false;
876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
877 // If it's not a constant expression, it'll generate a fixup and be
879 if (!CE) return true;
880 int64_t Value = CE->getValue();
881 return Value >= 256 && Value < 65536;
883 bool isImm0_65535Expr() const {
884 if (!isImm()) return false;
885 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
886 // If it's not a constant expression, it'll generate a fixup and be
888 if (!CE) return true;
889 int64_t Value = CE->getValue();
890 return Value >= 0 && Value < 65536;
892 bool isImm24bit() const {
893 if (!isImm()) return false;
894 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
895 if (!CE) return false;
896 int64_t Value = CE->getValue();
897 return Value >= 0 && Value <= 0xffffff;
899 bool isImmThumbSR() const {
900 if (!isImm()) return false;
901 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
902 if (!CE) return false;
903 int64_t Value = CE->getValue();
904 return Value > 0 && Value < 33;
906 bool isPKHLSLImm() const {
907 if (!isImm()) return false;
908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
909 if (!CE) return false;
910 int64_t Value = CE->getValue();
911 return Value >= 0 && Value < 32;
913 bool isPKHASRImm() const {
914 if (!isImm()) return false;
915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
916 if (!CE) return false;
917 int64_t Value = CE->getValue();
918 return Value > 0 && Value <= 32;
920 bool isAdrLabel() const {
921 // If we have an immediate that's not a constant, treat it as a label
922 // reference needing a fixup. If it is a constant, but it can't fit
923 // into shift immediate encoding, we reject it.
924 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
925 else return (isARMSOImm() || isARMSOImmNeg());
927 bool isARMSOImm() const {
928 if (!isImm()) return false;
929 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
930 if (!CE) return false;
931 int64_t Value = CE->getValue();
932 return ARM_AM::getSOImmVal(Value) != -1;
934 bool isARMSOImmNot() const {
935 if (!isImm()) return false;
936 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
937 if (!CE) return false;
938 int64_t Value = CE->getValue();
939 return ARM_AM::getSOImmVal(~Value) != -1;
941 bool isARMSOImmNeg() const {
942 if (!isImm()) return false;
943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
944 if (!CE) return false;
945 int64_t Value = CE->getValue();
946 // Only use this when not representable as a plain so_imm.
947 return ARM_AM::getSOImmVal(Value) == -1 &&
948 ARM_AM::getSOImmVal(-Value) != -1;
950 bool isT2SOImm() const {
951 if (!isImm()) return false;
952 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
953 if (!CE) return false;
954 int64_t Value = CE->getValue();
955 return ARM_AM::getT2SOImmVal(Value) != -1;
957 bool isT2SOImmNot() const {
958 if (!isImm()) return false;
959 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
960 if (!CE) return false;
961 int64_t Value = CE->getValue();
962 return ARM_AM::getT2SOImmVal(Value) == -1 &&
963 ARM_AM::getT2SOImmVal(~Value) != -1;
965 bool isT2SOImmNeg() const {
966 if (!isImm()) return false;
967 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
968 if (!CE) return false;
969 int64_t Value = CE->getValue();
970 // Only use this when not representable as a plain so_imm.
971 return ARM_AM::getT2SOImmVal(Value) == -1 &&
972 ARM_AM::getT2SOImmVal(-Value) != -1;
974 bool isSetEndImm() const {
975 if (!isImm()) return false;
976 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
977 if (!CE) return false;
978 int64_t Value = CE->getValue();
979 return Value == 1 || Value == 0;
981 bool isReg() const { return Kind == k_Register; }
982 bool isRegList() const { return Kind == k_RegisterList; }
983 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
984 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
985 bool isToken() const { return Kind == k_Token; }
986 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
987 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
988 bool isMem() const { return Kind == k_Memory; }
989 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
990 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
991 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
992 bool isRotImm() const { return Kind == k_RotateImmediate; }
993 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
994 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
995 bool isPostIdxReg() const {
996 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
998 bool isMemNoOffset(bool alignOK = false) const {
1001 // No offset of any kind.
1002 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1003 (alignOK || Memory.Alignment == 0);
1005 bool isMemPCRelImm12() const {
1006 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1008 // Base register must be PC.
1009 if (Memory.BaseRegNum != ARM::PC)
1011 // Immediate offset in range [-4095, 4095].
1012 if (!Memory.OffsetImm) return true;
1013 int64_t Val = Memory.OffsetImm->getValue();
1014 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1016 bool isAlignedMemory() const {
1017 return isMemNoOffset(true);
1019 bool isAddrMode2() const {
1020 if (!isMem() || Memory.Alignment != 0) return false;
1021 // Check for register offset.
1022 if (Memory.OffsetRegNum) return true;
1023 // Immediate offset in range [-4095, 4095].
1024 if (!Memory.OffsetImm) return true;
1025 int64_t Val = Memory.OffsetImm->getValue();
1026 return Val > -4096 && Val < 4096;
1028 bool isAM2OffsetImm() const {
1029 if (!isImm()) return false;
1030 // Immediate offset in range [-4095, 4095].
1031 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1032 if (!CE) return false;
1033 int64_t Val = CE->getValue();
1034 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1036 bool isAddrMode3() const {
1037 // If we have an immediate that's not a constant, treat it as a label
1038 // reference needing a fixup. If it is a constant, it's something else
1039 // and we reject it.
1040 if (isImm() && !isa<MCConstantExpr>(getImm()))
1042 if (!isMem() || Memory.Alignment != 0) return false;
1043 // No shifts are legal for AM3.
1044 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1045 // Check for register offset.
1046 if (Memory.OffsetRegNum) return true;
1047 // Immediate offset in range [-255, 255].
1048 if (!Memory.OffsetImm) return true;
1049 int64_t Val = Memory.OffsetImm->getValue();
1050 // The #-0 offset is encoded as INT32_MIN, and we have to check
1052 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1054 bool isAM3Offset() const {
1055 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1057 if (Kind == k_PostIndexRegister)
1058 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1059 // Immediate offset in range [-255, 255].
1060 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1061 if (!CE) return false;
1062 int64_t Val = CE->getValue();
1063 // Special case, #-0 is INT32_MIN.
1064 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1066 bool isAddrMode5() const {
1067 // If we have an immediate that's not a constant, treat it as a label
1068 // reference needing a fixup. If it is a constant, it's something else
1069 // and we reject it.
1070 if (isImm() && !isa<MCConstantExpr>(getImm()))
1072 if (!isMem() || Memory.Alignment != 0) return false;
1073 // Check for register offset.
1074 if (Memory.OffsetRegNum) return false;
1075 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1076 if (!Memory.OffsetImm) return true;
1077 int64_t Val = Memory.OffsetImm->getValue();
1078 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1081 bool isMemTBB() const {
1082 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1083 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1087 bool isMemTBH() const {
1088 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1089 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1090 Memory.Alignment != 0 )
1094 bool isMemRegOffset() const {
1095 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1099 bool isT2MemRegOffset() const {
1100 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1101 Memory.Alignment != 0)
1103 // Only lsl #{0, 1, 2, 3} allowed.
1104 if (Memory.ShiftType == ARM_AM::no_shift)
1106 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1110 bool isMemThumbRR() const {
1111 // Thumb reg+reg addressing is simple. Just two registers, a base and
1112 // an offset. No shifts, negations or any other complicating factors.
1113 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1114 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1116 return isARMLowRegister(Memory.BaseRegNum) &&
1117 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1119 bool isMemThumbRIs4() const {
1120 if (!isMem() || Memory.OffsetRegNum != 0 ||
1121 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1123 // Immediate offset, multiple of 4 in range [0, 124].
1124 if (!Memory.OffsetImm) return true;
1125 int64_t Val = Memory.OffsetImm->getValue();
1126 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1128 bool isMemThumbRIs2() const {
1129 if (!isMem() || Memory.OffsetRegNum != 0 ||
1130 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1132 // Immediate offset, multiple of 4 in range [0, 62].
1133 if (!Memory.OffsetImm) return true;
1134 int64_t Val = Memory.OffsetImm->getValue();
1135 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1137 bool isMemThumbRIs1() const {
1138 if (!isMem() || Memory.OffsetRegNum != 0 ||
1139 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1141 // Immediate offset in range [0, 31].
1142 if (!Memory.OffsetImm) return true;
1143 int64_t Val = Memory.OffsetImm->getValue();
1144 return Val >= 0 && Val <= 31;
1146 bool isMemThumbSPI() const {
1147 if (!isMem() || Memory.OffsetRegNum != 0 ||
1148 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1150 // Immediate offset, multiple of 4 in range [0, 1020].
1151 if (!Memory.OffsetImm) return true;
1152 int64_t Val = Memory.OffsetImm->getValue();
1153 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1155 bool isMemImm8s4Offset() const {
1156 // If we have an immediate that's not a constant, treat it as a label
1157 // reference needing a fixup. If it is a constant, it's something else
1158 // and we reject it.
1159 if (isImm() && !isa<MCConstantExpr>(getImm()))
1161 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1163 // Immediate offset a multiple of 4 in range [-1020, 1020].
1164 if (!Memory.OffsetImm) return true;
1165 int64_t Val = Memory.OffsetImm->getValue();
1166 // Special case, #-0 is INT32_MIN.
1167 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1169 bool isMemImm0_1020s4Offset() const {
1170 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1172 // Immediate offset a multiple of 4 in range [0, 1020].
1173 if (!Memory.OffsetImm) return true;
1174 int64_t Val = Memory.OffsetImm->getValue();
1175 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1177 bool isMemImm8Offset() const {
1178 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1180 // Base reg of PC isn't allowed for these encodings.
1181 if (Memory.BaseRegNum == ARM::PC) return false;
1182 // Immediate offset in range [-255, 255].
1183 if (!Memory.OffsetImm) return true;
1184 int64_t Val = Memory.OffsetImm->getValue();
1185 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1187 bool isMemPosImm8Offset() const {
1188 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1190 // Immediate offset in range [0, 255].
1191 if (!Memory.OffsetImm) return true;
1192 int64_t Val = Memory.OffsetImm->getValue();
1193 return Val >= 0 && Val < 256;
1195 bool isMemNegImm8Offset() const {
1196 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1198 // Base reg of PC isn't allowed for these encodings.
1199 if (Memory.BaseRegNum == ARM::PC) return false;
1200 // Immediate offset in range [-255, -1].
1201 if (!Memory.OffsetImm) return false;
1202 int64_t Val = Memory.OffsetImm->getValue();
1203 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1205 bool isMemUImm12Offset() const {
1206 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1208 // Immediate offset in range [0, 4095].
1209 if (!Memory.OffsetImm) return true;
1210 int64_t Val = Memory.OffsetImm->getValue();
1211 return (Val >= 0 && Val < 4096);
1213 bool isMemImm12Offset() const {
1214 // If we have an immediate that's not a constant, treat it as a label
1215 // reference needing a fixup. If it is a constant, it's something else
1216 // and we reject it.
1217 if (isImm() && !isa<MCConstantExpr>(getImm()))
1220 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1222 // Immediate offset in range [-4095, 4095].
1223 if (!Memory.OffsetImm) return true;
1224 int64_t Val = Memory.OffsetImm->getValue();
1225 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1227 bool isPostIdxImm8() const {
1228 if (!isImm()) return false;
1229 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1230 if (!CE) return false;
1231 int64_t Val = CE->getValue();
1232 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1234 bool isPostIdxImm8s4() const {
1235 if (!isImm()) return false;
1236 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1237 if (!CE) return false;
1238 int64_t Val = CE->getValue();
1239 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1243 bool isMSRMask() const { return Kind == k_MSRMask; }
1244 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1247 bool isSingleSpacedVectorList() const {
1248 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1250 bool isDoubleSpacedVectorList() const {
1251 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1253 bool isVecListOneD() const {
1254 if (!isSingleSpacedVectorList()) return false;
1255 return VectorList.Count == 1;
1258 bool isVecListDPair() const {
1259 if (!isSingleSpacedVectorList()) return false;
1260 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1261 .contains(VectorList.RegNum));
1264 bool isVecListThreeD() const {
1265 if (!isSingleSpacedVectorList()) return false;
1266 return VectorList.Count == 3;
1269 bool isVecListFourD() const {
1270 if (!isSingleSpacedVectorList()) return false;
1271 return VectorList.Count == 4;
1274 bool isVecListDPairSpaced() const {
1275 if (isSingleSpacedVectorList()) return false;
1276 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1277 .contains(VectorList.RegNum));
1280 bool isVecListThreeQ() const {
1281 if (!isDoubleSpacedVectorList()) return false;
1282 return VectorList.Count == 3;
1285 bool isVecListFourQ() const {
1286 if (!isDoubleSpacedVectorList()) return false;
1287 return VectorList.Count == 4;
1290 bool isSingleSpacedVectorAllLanes() const {
1291 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1293 bool isDoubleSpacedVectorAllLanes() const {
1294 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1296 bool isVecListOneDAllLanes() const {
1297 if (!isSingleSpacedVectorAllLanes()) return false;
1298 return VectorList.Count == 1;
1301 bool isVecListDPairAllLanes() const {
1302 if (!isSingleSpacedVectorAllLanes()) return false;
1303 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1304 .contains(VectorList.RegNum));
1307 bool isVecListDPairSpacedAllLanes() const {
1308 if (!isDoubleSpacedVectorAllLanes()) return false;
1309 return VectorList.Count == 2;
1312 bool isVecListThreeDAllLanes() const {
1313 if (!isSingleSpacedVectorAllLanes()) return false;
1314 return VectorList.Count == 3;
1317 bool isVecListThreeQAllLanes() const {
1318 if (!isDoubleSpacedVectorAllLanes()) return false;
1319 return VectorList.Count == 3;
1322 bool isVecListFourDAllLanes() const {
1323 if (!isSingleSpacedVectorAllLanes()) return false;
1324 return VectorList.Count == 4;
1327 bool isVecListFourQAllLanes() const {
1328 if (!isDoubleSpacedVectorAllLanes()) return false;
1329 return VectorList.Count == 4;
1332 bool isSingleSpacedVectorIndexed() const {
1333 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1335 bool isDoubleSpacedVectorIndexed() const {
1336 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1338 bool isVecListOneDByteIndexed() const {
1339 if (!isSingleSpacedVectorIndexed()) return false;
1340 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1343 bool isVecListOneDHWordIndexed() const {
1344 if (!isSingleSpacedVectorIndexed()) return false;
1345 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1348 bool isVecListOneDWordIndexed() const {
1349 if (!isSingleSpacedVectorIndexed()) return false;
1350 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1353 bool isVecListTwoDByteIndexed() const {
1354 if (!isSingleSpacedVectorIndexed()) return false;
1355 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1358 bool isVecListTwoDHWordIndexed() const {
1359 if (!isSingleSpacedVectorIndexed()) return false;
1360 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1363 bool isVecListTwoQWordIndexed() const {
1364 if (!isDoubleSpacedVectorIndexed()) return false;
1365 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1368 bool isVecListTwoQHWordIndexed() const {
1369 if (!isDoubleSpacedVectorIndexed()) return false;
1370 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1373 bool isVecListTwoDWordIndexed() const {
1374 if (!isSingleSpacedVectorIndexed()) return false;
1375 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1378 bool isVecListThreeDByteIndexed() const {
1379 if (!isSingleSpacedVectorIndexed()) return false;
1380 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1383 bool isVecListThreeDHWordIndexed() const {
1384 if (!isSingleSpacedVectorIndexed()) return false;
1385 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1388 bool isVecListThreeQWordIndexed() const {
1389 if (!isDoubleSpacedVectorIndexed()) return false;
1390 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1393 bool isVecListThreeQHWordIndexed() const {
1394 if (!isDoubleSpacedVectorIndexed()) return false;
1395 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1398 bool isVecListThreeDWordIndexed() const {
1399 if (!isSingleSpacedVectorIndexed()) return false;
1400 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1403 bool isVecListFourDByteIndexed() const {
1404 if (!isSingleSpacedVectorIndexed()) return false;
1405 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1408 bool isVecListFourDHWordIndexed() const {
1409 if (!isSingleSpacedVectorIndexed()) return false;
1410 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1413 bool isVecListFourQWordIndexed() const {
1414 if (!isDoubleSpacedVectorIndexed()) return false;
1415 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1418 bool isVecListFourQHWordIndexed() const {
1419 if (!isDoubleSpacedVectorIndexed()) return false;
1420 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1423 bool isVecListFourDWordIndexed() const {
1424 if (!isSingleSpacedVectorIndexed()) return false;
1425 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1428 bool isVectorIndex8() const {
1429 if (Kind != k_VectorIndex) return false;
1430 return VectorIndex.Val < 8;
1432 bool isVectorIndex16() const {
1433 if (Kind != k_VectorIndex) return false;
1434 return VectorIndex.Val < 4;
1436 bool isVectorIndex32() const {
1437 if (Kind != k_VectorIndex) return false;
1438 return VectorIndex.Val < 2;
1441 bool isNEONi8splat() const {
1442 if (!isImm()) return false;
1443 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1444 // Must be a constant.
1445 if (!CE) return false;
1446 int64_t Value = CE->getValue();
1447 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1449 return Value >= 0 && Value < 256;
1452 bool isNEONi16splat() const {
1453 if (!isImm()) return false;
1454 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1455 // Must be a constant.
1456 if (!CE) return false;
1457 int64_t Value = CE->getValue();
1458 // i16 value in the range [0,255] or [0x0100, 0xff00]
1459 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1462 bool isNEONi32splat() const {
1463 if (!isImm()) return false;
1464 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1465 // Must be a constant.
1466 if (!CE) return false;
1467 int64_t Value = CE->getValue();
1468 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1469 return (Value >= 0 && Value < 256) ||
1470 (Value >= 0x0100 && Value <= 0xff00) ||
1471 (Value >= 0x010000 && Value <= 0xff0000) ||
1472 (Value >= 0x01000000 && Value <= 0xff000000);
1475 bool isNEONi32vmov() const {
1476 if (!isImm()) return false;
1477 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1478 // Must be a constant.
1479 if (!CE) return false;
1480 int64_t Value = CE->getValue();
1481 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1482 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1483 return (Value >= 0 && Value < 256) ||
1484 (Value >= 0x0100 && Value <= 0xff00) ||
1485 (Value >= 0x010000 && Value <= 0xff0000) ||
1486 (Value >= 0x01000000 && Value <= 0xff000000) ||
1487 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1488 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1490 bool isNEONi32vmovNeg() const {
1491 if (!isImm()) return false;
1492 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1493 // Must be a constant.
1494 if (!CE) return false;
1495 int64_t Value = ~CE->getValue();
1496 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1497 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1498 return (Value >= 0 && Value < 256) ||
1499 (Value >= 0x0100 && Value <= 0xff00) ||
1500 (Value >= 0x010000 && Value <= 0xff0000) ||
1501 (Value >= 0x01000000 && Value <= 0xff000000) ||
1502 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1503 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1506 bool isNEONi64splat() const {
1507 if (!isImm()) return false;
1508 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1509 // Must be a constant.
1510 if (!CE) return false;
1511 uint64_t Value = CE->getValue();
1512 // i64 value with each byte being either 0 or 0xff.
1513 for (unsigned i = 0; i < 8; ++i)
1514 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1518 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1519 // Add as immediates when possible. Null MCExpr = 0.
1521 Inst.addOperand(MCOperand::CreateImm(0));
1522 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1523 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1525 Inst.addOperand(MCOperand::CreateExpr(Expr));
1528 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1529 assert(N == 2 && "Invalid number of operands!");
1530 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1531 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1532 Inst.addOperand(MCOperand::CreateReg(RegNum));
1535 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1536 assert(N == 1 && "Invalid number of operands!");
1537 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1540 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1541 assert(N == 1 && "Invalid number of operands!");
1542 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1545 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1546 assert(N == 1 && "Invalid number of operands!");
1547 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1550 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1551 assert(N == 1 && "Invalid number of operands!");
1552 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1555 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1556 assert(N == 1 && "Invalid number of operands!");
1557 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1560 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1561 assert(N == 1 && "Invalid number of operands!");
1562 Inst.addOperand(MCOperand::CreateReg(getReg()));
1565 void addRegOperands(MCInst &Inst, unsigned N) const {
1566 assert(N == 1 && "Invalid number of operands!");
1567 Inst.addOperand(MCOperand::CreateReg(getReg()));
1570 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1571 assert(N == 3 && "Invalid number of operands!");
1572 assert(isRegShiftedReg() &&
1573 "addRegShiftedRegOperands() on non RegShiftedReg!");
1574 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1575 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1576 Inst.addOperand(MCOperand::CreateImm(
1577 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1580 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1581 assert(N == 2 && "Invalid number of operands!");
1582 assert(isRegShiftedImm() &&
1583 "addRegShiftedImmOperands() on non RegShiftedImm!");
1584 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1585 // Shift of #32 is encoded as 0 where permitted
1586 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1587 Inst.addOperand(MCOperand::CreateImm(
1588 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1591 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1592 assert(N == 1 && "Invalid number of operands!");
1593 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1597 void addRegListOperands(MCInst &Inst, unsigned N) const {
1598 assert(N == 1 && "Invalid number of operands!");
1599 const SmallVectorImpl<unsigned> &RegList = getRegList();
1600 for (SmallVectorImpl<unsigned>::const_iterator
1601 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1602 Inst.addOperand(MCOperand::CreateReg(*I));
1605 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1606 addRegListOperands(Inst, N);
1609 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1610 addRegListOperands(Inst, N);
1613 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1614 assert(N == 1 && "Invalid number of operands!");
1615 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1616 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1619 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1620 assert(N == 1 && "Invalid number of operands!");
1621 // Munge the lsb/width into a bitfield mask.
1622 unsigned lsb = Bitfield.LSB;
1623 unsigned width = Bitfield.Width;
1624 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1625 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1626 (32 - (lsb + width)));
1627 Inst.addOperand(MCOperand::CreateImm(Mask));
1630 void addImmOperands(MCInst &Inst, unsigned N) const {
1631 assert(N == 1 && "Invalid number of operands!");
1632 addExpr(Inst, getImm());
1635 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1636 assert(N == 1 && "Invalid number of operands!");
1637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1638 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1641 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1642 assert(N == 1 && "Invalid number of operands!");
1643 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1644 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1647 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1648 assert(N == 1 && "Invalid number of operands!");
1649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1650 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1651 Inst.addOperand(MCOperand::CreateImm(Val));
1654 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1655 assert(N == 1 && "Invalid number of operands!");
1656 // FIXME: We really want to scale the value here, but the LDRD/STRD
1657 // instruction don't encode operands that way yet.
1658 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1659 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1662 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1663 assert(N == 1 && "Invalid number of operands!");
1664 // The immediate is scaled by four in the encoding and is stored
1665 // in the MCInst as such. Lop off the low two bits here.
1666 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1667 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1670 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1671 assert(N == 1 && "Invalid number of operands!");
1672 // The immediate is scaled by four in the encoding and is stored
1673 // in the MCInst as such. Lop off the low two bits here.
1674 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1675 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1678 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1679 assert(N == 1 && "Invalid number of operands!");
1680 // The immediate is scaled by four in the encoding and is stored
1681 // in the MCInst as such. Lop off the low two bits here.
1682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1683 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1686 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1687 assert(N == 1 && "Invalid number of operands!");
1688 // The constant encodes as the immediate-1, and we store in the instruction
1689 // the bits as encoded, so subtract off one here.
1690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1691 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1694 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1695 assert(N == 1 && "Invalid number of operands!");
1696 // The constant encodes as the immediate-1, and we store in the instruction
1697 // the bits as encoded, so subtract off one here.
1698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1699 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1702 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1703 assert(N == 1 && "Invalid number of operands!");
1704 // The constant encodes as the immediate, except for 32, which encodes as
1706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1707 unsigned Imm = CE->getValue();
1708 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1711 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1712 assert(N == 1 && "Invalid number of operands!");
1713 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1714 // the instruction as well.
1715 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1716 int Val = CE->getValue();
1717 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1720 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1721 assert(N == 1 && "Invalid number of operands!");
1722 // The operand is actually a t2_so_imm, but we have its bitwise
1723 // negation in the assembly source, so twiddle it here.
1724 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1725 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1728 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1729 assert(N == 1 && "Invalid number of operands!");
1730 // The operand is actually a t2_so_imm, but we have its
1731 // negation in the assembly source, so twiddle it here.
1732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1733 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1736 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1737 assert(N == 1 && "Invalid number of operands!");
1738 // The operand is actually an imm0_4095, but we have its
1739 // negation in the assembly source, so twiddle it here.
1740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1741 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1744 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1745 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1746 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1750 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1751 assert(SR && "Unknown value type!");
1752 Inst.addOperand(MCOperand::CreateExpr(SR));
1755 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1756 assert(N == 1 && "Invalid number of operands!");
1758 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1760 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1764 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1765 assert(SR && "Unknown value type!");
1766 Inst.addOperand(MCOperand::CreateExpr(SR));
1770 assert(isMem() && "Unknown value type!");
1771 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1772 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1775 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1776 assert(N == 1 && "Invalid number of operands!");
1777 // The operand is actually a so_imm, but we have its bitwise
1778 // negation in the assembly source, so twiddle it here.
1779 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1780 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1783 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1784 assert(N == 1 && "Invalid number of operands!");
1785 // The operand is actually a so_imm, but we have its
1786 // negation in the assembly source, so twiddle it here.
1787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1788 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1791 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1792 assert(N == 1 && "Invalid number of operands!");
1793 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1796 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1797 assert(N == 1 && "Invalid number of operands!");
1798 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1801 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1802 assert(N == 1 && "Invalid number of operands!");
1803 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1806 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1807 assert(N == 1 && "Invalid number of operands!");
1808 int32_t Imm = Memory.OffsetImm->getValue();
1809 Inst.addOperand(MCOperand::CreateImm(Imm));
1812 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1813 assert(N == 1 && "Invalid number of operands!");
1814 assert(isImm() && "Not an immediate!");
1816 // If we have an immediate that's not a constant, treat it as a label
1817 // reference needing a fixup.
1818 if (!isa<MCConstantExpr>(getImm())) {
1819 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1823 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1824 int Val = CE->getValue();
1825 Inst.addOperand(MCOperand::CreateImm(Val));
1828 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1829 assert(N == 2 && "Invalid number of operands!");
1830 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1831 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1834 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1835 assert(N == 3 && "Invalid number of operands!");
1836 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1837 if (!Memory.OffsetRegNum) {
1838 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1839 // Special case for #-0
1840 if (Val == INT32_MIN) Val = 0;
1841 if (Val < 0) Val = -Val;
1842 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1844 // For register offset, we encode the shift type and negation flag
1846 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1847 Memory.ShiftImm, Memory.ShiftType);
1849 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1850 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1851 Inst.addOperand(MCOperand::CreateImm(Val));
1854 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1855 assert(N == 2 && "Invalid number of operands!");
1856 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1857 assert(CE && "non-constant AM2OffsetImm operand!");
1858 int32_t Val = CE->getValue();
1859 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1860 // Special case for #-0
1861 if (Val == INT32_MIN) Val = 0;
1862 if (Val < 0) Val = -Val;
1863 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1864 Inst.addOperand(MCOperand::CreateReg(0));
1865 Inst.addOperand(MCOperand::CreateImm(Val));
1868 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1869 assert(N == 3 && "Invalid number of operands!");
1870 // If we have an immediate that's not a constant, treat it as a label
1871 // reference needing a fixup. If it is a constant, it's something else
1872 // and we reject it.
1874 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1875 Inst.addOperand(MCOperand::CreateReg(0));
1876 Inst.addOperand(MCOperand::CreateImm(0));
1880 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1881 if (!Memory.OffsetRegNum) {
1882 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1883 // Special case for #-0
1884 if (Val == INT32_MIN) Val = 0;
1885 if (Val < 0) Val = -Val;
1886 Val = ARM_AM::getAM3Opc(AddSub, Val);
1888 // For register offset, we encode the shift type and negation flag
1890 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1892 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1893 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1894 Inst.addOperand(MCOperand::CreateImm(Val));
1897 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1898 assert(N == 2 && "Invalid number of operands!");
1899 if (Kind == k_PostIndexRegister) {
1901 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1902 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1903 Inst.addOperand(MCOperand::CreateImm(Val));
1908 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1909 int32_t Val = CE->getValue();
1910 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1911 // Special case for #-0
1912 if (Val == INT32_MIN) Val = 0;
1913 if (Val < 0) Val = -Val;
1914 Val = ARM_AM::getAM3Opc(AddSub, Val);
1915 Inst.addOperand(MCOperand::CreateReg(0));
1916 Inst.addOperand(MCOperand::CreateImm(Val));
1919 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1920 assert(N == 2 && "Invalid number of operands!");
1921 // If we have an immediate that's not a constant, treat it as a label
1922 // reference needing a fixup. If it is a constant, it's something else
1923 // and we reject it.
1925 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1926 Inst.addOperand(MCOperand::CreateImm(0));
1930 // The lower two bits are always zero and as such are not encoded.
1931 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1932 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1933 // Special case for #-0
1934 if (Val == INT32_MIN) Val = 0;
1935 if (Val < 0) Val = -Val;
1936 Val = ARM_AM::getAM5Opc(AddSub, Val);
1937 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1938 Inst.addOperand(MCOperand::CreateImm(Val));
1941 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1942 assert(N == 2 && "Invalid number of operands!");
1943 // If we have an immediate that's not a constant, treat it as a label
1944 // reference needing a fixup. If it is a constant, it's something else
1945 // and we reject it.
1947 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1948 Inst.addOperand(MCOperand::CreateImm(0));
1952 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1953 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1954 Inst.addOperand(MCOperand::CreateImm(Val));
1957 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1958 assert(N == 2 && "Invalid number of operands!");
1959 // The lower two bits are always zero and as such are not encoded.
1960 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1961 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1962 Inst.addOperand(MCOperand::CreateImm(Val));
1965 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1966 assert(N == 2 && "Invalid number of operands!");
1967 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1968 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1969 Inst.addOperand(MCOperand::CreateImm(Val));
1972 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1973 addMemImm8OffsetOperands(Inst, N);
1976 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1977 addMemImm8OffsetOperands(Inst, N);
1980 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1981 assert(N == 2 && "Invalid number of operands!");
1982 // If this is an immediate, it's a label reference.
1984 addExpr(Inst, getImm());
1985 Inst.addOperand(MCOperand::CreateImm(0));
1989 // Otherwise, it's a normal memory reg+offset.
1990 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1991 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1992 Inst.addOperand(MCOperand::CreateImm(Val));
1995 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1996 assert(N == 2 && "Invalid number of operands!");
1997 // If this is an immediate, it's a label reference.
1999 addExpr(Inst, getImm());
2000 Inst.addOperand(MCOperand::CreateImm(0));
2004 // Otherwise, it's a normal memory reg+offset.
2005 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2006 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2007 Inst.addOperand(MCOperand::CreateImm(Val));
2010 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2011 assert(N == 2 && "Invalid number of operands!");
2012 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2013 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2016 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2017 assert(N == 2 && "Invalid number of operands!");
2018 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2019 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2022 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2023 assert(N == 3 && "Invalid number of operands!");
2025 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2026 Memory.ShiftImm, Memory.ShiftType);
2027 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2028 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2029 Inst.addOperand(MCOperand::CreateImm(Val));
2032 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2033 assert(N == 3 && "Invalid number of operands!");
2034 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2035 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2036 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2039 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2040 assert(N == 2 && "Invalid number of operands!");
2041 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2042 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2045 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2046 assert(N == 2 && "Invalid number of operands!");
2047 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2048 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2049 Inst.addOperand(MCOperand::CreateImm(Val));
2052 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2053 assert(N == 2 && "Invalid number of operands!");
2054 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2055 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2056 Inst.addOperand(MCOperand::CreateImm(Val));
2059 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2060 assert(N == 2 && "Invalid number of operands!");
2061 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2062 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2063 Inst.addOperand(MCOperand::CreateImm(Val));
2066 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2067 assert(N == 2 && "Invalid number of operands!");
2068 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2069 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2070 Inst.addOperand(MCOperand::CreateImm(Val));
2073 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2074 assert(N == 1 && "Invalid number of operands!");
2075 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2076 assert(CE && "non-constant post-idx-imm8 operand!");
2077 int Imm = CE->getValue();
2078 bool isAdd = Imm >= 0;
2079 if (Imm == INT32_MIN) Imm = 0;
2080 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2081 Inst.addOperand(MCOperand::CreateImm(Imm));
2084 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2085 assert(N == 1 && "Invalid number of operands!");
2086 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2087 assert(CE && "non-constant post-idx-imm8s4 operand!");
2088 int Imm = CE->getValue();
2089 bool isAdd = Imm >= 0;
2090 if (Imm == INT32_MIN) Imm = 0;
2091 // Immediate is scaled by 4.
2092 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2093 Inst.addOperand(MCOperand::CreateImm(Imm));
2096 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2097 assert(N == 2 && "Invalid number of operands!");
2098 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2099 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2102 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2103 assert(N == 2 && "Invalid number of operands!");
2104 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2105 // The sign, shift type, and shift amount are encoded in a single operand
2106 // using the AM2 encoding helpers.
2107 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2108 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2109 PostIdxReg.ShiftTy);
2110 Inst.addOperand(MCOperand::CreateImm(Imm));
2113 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2114 assert(N == 1 && "Invalid number of operands!");
2115 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2118 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2119 assert(N == 1 && "Invalid number of operands!");
2120 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2123 void addVecListOperands(MCInst &Inst, unsigned N) const {
2124 assert(N == 1 && "Invalid number of operands!");
2125 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2128 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2129 assert(N == 2 && "Invalid number of operands!");
2130 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2131 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2134 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2135 assert(N == 1 && "Invalid number of operands!");
2136 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2139 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2140 assert(N == 1 && "Invalid number of operands!");
2141 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2144 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2145 assert(N == 1 && "Invalid number of operands!");
2146 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2149 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2150 assert(N == 1 && "Invalid number of operands!");
2151 // The immediate encodes the type of constant as well as the value.
2152 // Mask in that this is an i8 splat.
2153 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2154 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2157 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2158 assert(N == 1 && "Invalid number of operands!");
2159 // The immediate encodes the type of constant as well as the value.
2160 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2161 unsigned Value = CE->getValue();
2163 Value = (Value >> 8) | 0xa00;
2166 Inst.addOperand(MCOperand::CreateImm(Value));
2169 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2170 assert(N == 1 && "Invalid number of operands!");
2171 // The immediate encodes the type of constant as well as the value.
2172 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2173 unsigned Value = CE->getValue();
2174 if (Value >= 256 && Value <= 0xff00)
2175 Value = (Value >> 8) | 0x200;
2176 else if (Value > 0xffff && Value <= 0xff0000)
2177 Value = (Value >> 16) | 0x400;
2178 else if (Value > 0xffffff)
2179 Value = (Value >> 24) | 0x600;
2180 Inst.addOperand(MCOperand::CreateImm(Value));
2183 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2184 assert(N == 1 && "Invalid number of operands!");
2185 // The immediate encodes the type of constant as well as the value.
2186 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2187 unsigned Value = CE->getValue();
2188 if (Value >= 256 && Value <= 0xffff)
2189 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2190 else if (Value > 0xffff && Value <= 0xffffff)
2191 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2192 else if (Value > 0xffffff)
2193 Value = (Value >> 24) | 0x600;
2194 Inst.addOperand(MCOperand::CreateImm(Value));
2197 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2198 assert(N == 1 && "Invalid number of operands!");
2199 // The immediate encodes the type of constant as well as the value.
2200 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2201 unsigned Value = ~CE->getValue();
2202 if (Value >= 256 && Value <= 0xffff)
2203 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2204 else if (Value > 0xffff && Value <= 0xffffff)
2205 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2206 else if (Value > 0xffffff)
2207 Value = (Value >> 24) | 0x600;
2208 Inst.addOperand(MCOperand::CreateImm(Value));
2211 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2212 assert(N == 1 && "Invalid number of operands!");
2213 // The immediate encodes the type of constant as well as the value.
2214 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2215 uint64_t Value = CE->getValue();
2217 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2218 Imm |= (Value & 1) << i;
2220 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2223 virtual void print(raw_ostream &OS) const;
2225 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2226 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2227 Op->ITMask.Mask = Mask;
2233 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2234 ARMOperand *Op = new ARMOperand(k_CondCode);
2241 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2242 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2243 Op->Cop.Val = CopVal;
2249 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2250 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2251 Op->Cop.Val = CopVal;
2257 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2258 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2265 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2266 ARMOperand *Op = new ARMOperand(k_CCOut);
2267 Op->Reg.RegNum = RegNum;
2273 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2274 ARMOperand *Op = new ARMOperand(k_Token);
2275 Op->Tok.Data = Str.data();
2276 Op->Tok.Length = Str.size();
2282 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2283 ARMOperand *Op = new ARMOperand(k_Register);
2284 Op->Reg.RegNum = RegNum;
2290 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2295 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2296 Op->RegShiftedReg.ShiftTy = ShTy;
2297 Op->RegShiftedReg.SrcReg = SrcReg;
2298 Op->RegShiftedReg.ShiftReg = ShiftReg;
2299 Op->RegShiftedReg.ShiftImm = ShiftImm;
2305 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2309 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2310 Op->RegShiftedImm.ShiftTy = ShTy;
2311 Op->RegShiftedImm.SrcReg = SrcReg;
2312 Op->RegShiftedImm.ShiftImm = ShiftImm;
2318 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2320 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2321 Op->ShifterImm.isASR = isASR;
2322 Op->ShifterImm.Imm = Imm;
2328 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2329 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2330 Op->RotImm.Imm = Imm;
2336 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2338 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2339 Op->Bitfield.LSB = LSB;
2340 Op->Bitfield.Width = Width;
2347 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2348 SMLoc StartLoc, SMLoc EndLoc) {
2349 assert (Regs.size() > 0 && "RegList contains no registers?");
2350 KindTy Kind = k_RegisterList;
2352 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2353 Kind = k_DPRRegisterList;
2354 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2355 contains(Regs.front().second))
2356 Kind = k_SPRRegisterList;
2358 // Sort based on the register encoding values.
2359 array_pod_sort(Regs.begin(), Regs.end());
2361 ARMOperand *Op = new ARMOperand(Kind);
2362 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2363 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2364 Op->Registers.push_back(I->second);
2365 Op->StartLoc = StartLoc;
2366 Op->EndLoc = EndLoc;
2370 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2371 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2372 ARMOperand *Op = new ARMOperand(k_VectorList);
2373 Op->VectorList.RegNum = RegNum;
2374 Op->VectorList.Count = Count;
2375 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2381 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2382 bool isDoubleSpaced,
2384 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2385 Op->VectorList.RegNum = RegNum;
2386 Op->VectorList.Count = Count;
2387 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2393 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2395 bool isDoubleSpaced,
2397 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2398 Op->VectorList.RegNum = RegNum;
2399 Op->VectorList.Count = Count;
2400 Op->VectorList.LaneIndex = Index;
2401 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2407 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2409 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2410 Op->VectorIndex.Val = Idx;
2416 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2417 ARMOperand *Op = new ARMOperand(k_Immediate);
2424 static ARMOperand *CreateMem(unsigned BaseRegNum,
2425 const MCConstantExpr *OffsetImm,
2426 unsigned OffsetRegNum,
2427 ARM_AM::ShiftOpc ShiftType,
2432 ARMOperand *Op = new ARMOperand(k_Memory);
2433 Op->Memory.BaseRegNum = BaseRegNum;
2434 Op->Memory.OffsetImm = OffsetImm;
2435 Op->Memory.OffsetRegNum = OffsetRegNum;
2436 Op->Memory.ShiftType = ShiftType;
2437 Op->Memory.ShiftImm = ShiftImm;
2438 Op->Memory.Alignment = Alignment;
2439 Op->Memory.isNegative = isNegative;
2445 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2446 ARM_AM::ShiftOpc ShiftTy,
2449 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2450 Op->PostIdxReg.RegNum = RegNum;
2451 Op->PostIdxReg.isAdd = isAdd;
2452 Op->PostIdxReg.ShiftTy = ShiftTy;
2453 Op->PostIdxReg.ShiftImm = ShiftImm;
2459 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2460 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2461 Op->MBOpt.Val = Opt;
2467 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2469 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2470 Op->ISBOpt.Val = Opt;
2476 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2477 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2478 Op->IFlags.Val = IFlags;
2484 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2485 ARMOperand *Op = new ARMOperand(k_MSRMask);
2486 Op->MMask.Val = MMask;
2493 } // end anonymous namespace.
2495 void ARMOperand::print(raw_ostream &OS) const {
2498 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2501 OS << "<ccout " << getReg() << ">";
2503 case k_ITCondMask: {
2504 static const char *const MaskStr[] = {
2505 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2506 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2508 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2509 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2513 OS << "<coprocessor number: " << getCoproc() << ">";
2516 OS << "<coprocessor register: " << getCoproc() << ">";
2518 case k_CoprocOption:
2519 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2522 OS << "<mask: " << getMSRMask() << ">";
2525 getImm()->print(OS);
2527 case k_MemBarrierOpt:
2528 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2530 case k_InstSyncBarrierOpt:
2531 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2535 << " base:" << Memory.BaseRegNum;
2538 case k_PostIndexRegister:
2539 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2540 << PostIdxReg.RegNum;
2541 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2542 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2543 << PostIdxReg.ShiftImm;
2546 case k_ProcIFlags: {
2547 OS << "<ARM_PROC::";
2548 unsigned IFlags = getProcIFlags();
2549 for (int i=2; i >= 0; --i)
2550 if (IFlags & (1 << i))
2551 OS << ARM_PROC::IFlagsToString(1 << i);
2556 OS << "<register " << getReg() << ">";
2558 case k_ShifterImmediate:
2559 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2560 << " #" << ShifterImm.Imm << ">";
2562 case k_ShiftedRegister:
2563 OS << "<so_reg_reg "
2564 << RegShiftedReg.SrcReg << " "
2565 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2566 << " " << RegShiftedReg.ShiftReg << ">";
2568 case k_ShiftedImmediate:
2569 OS << "<so_reg_imm "
2570 << RegShiftedImm.SrcReg << " "
2571 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2572 << " #" << RegShiftedImm.ShiftImm << ">";
2574 case k_RotateImmediate:
2575 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2577 case k_BitfieldDescriptor:
2578 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2579 << ", width: " << Bitfield.Width << ">";
2581 case k_RegisterList:
2582 case k_DPRRegisterList:
2583 case k_SPRRegisterList: {
2584 OS << "<register_list ";
2586 const SmallVectorImpl<unsigned> &RegList = getRegList();
2587 for (SmallVectorImpl<unsigned>::const_iterator
2588 I = RegList.begin(), E = RegList.end(); I != E; ) {
2590 if (++I < E) OS << ", ";
2597 OS << "<vector_list " << VectorList.Count << " * "
2598 << VectorList.RegNum << ">";
2600 case k_VectorListAllLanes:
2601 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2602 << VectorList.RegNum << ">";
2604 case k_VectorListIndexed:
2605 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2606 << VectorList.Count << " * " << VectorList.RegNum << ">";
2609 OS << "'" << getToken() << "'";
2612 OS << "<vectorindex " << getVectorIndex() << ">";
2617 /// @name Auto-generated Match Functions
2620 static unsigned MatchRegisterName(StringRef Name);
2624 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2625 SMLoc &StartLoc, SMLoc &EndLoc) {
2626 StartLoc = Parser.getTok().getLoc();
2627 EndLoc = Parser.getTok().getEndLoc();
2628 RegNo = tryParseRegister();
2630 return (RegNo == (unsigned)-1);
2633 /// Try to parse a register name. The token must be an Identifier when called,
2634 /// and if it is a register name the token is eaten and the register number is
2635 /// returned. Otherwise return -1.
2637 int ARMAsmParser::tryParseRegister() {
2638 const AsmToken &Tok = Parser.getTok();
2639 if (Tok.isNot(AsmToken::Identifier)) return -1;
2641 std::string lowerCase = Tok.getString().lower();
2642 unsigned RegNum = MatchRegisterName(lowerCase);
2644 RegNum = StringSwitch<unsigned>(lowerCase)
2645 .Case("r13", ARM::SP)
2646 .Case("r14", ARM::LR)
2647 .Case("r15", ARM::PC)
2648 .Case("ip", ARM::R12)
2649 // Additional register name aliases for 'gas' compatibility.
2650 .Case("a1", ARM::R0)
2651 .Case("a2", ARM::R1)
2652 .Case("a3", ARM::R2)
2653 .Case("a4", ARM::R3)
2654 .Case("v1", ARM::R4)
2655 .Case("v2", ARM::R5)
2656 .Case("v3", ARM::R6)
2657 .Case("v4", ARM::R7)
2658 .Case("v5", ARM::R8)
2659 .Case("v6", ARM::R9)
2660 .Case("v7", ARM::R10)
2661 .Case("v8", ARM::R11)
2662 .Case("sb", ARM::R9)
2663 .Case("sl", ARM::R10)
2664 .Case("fp", ARM::R11)
2668 // Check for aliases registered via .req. Canonicalize to lower case.
2669 // That's more consistent since register names are case insensitive, and
2670 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2671 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2672 // If no match, return failure.
2673 if (Entry == RegisterReqs.end())
2675 Parser.Lex(); // Eat identifier token.
2676 return Entry->getValue();
2679 Parser.Lex(); // Eat identifier token.
2684 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2685 // If a recoverable error occurs, return 1. If an irrecoverable error
2686 // occurs, return -1. An irrecoverable error is one where tokens have been
2687 // consumed in the process of trying to parse the shifter (i.e., when it is
2688 // indeed a shifter operand, but malformed).
2689 int ARMAsmParser::tryParseShiftRegister(
2690 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2691 SMLoc S = Parser.getTok().getLoc();
2692 const AsmToken &Tok = Parser.getTok();
2693 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2695 std::string lowerCase = Tok.getString().lower();
2696 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2697 .Case("asl", ARM_AM::lsl)
2698 .Case("lsl", ARM_AM::lsl)
2699 .Case("lsr", ARM_AM::lsr)
2700 .Case("asr", ARM_AM::asr)
2701 .Case("ror", ARM_AM::ror)
2702 .Case("rrx", ARM_AM::rrx)
2703 .Default(ARM_AM::no_shift);
2705 if (ShiftTy == ARM_AM::no_shift)
2708 Parser.Lex(); // Eat the operator.
2710 // The source register for the shift has already been added to the
2711 // operand list, so we need to pop it off and combine it into the shifted
2712 // register operand instead.
2713 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2714 if (!PrevOp->isReg())
2715 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2716 int SrcReg = PrevOp->getReg();
2721 if (ShiftTy == ARM_AM::rrx) {
2722 // RRX Doesn't have an explicit shift amount. The encoder expects
2723 // the shift register to be the same as the source register. Seems odd,
2727 // Figure out if this is shifted by a constant or a register (for non-RRX).
2728 if (Parser.getTok().is(AsmToken::Hash) ||
2729 Parser.getTok().is(AsmToken::Dollar)) {
2730 Parser.Lex(); // Eat hash.
2731 SMLoc ImmLoc = Parser.getTok().getLoc();
2732 const MCExpr *ShiftExpr = 0;
2733 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2734 Error(ImmLoc, "invalid immediate shift value");
2737 // The expression must be evaluatable as an immediate.
2738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2740 Error(ImmLoc, "invalid immediate shift value");
2743 // Range check the immediate.
2744 // lsl, ror: 0 <= imm <= 31
2745 // lsr, asr: 0 <= imm <= 32
2746 Imm = CE->getValue();
2748 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2749 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2750 Error(ImmLoc, "immediate shift value out of range");
2753 // shift by zero is a nop. Always send it through as lsl.
2754 // ('as' compatibility)
2756 ShiftTy = ARM_AM::lsl;
2757 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2758 SMLoc L = Parser.getTok().getLoc();
2759 EndLoc = Parser.getTok().getEndLoc();
2760 ShiftReg = tryParseRegister();
2761 if (ShiftReg == -1) {
2762 Error (L, "expected immediate or register in shift operand");
2766 Error (Parser.getTok().getLoc(),
2767 "expected immediate or register in shift operand");
2772 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2773 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2777 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2784 /// Try to parse a register name. The token must be an Identifier when called.
2785 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2786 /// if there is a "writeback". 'true' if it's not a register.
2788 /// TODO this is likely to change to allow different register types and or to
2789 /// parse for a specific register type.
2791 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2792 const AsmToken &RegTok = Parser.getTok();
2793 int RegNo = tryParseRegister();
2797 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2798 RegTok.getEndLoc()));
2800 const AsmToken &ExclaimTok = Parser.getTok();
2801 if (ExclaimTok.is(AsmToken::Exclaim)) {
2802 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2803 ExclaimTok.getLoc()));
2804 Parser.Lex(); // Eat exclaim token
2808 // Also check for an index operand. This is only legal for vector registers,
2809 // but that'll get caught OK in operand matching, so we don't need to
2810 // explicitly filter everything else out here.
2811 if (Parser.getTok().is(AsmToken::LBrac)) {
2812 SMLoc SIdx = Parser.getTok().getLoc();
2813 Parser.Lex(); // Eat left bracket token.
2815 const MCExpr *ImmVal;
2816 if (getParser().parseExpression(ImmVal))
2818 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2820 return TokError("immediate value expected for vector index");
2822 if (Parser.getTok().isNot(AsmToken::RBrac))
2823 return Error(Parser.getTok().getLoc(), "']' expected");
2825 SMLoc E = Parser.getTok().getEndLoc();
2826 Parser.Lex(); // Eat right bracket token.
2828 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2836 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2837 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2839 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2840 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2842 switch (Name.size()) {
2845 if (Name[0] != CoprocOp)
2861 if (Name[0] != CoprocOp || Name[1] != '1')
2865 case '0': return 10;
2866 case '1': return 11;
2867 case '2': return 12;
2868 case '3': return 13;
2869 case '4': return 14;
2870 case '5': return 15;
2875 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2876 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2877 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2878 SMLoc S = Parser.getTok().getLoc();
2879 const AsmToken &Tok = Parser.getTok();
2880 if (!Tok.is(AsmToken::Identifier))
2881 return MatchOperand_NoMatch;
2882 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2883 .Case("eq", ARMCC::EQ)
2884 .Case("ne", ARMCC::NE)
2885 .Case("hs", ARMCC::HS)
2886 .Case("cs", ARMCC::HS)
2887 .Case("lo", ARMCC::LO)
2888 .Case("cc", ARMCC::LO)
2889 .Case("mi", ARMCC::MI)
2890 .Case("pl", ARMCC::PL)
2891 .Case("vs", ARMCC::VS)
2892 .Case("vc", ARMCC::VC)
2893 .Case("hi", ARMCC::HI)
2894 .Case("ls", ARMCC::LS)
2895 .Case("ge", ARMCC::GE)
2896 .Case("lt", ARMCC::LT)
2897 .Case("gt", ARMCC::GT)
2898 .Case("le", ARMCC::LE)
2899 .Case("al", ARMCC::AL)
2902 return MatchOperand_NoMatch;
2903 Parser.Lex(); // Eat the token.
2905 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2907 return MatchOperand_Success;
2910 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2911 /// token must be an Identifier when called, and if it is a coprocessor
2912 /// number, the token is eaten and the operand is added to the operand list.
2913 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2914 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2915 SMLoc S = Parser.getTok().getLoc();
2916 const AsmToken &Tok = Parser.getTok();
2917 if (Tok.isNot(AsmToken::Identifier))
2918 return MatchOperand_NoMatch;
2920 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2922 return MatchOperand_NoMatch;
2924 Parser.Lex(); // Eat identifier token.
2925 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2926 return MatchOperand_Success;
2929 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2930 /// token must be an Identifier when called, and if it is a coprocessor
2931 /// number, the token is eaten and the operand is added to the operand list.
2932 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2933 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2934 SMLoc S = Parser.getTok().getLoc();
2935 const AsmToken &Tok = Parser.getTok();
2936 if (Tok.isNot(AsmToken::Identifier))
2937 return MatchOperand_NoMatch;
2939 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2941 return MatchOperand_NoMatch;
2943 Parser.Lex(); // Eat identifier token.
2944 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2945 return MatchOperand_Success;
2948 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2949 /// coproc_option : '{' imm0_255 '}'
2950 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2951 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2952 SMLoc S = Parser.getTok().getLoc();
2954 // If this isn't a '{', this isn't a coprocessor immediate operand.
2955 if (Parser.getTok().isNot(AsmToken::LCurly))
2956 return MatchOperand_NoMatch;
2957 Parser.Lex(); // Eat the '{'
2960 SMLoc Loc = Parser.getTok().getLoc();
2961 if (getParser().parseExpression(Expr)) {
2962 Error(Loc, "illegal expression");
2963 return MatchOperand_ParseFail;
2965 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2966 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2967 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2968 return MatchOperand_ParseFail;
2970 int Val = CE->getValue();
2972 // Check for and consume the closing '}'
2973 if (Parser.getTok().isNot(AsmToken::RCurly))
2974 return MatchOperand_ParseFail;
2975 SMLoc E = Parser.getTok().getEndLoc();
2976 Parser.Lex(); // Eat the '}'
2978 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2979 return MatchOperand_Success;
2982 // For register list parsing, we need to map from raw GPR register numbering
2983 // to the enumeration values. The enumeration values aren't sorted by
2984 // register number due to our using "sp", "lr" and "pc" as canonical names.
2985 static unsigned getNextRegister(unsigned Reg) {
2986 // If this is a GPR, we need to do it manually, otherwise we can rely
2987 // on the sort ordering of the enumeration since the other reg-classes
2989 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2992 default: llvm_unreachable("Invalid GPR number!");
2993 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2994 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2995 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2996 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2997 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2998 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2999 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3000 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3004 // Return the low-subreg of a given Q register.
3005 static unsigned getDRegFromQReg(unsigned QReg) {
3007 default: llvm_unreachable("expected a Q register!");
3008 case ARM::Q0: return ARM::D0;
3009 case ARM::Q1: return ARM::D2;
3010 case ARM::Q2: return ARM::D4;
3011 case ARM::Q3: return ARM::D6;
3012 case ARM::Q4: return ARM::D8;
3013 case ARM::Q5: return ARM::D10;
3014 case ARM::Q6: return ARM::D12;
3015 case ARM::Q7: return ARM::D14;
3016 case ARM::Q8: return ARM::D16;
3017 case ARM::Q9: return ARM::D18;
3018 case ARM::Q10: return ARM::D20;
3019 case ARM::Q11: return ARM::D22;
3020 case ARM::Q12: return ARM::D24;
3021 case ARM::Q13: return ARM::D26;
3022 case ARM::Q14: return ARM::D28;
3023 case ARM::Q15: return ARM::D30;
3027 /// Parse a register list.
3029 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3030 assert(Parser.getTok().is(AsmToken::LCurly) &&
3031 "Token is not a Left Curly Brace");
3032 SMLoc S = Parser.getTok().getLoc();
3033 Parser.Lex(); // Eat '{' token.
3034 SMLoc RegLoc = Parser.getTok().getLoc();
3036 // Check the first register in the list to see what register class
3037 // this is a list of.
3038 int Reg = tryParseRegister();
3040 return Error(RegLoc, "register expected");
3042 // The reglist instructions have at most 16 registers, so reserve
3043 // space for that many.
3045 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3047 // Allow Q regs and just interpret them as the two D sub-registers.
3048 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3049 Reg = getDRegFromQReg(Reg);
3050 EReg = MRI->getEncodingValue(Reg);
3051 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3054 const MCRegisterClass *RC;
3055 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3056 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3057 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3058 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3059 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3060 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3062 return Error(RegLoc, "invalid register in register list");
3064 // Store the register.
3065 EReg = MRI->getEncodingValue(Reg);
3066 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3068 // This starts immediately after the first register token in the list,
3069 // so we can see either a comma or a minus (range separator) as a legal
3071 while (Parser.getTok().is(AsmToken::Comma) ||
3072 Parser.getTok().is(AsmToken::Minus)) {
3073 if (Parser.getTok().is(AsmToken::Minus)) {
3074 Parser.Lex(); // Eat the minus.
3075 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3076 int EndReg = tryParseRegister();
3078 return Error(AfterMinusLoc, "register expected");
3079 // Allow Q regs and just interpret them as the two D sub-registers.
3080 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3081 EndReg = getDRegFromQReg(EndReg) + 1;
3082 // If the register is the same as the start reg, there's nothing
3086 // The register must be in the same register class as the first.
3087 if (!RC->contains(EndReg))
3088 return Error(AfterMinusLoc, "invalid register in register list");
3089 // Ranges must go from low to high.
3090 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3091 return Error(AfterMinusLoc, "bad range in register list");
3093 // Add all the registers in the range to the register list.
3094 while (Reg != EndReg) {
3095 Reg = getNextRegister(Reg);
3096 EReg = MRI->getEncodingValue(Reg);
3097 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3101 Parser.Lex(); // Eat the comma.
3102 RegLoc = Parser.getTok().getLoc();
3104 const AsmToken RegTok = Parser.getTok();
3105 Reg = tryParseRegister();
3107 return Error(RegLoc, "register expected");
3108 // Allow Q regs and just interpret them as the two D sub-registers.
3109 bool isQReg = false;
3110 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3111 Reg = getDRegFromQReg(Reg);
3114 // The register must be in the same register class as the first.
3115 if (!RC->contains(Reg))
3116 return Error(RegLoc, "invalid register in register list");
3117 // List must be monotonically increasing.
3118 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3119 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3120 Warning(RegLoc, "register list not in ascending order");
3122 return Error(RegLoc, "register list not in ascending order");
3124 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3125 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3126 ") in register list");
3129 // VFP register lists must also be contiguous.
3130 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3132 return Error(RegLoc, "non-contiguous register range");
3133 EReg = MRI->getEncodingValue(Reg);
3134 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3136 EReg = MRI->getEncodingValue(++Reg);
3137 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3141 if (Parser.getTok().isNot(AsmToken::RCurly))
3142 return Error(Parser.getTok().getLoc(), "'}' expected");
3143 SMLoc E = Parser.getTok().getEndLoc();
3144 Parser.Lex(); // Eat '}' token.
3146 // Push the register list operand.
3147 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3149 // The ARM system instruction variants for LDM/STM have a '^' token here.
3150 if (Parser.getTok().is(AsmToken::Caret)) {
3151 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3152 Parser.Lex(); // Eat '^' token.
3158 // Helper function to parse the lane index for vector lists.
3159 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3160 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3161 Index = 0; // Always return a defined index value.
3162 if (Parser.getTok().is(AsmToken::LBrac)) {
3163 Parser.Lex(); // Eat the '['.
3164 if (Parser.getTok().is(AsmToken::RBrac)) {
3165 // "Dn[]" is the 'all lanes' syntax.
3166 LaneKind = AllLanes;
3167 EndLoc = Parser.getTok().getEndLoc();
3168 Parser.Lex(); // Eat the ']'.
3169 return MatchOperand_Success;
3172 // There's an optional '#' token here. Normally there wouldn't be, but
3173 // inline assemble puts one in, and it's friendly to accept that.
3174 if (Parser.getTok().is(AsmToken::Hash))
3175 Parser.Lex(); // Eat '#' or '$'.
3177 const MCExpr *LaneIndex;
3178 SMLoc Loc = Parser.getTok().getLoc();
3179 if (getParser().parseExpression(LaneIndex)) {
3180 Error(Loc, "illegal expression");
3181 return MatchOperand_ParseFail;
3183 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3185 Error(Loc, "lane index must be empty or an integer");
3186 return MatchOperand_ParseFail;
3188 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3189 Error(Parser.getTok().getLoc(), "']' expected");
3190 return MatchOperand_ParseFail;
3192 EndLoc = Parser.getTok().getEndLoc();
3193 Parser.Lex(); // Eat the ']'.
3194 int64_t Val = CE->getValue();
3196 // FIXME: Make this range check context sensitive for .8, .16, .32.
3197 if (Val < 0 || Val > 7) {
3198 Error(Parser.getTok().getLoc(), "lane index out of range");
3199 return MatchOperand_ParseFail;
3202 LaneKind = IndexedLane;
3203 return MatchOperand_Success;
3206 return MatchOperand_Success;
3209 // parse a vector register list
3210 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3211 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3212 VectorLaneTy LaneKind;
3214 SMLoc S = Parser.getTok().getLoc();
3215 // As an extension (to match gas), support a plain D register or Q register
3216 // (without encosing curly braces) as a single or double entry list,
3218 if (Parser.getTok().is(AsmToken::Identifier)) {
3219 SMLoc E = Parser.getTok().getEndLoc();
3220 int Reg = tryParseRegister();
3222 return MatchOperand_NoMatch;
3223 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3224 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3225 if (Res != MatchOperand_Success)
3229 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3232 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3236 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3241 return MatchOperand_Success;
3243 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3244 Reg = getDRegFromQReg(Reg);
3245 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3246 if (Res != MatchOperand_Success)
3250 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3251 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3252 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3255 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3256 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3257 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3261 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3266 return MatchOperand_Success;
3268 Error(S, "vector register expected");
3269 return MatchOperand_ParseFail;
3272 if (Parser.getTok().isNot(AsmToken::LCurly))
3273 return MatchOperand_NoMatch;
3275 Parser.Lex(); // Eat '{' token.
3276 SMLoc RegLoc = Parser.getTok().getLoc();
3278 int Reg = tryParseRegister();
3280 Error(RegLoc, "register expected");
3281 return MatchOperand_ParseFail;
3285 unsigned FirstReg = Reg;
3286 // The list is of D registers, but we also allow Q regs and just interpret
3287 // them as the two D sub-registers.
3288 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3289 FirstReg = Reg = getDRegFromQReg(Reg);
3290 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3291 // it's ambiguous with four-register single spaced.
3297 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3298 return MatchOperand_ParseFail;
3300 while (Parser.getTok().is(AsmToken::Comma) ||
3301 Parser.getTok().is(AsmToken::Minus)) {
3302 if (Parser.getTok().is(AsmToken::Minus)) {
3304 Spacing = 1; // Register range implies a single spaced list.
3305 else if (Spacing == 2) {
3306 Error(Parser.getTok().getLoc(),
3307 "sequential registers in double spaced list");
3308 return MatchOperand_ParseFail;
3310 Parser.Lex(); // Eat the minus.
3311 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3312 int EndReg = tryParseRegister();
3314 Error(AfterMinusLoc, "register expected");
3315 return MatchOperand_ParseFail;
3317 // Allow Q regs and just interpret them as the two D sub-registers.
3318 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3319 EndReg = getDRegFromQReg(EndReg) + 1;
3320 // If the register is the same as the start reg, there's nothing
3324 // The register must be in the same register class as the first.
3325 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3326 Error(AfterMinusLoc, "invalid register in register list");
3327 return MatchOperand_ParseFail;
3329 // Ranges must go from low to high.
3331 Error(AfterMinusLoc, "bad range in register list");
3332 return MatchOperand_ParseFail;
3334 // Parse the lane specifier if present.
3335 VectorLaneTy NextLaneKind;
3336 unsigned NextLaneIndex;
3337 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3338 MatchOperand_Success)
3339 return MatchOperand_ParseFail;
3340 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3341 Error(AfterMinusLoc, "mismatched lane index in register list");
3342 return MatchOperand_ParseFail;
3345 // Add all the registers in the range to the register list.
3346 Count += EndReg - Reg;
3350 Parser.Lex(); // Eat the comma.
3351 RegLoc = Parser.getTok().getLoc();
3353 Reg = tryParseRegister();
3355 Error(RegLoc, "register expected");
3356 return MatchOperand_ParseFail;
3358 // vector register lists must be contiguous.
3359 // It's OK to use the enumeration values directly here rather, as the
3360 // VFP register classes have the enum sorted properly.
3362 // The list is of D registers, but we also allow Q regs and just interpret
3363 // them as the two D sub-registers.
3364 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3366 Spacing = 1; // Register range implies a single spaced list.
3367 else if (Spacing == 2) {
3369 "invalid register in double-spaced list (must be 'D' register')");
3370 return MatchOperand_ParseFail;
3372 Reg = getDRegFromQReg(Reg);
3373 if (Reg != OldReg + 1) {
3374 Error(RegLoc, "non-contiguous register range");
3375 return MatchOperand_ParseFail;
3379 // Parse the lane specifier if present.
3380 VectorLaneTy NextLaneKind;
3381 unsigned NextLaneIndex;
3382 SMLoc LaneLoc = Parser.getTok().getLoc();
3383 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3384 MatchOperand_Success)
3385 return MatchOperand_ParseFail;
3386 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3387 Error(LaneLoc, "mismatched lane index in register list");
3388 return MatchOperand_ParseFail;
3392 // Normal D register.
3393 // Figure out the register spacing (single or double) of the list if
3394 // we don't know it already.
3396 Spacing = 1 + (Reg == OldReg + 2);
3398 // Just check that it's contiguous and keep going.
3399 if (Reg != OldReg + Spacing) {
3400 Error(RegLoc, "non-contiguous register range");
3401 return MatchOperand_ParseFail;
3404 // Parse the lane specifier if present.
3405 VectorLaneTy NextLaneKind;
3406 unsigned NextLaneIndex;
3407 SMLoc EndLoc = Parser.getTok().getLoc();
3408 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3409 return MatchOperand_ParseFail;
3410 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3411 Error(EndLoc, "mismatched lane index in register list");
3412 return MatchOperand_ParseFail;
3416 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3417 Error(Parser.getTok().getLoc(), "'}' expected");
3418 return MatchOperand_ParseFail;
3420 E = Parser.getTok().getEndLoc();
3421 Parser.Lex(); // Eat '}' token.
3425 // Two-register operands have been converted to the
3426 // composite register classes.
3428 const MCRegisterClass *RC = (Spacing == 1) ?
3429 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3430 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3431 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3434 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3435 (Spacing == 2), S, E));
3438 // Two-register operands have been converted to the
3439 // composite register classes.
3441 const MCRegisterClass *RC = (Spacing == 1) ?
3442 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3443 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3444 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3446 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3451 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3457 return MatchOperand_Success;
3460 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3461 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3462 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3463 SMLoc S = Parser.getTok().getLoc();
3464 const AsmToken &Tok = Parser.getTok();
3467 if (Tok.is(AsmToken::Identifier)) {
3468 StringRef OptStr = Tok.getString();
3470 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3471 .Case("sy", ARM_MB::SY)
3472 .Case("st", ARM_MB::ST)
3473 .Case("ld", ARM_MB::LD)
3474 .Case("sh", ARM_MB::ISH)
3475 .Case("ish", ARM_MB::ISH)
3476 .Case("shst", ARM_MB::ISHST)
3477 .Case("ishst", ARM_MB::ISHST)
3478 .Case("ishld", ARM_MB::ISHLD)
3479 .Case("nsh", ARM_MB::NSH)
3480 .Case("un", ARM_MB::NSH)
3481 .Case("nshst", ARM_MB::NSHST)
3482 .Case("nshld", ARM_MB::NSHLD)
3483 .Case("unst", ARM_MB::NSHST)
3484 .Case("osh", ARM_MB::OSH)
3485 .Case("oshst", ARM_MB::OSHST)
3486 .Case("oshld", ARM_MB::OSHLD)
3489 // ishld, oshld, nshld and ld are only available from ARMv8.
3490 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3491 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3495 return MatchOperand_NoMatch;
3497 Parser.Lex(); // Eat identifier token.
3498 } else if (Tok.is(AsmToken::Hash) ||
3499 Tok.is(AsmToken::Dollar) ||
3500 Tok.is(AsmToken::Integer)) {
3501 if (Parser.getTok().isNot(AsmToken::Integer))
3502 Parser.Lex(); // Eat '#' or '$'.
3503 SMLoc Loc = Parser.getTok().getLoc();
3505 const MCExpr *MemBarrierID;
3506 if (getParser().parseExpression(MemBarrierID)) {
3507 Error(Loc, "illegal expression");
3508 return MatchOperand_ParseFail;
3511 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3513 Error(Loc, "constant expression expected");
3514 return MatchOperand_ParseFail;
3517 int Val = CE->getValue();
3519 Error(Loc, "immediate value out of range");
3520 return MatchOperand_ParseFail;
3523 Opt = ARM_MB::RESERVED_0 + Val;
3525 return MatchOperand_ParseFail;
3527 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3528 return MatchOperand_Success;
3531 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3532 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3533 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3534 SMLoc S = Parser.getTok().getLoc();
3535 const AsmToken &Tok = Parser.getTok();
3538 if (Tok.is(AsmToken::Identifier)) {
3539 StringRef OptStr = Tok.getString();
3541 if (OptStr.lower() == "sy")
3544 return MatchOperand_NoMatch;
3546 Parser.Lex(); // Eat identifier token.
3547 } else if (Tok.is(AsmToken::Hash) ||
3548 Tok.is(AsmToken::Dollar) ||
3549 Tok.is(AsmToken::Integer)) {
3550 if (Parser.getTok().isNot(AsmToken::Integer))
3551 Parser.Lex(); // Eat '#' or '$'.
3552 SMLoc Loc = Parser.getTok().getLoc();
3554 const MCExpr *ISBarrierID;
3555 if (getParser().parseExpression(ISBarrierID)) {
3556 Error(Loc, "illegal expression");
3557 return MatchOperand_ParseFail;
3560 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3562 Error(Loc, "constant expression expected");
3563 return MatchOperand_ParseFail;
3566 int Val = CE->getValue();
3568 Error(Loc, "immediate value out of range");
3569 return MatchOperand_ParseFail;
3572 Opt = ARM_ISB::RESERVED_0 + Val;
3574 return MatchOperand_ParseFail;
3576 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3577 (ARM_ISB::InstSyncBOpt)Opt, S));
3578 return MatchOperand_Success;
3582 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3583 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3584 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3585 SMLoc S = Parser.getTok().getLoc();
3586 const AsmToken &Tok = Parser.getTok();
3587 if (!Tok.is(AsmToken::Identifier))
3588 return MatchOperand_NoMatch;
3589 StringRef IFlagsStr = Tok.getString();
3591 // An iflags string of "none" is interpreted to mean that none of the AIF
3592 // bits are set. Not a terribly useful instruction, but a valid encoding.
3593 unsigned IFlags = 0;
3594 if (IFlagsStr != "none") {
3595 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3596 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3597 .Case("a", ARM_PROC::A)
3598 .Case("i", ARM_PROC::I)
3599 .Case("f", ARM_PROC::F)
3602 // If some specific iflag is already set, it means that some letter is
3603 // present more than once, this is not acceptable.
3604 if (Flag == ~0U || (IFlags & Flag))
3605 return MatchOperand_NoMatch;
3611 Parser.Lex(); // Eat identifier token.
3612 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3613 return MatchOperand_Success;
3616 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3617 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3618 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3619 SMLoc S = Parser.getTok().getLoc();
3620 const AsmToken &Tok = Parser.getTok();
3621 if (!Tok.is(AsmToken::Identifier))
3622 return MatchOperand_NoMatch;
3623 StringRef Mask = Tok.getString();
3626 // See ARMv6-M 10.1.1
3627 std::string Name = Mask.lower();
3628 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3629 // Note: in the documentation:
3630 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3631 // for MSR APSR_nzcvq.
3632 // but we do make it an alias here. This is so to get the "mask encoding"
3633 // bits correct on MSR APSR writes.
3635 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3636 // should really only be allowed when writing a special register. Note
3637 // they get dropped in the MRS instruction reading a special register as
3638 // the SYSm field is only 8 bits.
3640 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3641 // includes the DSP extension but that is not checked.
3642 .Case("apsr", 0x800)
3643 .Case("apsr_nzcvq", 0x800)
3644 .Case("apsr_g", 0x400)
3645 .Case("apsr_nzcvqg", 0xc00)
3646 .Case("iapsr", 0x801)
3647 .Case("iapsr_nzcvq", 0x801)
3648 .Case("iapsr_g", 0x401)
3649 .Case("iapsr_nzcvqg", 0xc01)
3650 .Case("eapsr", 0x802)
3651 .Case("eapsr_nzcvq", 0x802)
3652 .Case("eapsr_g", 0x402)
3653 .Case("eapsr_nzcvqg", 0xc02)
3654 .Case("xpsr", 0x803)
3655 .Case("xpsr_nzcvq", 0x803)
3656 .Case("xpsr_g", 0x403)
3657 .Case("xpsr_nzcvqg", 0xc03)
3658 .Case("ipsr", 0x805)
3659 .Case("epsr", 0x806)
3660 .Case("iepsr", 0x807)
3663 .Case("primask", 0x810)
3664 .Case("basepri", 0x811)
3665 .Case("basepri_max", 0x812)
3666 .Case("faultmask", 0x813)
3667 .Case("control", 0x814)
3670 if (FlagsVal == ~0U)
3671 return MatchOperand_NoMatch;
3673 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3674 // basepri, basepri_max and faultmask only valid for V7m.
3675 return MatchOperand_NoMatch;
3677 Parser.Lex(); // Eat identifier token.
3678 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3679 return MatchOperand_Success;
3682 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3683 size_t Start = 0, Next = Mask.find('_');
3684 StringRef Flags = "";
3685 std::string SpecReg = Mask.slice(Start, Next).lower();
3686 if (Next != StringRef::npos)
3687 Flags = Mask.slice(Next+1, Mask.size());
3689 // FlagsVal contains the complete mask:
3691 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3692 unsigned FlagsVal = 0;
3694 if (SpecReg == "apsr") {
3695 FlagsVal = StringSwitch<unsigned>(Flags)
3696 .Case("nzcvq", 0x8) // same as CPSR_f
3697 .Case("g", 0x4) // same as CPSR_s
3698 .Case("nzcvqg", 0xc) // same as CPSR_fs
3701 if (FlagsVal == ~0U) {
3703 return MatchOperand_NoMatch;
3705 FlagsVal = 8; // No flag
3707 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3708 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3709 if (Flags == "all" || Flags == "")
3711 for (int i = 0, e = Flags.size(); i != e; ++i) {
3712 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3719 // If some specific flag is already set, it means that some letter is
3720 // present more than once, this is not acceptable.
3721 if (FlagsVal == ~0U || (FlagsVal & Flag))
3722 return MatchOperand_NoMatch;
3725 } else // No match for special register.
3726 return MatchOperand_NoMatch;
3728 // Special register without flags is NOT equivalent to "fc" flags.
3729 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3730 // two lines would enable gas compatibility at the expense of breaking
3736 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3737 if (SpecReg == "spsr")
3740 Parser.Lex(); // Eat identifier token.
3741 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3742 return MatchOperand_Success;
3745 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3746 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3747 int Low, int High) {
3748 const AsmToken &Tok = Parser.getTok();
3749 if (Tok.isNot(AsmToken::Identifier)) {
3750 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3751 return MatchOperand_ParseFail;
3753 StringRef ShiftName = Tok.getString();
3754 std::string LowerOp = Op.lower();
3755 std::string UpperOp = Op.upper();
3756 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3757 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3758 return MatchOperand_ParseFail;
3760 Parser.Lex(); // Eat shift type token.
3762 // There must be a '#' and a shift amount.
3763 if (Parser.getTok().isNot(AsmToken::Hash) &&
3764 Parser.getTok().isNot(AsmToken::Dollar)) {
3765 Error(Parser.getTok().getLoc(), "'#' expected");
3766 return MatchOperand_ParseFail;
3768 Parser.Lex(); // Eat hash token.
3770 const MCExpr *ShiftAmount;
3771 SMLoc Loc = Parser.getTok().getLoc();
3773 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3774 Error(Loc, "illegal expression");
3775 return MatchOperand_ParseFail;
3777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3779 Error(Loc, "constant expression expected");
3780 return MatchOperand_ParseFail;
3782 int Val = CE->getValue();
3783 if (Val < Low || Val > High) {
3784 Error(Loc, "immediate value out of range");
3785 return MatchOperand_ParseFail;
3788 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3790 return MatchOperand_Success;
3793 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3794 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3795 const AsmToken &Tok = Parser.getTok();
3796 SMLoc S = Tok.getLoc();
3797 if (Tok.isNot(AsmToken::Identifier)) {
3798 Error(S, "'be' or 'le' operand expected");
3799 return MatchOperand_ParseFail;
3801 int Val = StringSwitch<int>(Tok.getString().lower())
3805 Parser.Lex(); // Eat the token.
3808 Error(S, "'be' or 'le' operand expected");
3809 return MatchOperand_ParseFail;
3811 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3813 S, Tok.getEndLoc()));
3814 return MatchOperand_Success;
3817 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3818 /// instructions. Legal values are:
3819 /// lsl #n 'n' in [0,31]
3820 /// asr #n 'n' in [1,32]
3821 /// n == 32 encoded as n == 0.
3822 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3823 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3824 const AsmToken &Tok = Parser.getTok();
3825 SMLoc S = Tok.getLoc();
3826 if (Tok.isNot(AsmToken::Identifier)) {
3827 Error(S, "shift operator 'asr' or 'lsl' expected");
3828 return MatchOperand_ParseFail;
3830 StringRef ShiftName = Tok.getString();
3832 if (ShiftName == "lsl" || ShiftName == "LSL")
3834 else if (ShiftName == "asr" || ShiftName == "ASR")
3837 Error(S, "shift operator 'asr' or 'lsl' expected");
3838 return MatchOperand_ParseFail;
3840 Parser.Lex(); // Eat the operator.
3842 // A '#' and a shift amount.
3843 if (Parser.getTok().isNot(AsmToken::Hash) &&
3844 Parser.getTok().isNot(AsmToken::Dollar)) {
3845 Error(Parser.getTok().getLoc(), "'#' expected");
3846 return MatchOperand_ParseFail;
3848 Parser.Lex(); // Eat hash token.
3849 SMLoc ExLoc = Parser.getTok().getLoc();
3851 const MCExpr *ShiftAmount;
3853 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3854 Error(ExLoc, "malformed shift expression");
3855 return MatchOperand_ParseFail;
3857 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3859 Error(ExLoc, "shift amount must be an immediate");
3860 return MatchOperand_ParseFail;
3863 int64_t Val = CE->getValue();
3865 // Shift amount must be in [1,32]
3866 if (Val < 1 || Val > 32) {
3867 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3868 return MatchOperand_ParseFail;
3870 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3871 if (isThumb() && Val == 32) {
3872 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3873 return MatchOperand_ParseFail;
3875 if (Val == 32) Val = 0;
3877 // Shift amount must be in [1,32]
3878 if (Val < 0 || Val > 31) {
3879 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3880 return MatchOperand_ParseFail;
3884 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3886 return MatchOperand_Success;
3889 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3890 /// of instructions. Legal values are:
3891 /// ror #n 'n' in {0, 8, 16, 24}
3892 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3893 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3894 const AsmToken &Tok = Parser.getTok();
3895 SMLoc S = Tok.getLoc();
3896 if (Tok.isNot(AsmToken::Identifier))
3897 return MatchOperand_NoMatch;
3898 StringRef ShiftName = Tok.getString();
3899 if (ShiftName != "ror" && ShiftName != "ROR")
3900 return MatchOperand_NoMatch;
3901 Parser.Lex(); // Eat the operator.
3903 // A '#' and a rotate amount.
3904 if (Parser.getTok().isNot(AsmToken::Hash) &&
3905 Parser.getTok().isNot(AsmToken::Dollar)) {
3906 Error(Parser.getTok().getLoc(), "'#' expected");
3907 return MatchOperand_ParseFail;
3909 Parser.Lex(); // Eat hash token.
3910 SMLoc ExLoc = Parser.getTok().getLoc();
3912 const MCExpr *ShiftAmount;
3914 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3915 Error(ExLoc, "malformed rotate expression");
3916 return MatchOperand_ParseFail;
3918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3920 Error(ExLoc, "rotate amount must be an immediate");
3921 return MatchOperand_ParseFail;
3924 int64_t Val = CE->getValue();
3925 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3926 // normally, zero is represented in asm by omitting the rotate operand
3928 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3929 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
3930 return MatchOperand_ParseFail;
3933 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
3935 return MatchOperand_Success;
3938 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3939 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3940 SMLoc S = Parser.getTok().getLoc();
3941 // The bitfield descriptor is really two operands, the LSB and the width.
3942 if (Parser.getTok().isNot(AsmToken::Hash) &&
3943 Parser.getTok().isNot(AsmToken::Dollar)) {
3944 Error(Parser.getTok().getLoc(), "'#' expected");
3945 return MatchOperand_ParseFail;
3947 Parser.Lex(); // Eat hash token.
3949 const MCExpr *LSBExpr;
3950 SMLoc E = Parser.getTok().getLoc();
3951 if (getParser().parseExpression(LSBExpr)) {
3952 Error(E, "malformed immediate expression");
3953 return MatchOperand_ParseFail;
3955 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3957 Error(E, "'lsb' operand must be an immediate");
3958 return MatchOperand_ParseFail;
3961 int64_t LSB = CE->getValue();
3962 // The LSB must be in the range [0,31]
3963 if (LSB < 0 || LSB > 31) {
3964 Error(E, "'lsb' operand must be in the range [0,31]");
3965 return MatchOperand_ParseFail;
3967 E = Parser.getTok().getLoc();
3969 // Expect another immediate operand.
3970 if (Parser.getTok().isNot(AsmToken::Comma)) {
3971 Error(Parser.getTok().getLoc(), "too few operands");
3972 return MatchOperand_ParseFail;
3974 Parser.Lex(); // Eat hash token.
3975 if (Parser.getTok().isNot(AsmToken::Hash) &&
3976 Parser.getTok().isNot(AsmToken::Dollar)) {
3977 Error(Parser.getTok().getLoc(), "'#' expected");
3978 return MatchOperand_ParseFail;
3980 Parser.Lex(); // Eat hash token.
3982 const MCExpr *WidthExpr;
3984 if (getParser().parseExpression(WidthExpr, EndLoc)) {
3985 Error(E, "malformed immediate expression");
3986 return MatchOperand_ParseFail;
3988 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3990 Error(E, "'width' operand must be an immediate");
3991 return MatchOperand_ParseFail;
3994 int64_t Width = CE->getValue();
3995 // The LSB must be in the range [1,32-lsb]
3996 if (Width < 1 || Width > 32 - LSB) {
3997 Error(E, "'width' operand must be in the range [1,32-lsb]");
3998 return MatchOperand_ParseFail;
4001 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
4003 return MatchOperand_Success;
4006 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4007 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4008 // Check for a post-index addressing register operand. Specifically:
4009 // postidx_reg := '+' register {, shift}
4010 // | '-' register {, shift}
4011 // | register {, shift}
4013 // This method must return MatchOperand_NoMatch without consuming any tokens
4014 // in the case where there is no match, as other alternatives take other
4016 AsmToken Tok = Parser.getTok();
4017 SMLoc S = Tok.getLoc();
4018 bool haveEaten = false;
4020 if (Tok.is(AsmToken::Plus)) {
4021 Parser.Lex(); // Eat the '+' token.
4023 } else if (Tok.is(AsmToken::Minus)) {
4024 Parser.Lex(); // Eat the '-' token.
4029 SMLoc E = Parser.getTok().getEndLoc();
4030 int Reg = tryParseRegister();
4033 return MatchOperand_NoMatch;
4034 Error(Parser.getTok().getLoc(), "register expected");
4035 return MatchOperand_ParseFail;
4038 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4039 unsigned ShiftImm = 0;
4040 if (Parser.getTok().is(AsmToken::Comma)) {
4041 Parser.Lex(); // Eat the ','.
4042 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4043 return MatchOperand_ParseFail;
4045 // FIXME: Only approximates end...may include intervening whitespace.
4046 E = Parser.getTok().getLoc();
4049 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4052 return MatchOperand_Success;
4055 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4056 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4057 // Check for a post-index addressing register operand. Specifically:
4058 // am3offset := '+' register
4065 // This method must return MatchOperand_NoMatch without consuming any tokens
4066 // in the case where there is no match, as other alternatives take other
4068 AsmToken Tok = Parser.getTok();
4069 SMLoc S = Tok.getLoc();
4071 // Do immediates first, as we always parse those if we have a '#'.
4072 if (Parser.getTok().is(AsmToken::Hash) ||
4073 Parser.getTok().is(AsmToken::Dollar)) {
4074 Parser.Lex(); // Eat '#' or '$'.
4075 // Explicitly look for a '-', as we need to encode negative zero
4077 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4078 const MCExpr *Offset;
4080 if (getParser().parseExpression(Offset, E))
4081 return MatchOperand_ParseFail;
4082 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4084 Error(S, "constant expression expected");
4085 return MatchOperand_ParseFail;
4087 // Negative zero is encoded as the flag value INT32_MIN.
4088 int32_t Val = CE->getValue();
4089 if (isNegative && Val == 0)
4093 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4095 return MatchOperand_Success;
4099 bool haveEaten = false;
4101 if (Tok.is(AsmToken::Plus)) {
4102 Parser.Lex(); // Eat the '+' token.
4104 } else if (Tok.is(AsmToken::Minus)) {
4105 Parser.Lex(); // Eat the '-' token.
4110 Tok = Parser.getTok();
4111 int Reg = tryParseRegister();
4114 return MatchOperand_NoMatch;
4115 Error(Tok.getLoc(), "register expected");
4116 return MatchOperand_ParseFail;
4119 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4120 0, S, Tok.getEndLoc()));
4122 return MatchOperand_Success;
4125 /// Convert parsed operands to MCInst. Needed here because this instruction
4126 /// only has two register operands, but multiplication is commutative so
4127 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4129 cvtThumbMultiply(MCInst &Inst,
4130 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4131 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4132 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4133 // If we have a three-operand form, make sure to set Rn to be the operand
4134 // that isn't the same as Rd.
4136 if (Operands.size() == 6 &&
4137 ((ARMOperand*)Operands[4])->getReg() ==
4138 ((ARMOperand*)Operands[3])->getReg())
4140 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4141 Inst.addOperand(Inst.getOperand(0));
4142 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4146 cvtThumbBranches(MCInst &Inst,
4147 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4148 int CondOp = -1, ImmOp = -1;
4149 switch(Inst.getOpcode()) {
4151 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4154 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4156 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4158 // first decide whether or not the branch should be conditional
4159 // by looking at it's location relative to an IT block
4161 // inside an IT block we cannot have any conditional branches. any
4162 // such instructions needs to be converted to unconditional form
4163 switch(Inst.getOpcode()) {
4164 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4165 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4168 // outside IT blocks we can only have unconditional branches with AL
4169 // condition code or conditional branches with non-AL condition code
4170 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4171 switch(Inst.getOpcode()) {
4174 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4178 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4183 // now decide on encoding size based on branch target range
4184 switch(Inst.getOpcode()) {
4185 // classify tB as either t2B or t1B based on range of immediate operand
4187 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4188 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4189 Inst.setOpcode(ARM::t2B);
4192 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4194 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4195 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4196 Inst.setOpcode(ARM::t2Bcc);
4200 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4201 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4204 /// Parse an ARM memory expression, return false if successful else return true
4205 /// or an error. The first token must be a '[' when called.
4207 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4209 assert(Parser.getTok().is(AsmToken::LBrac) &&
4210 "Token is not a Left Bracket");
4211 S = Parser.getTok().getLoc();
4212 Parser.Lex(); // Eat left bracket token.
4214 const AsmToken &BaseRegTok = Parser.getTok();
4215 int BaseRegNum = tryParseRegister();
4216 if (BaseRegNum == -1)
4217 return Error(BaseRegTok.getLoc(), "register expected");
4219 // The next token must either be a comma, a colon or a closing bracket.
4220 const AsmToken &Tok = Parser.getTok();
4221 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4222 !Tok.is(AsmToken::RBrac))
4223 return Error(Tok.getLoc(), "malformed memory operand");
4225 if (Tok.is(AsmToken::RBrac)) {
4226 E = Tok.getEndLoc();
4227 Parser.Lex(); // Eat right bracket token.
4229 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4230 0, 0, false, S, E));
4232 // If there's a pre-indexing writeback marker, '!', just add it as a token
4233 // operand. It's rather odd, but syntactically valid.
4234 if (Parser.getTok().is(AsmToken::Exclaim)) {
4235 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4236 Parser.Lex(); // Eat the '!'.
4242 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4243 "Lost colon or comma in memory operand?!");
4244 if (Tok.is(AsmToken::Comma)) {
4245 Parser.Lex(); // Eat the comma.
4248 // If we have a ':', it's an alignment specifier.
4249 if (Parser.getTok().is(AsmToken::Colon)) {
4250 Parser.Lex(); // Eat the ':'.
4251 E = Parser.getTok().getLoc();
4254 if (getParser().parseExpression(Expr))
4257 // The expression has to be a constant. Memory references with relocations
4258 // don't come through here, as they use the <label> forms of the relevant
4260 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4262 return Error (E, "constant expression expected");
4265 switch (CE->getValue()) {
4268 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4269 case 16: Align = 2; break;
4270 case 32: Align = 4; break;
4271 case 64: Align = 8; break;
4272 case 128: Align = 16; break;
4273 case 256: Align = 32; break;
4276 // Now we should have the closing ']'
4277 if (Parser.getTok().isNot(AsmToken::RBrac))
4278 return Error(Parser.getTok().getLoc(), "']' expected");
4279 E = Parser.getTok().getEndLoc();
4280 Parser.Lex(); // Eat right bracket token.
4282 // Don't worry about range checking the value here. That's handled by
4283 // the is*() predicates.
4284 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4285 ARM_AM::no_shift, 0, Align,
4288 // If there's a pre-indexing writeback marker, '!', just add it as a token
4290 if (Parser.getTok().is(AsmToken::Exclaim)) {
4291 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4292 Parser.Lex(); // Eat the '!'.
4298 // If we have a '#', it's an immediate offset, else assume it's a register
4299 // offset. Be friendly and also accept a plain integer (without a leading
4300 // hash) for gas compatibility.
4301 if (Parser.getTok().is(AsmToken::Hash) ||
4302 Parser.getTok().is(AsmToken::Dollar) ||
4303 Parser.getTok().is(AsmToken::Integer)) {
4304 if (Parser.getTok().isNot(AsmToken::Integer))
4305 Parser.Lex(); // Eat '#' or '$'.
4306 E = Parser.getTok().getLoc();
4308 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4309 const MCExpr *Offset;
4310 if (getParser().parseExpression(Offset))
4313 // The expression has to be a constant. Memory references with relocations
4314 // don't come through here, as they use the <label> forms of the relevant
4316 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4318 return Error (E, "constant expression expected");
4320 // If the constant was #-0, represent it as INT32_MIN.
4321 int32_t Val = CE->getValue();
4322 if (isNegative && Val == 0)
4323 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4325 // Now we should have the closing ']'
4326 if (Parser.getTok().isNot(AsmToken::RBrac))
4327 return Error(Parser.getTok().getLoc(), "']' expected");
4328 E = Parser.getTok().getEndLoc();
4329 Parser.Lex(); // Eat right bracket token.
4331 // Don't worry about range checking the value here. That's handled by
4332 // the is*() predicates.
4333 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4334 ARM_AM::no_shift, 0, 0,
4337 // If there's a pre-indexing writeback marker, '!', just add it as a token
4339 if (Parser.getTok().is(AsmToken::Exclaim)) {
4340 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4341 Parser.Lex(); // Eat the '!'.
4347 // The register offset is optionally preceded by a '+' or '-'
4348 bool isNegative = false;
4349 if (Parser.getTok().is(AsmToken::Minus)) {
4351 Parser.Lex(); // Eat the '-'.
4352 } else if (Parser.getTok().is(AsmToken::Plus)) {
4354 Parser.Lex(); // Eat the '+'.
4357 E = Parser.getTok().getLoc();
4358 int OffsetRegNum = tryParseRegister();
4359 if (OffsetRegNum == -1)
4360 return Error(E, "register expected");
4362 // If there's a shift operator, handle it.
4363 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4364 unsigned ShiftImm = 0;
4365 if (Parser.getTok().is(AsmToken::Comma)) {
4366 Parser.Lex(); // Eat the ','.
4367 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4371 // Now we should have the closing ']'
4372 if (Parser.getTok().isNot(AsmToken::RBrac))
4373 return Error(Parser.getTok().getLoc(), "']' expected");
4374 E = Parser.getTok().getEndLoc();
4375 Parser.Lex(); // Eat right bracket token.
4377 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4378 ShiftType, ShiftImm, 0, isNegative,
4381 // If there's a pre-indexing writeback marker, '!', just add it as a token
4383 if (Parser.getTok().is(AsmToken::Exclaim)) {
4384 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4385 Parser.Lex(); // Eat the '!'.
4391 /// parseMemRegOffsetShift - one of these two:
4392 /// ( lsl | lsr | asr | ror ) , # shift_amount
4394 /// return true if it parses a shift otherwise it returns false.
4395 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4397 SMLoc Loc = Parser.getTok().getLoc();
4398 const AsmToken &Tok = Parser.getTok();
4399 if (Tok.isNot(AsmToken::Identifier))
4401 StringRef ShiftName = Tok.getString();
4402 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4403 ShiftName == "asl" || ShiftName == "ASL")
4405 else if (ShiftName == "lsr" || ShiftName == "LSR")
4407 else if (ShiftName == "asr" || ShiftName == "ASR")
4409 else if (ShiftName == "ror" || ShiftName == "ROR")
4411 else if (ShiftName == "rrx" || ShiftName == "RRX")
4414 return Error(Loc, "illegal shift operator");
4415 Parser.Lex(); // Eat shift type token.
4417 // rrx stands alone.
4419 if (St != ARM_AM::rrx) {
4420 Loc = Parser.getTok().getLoc();
4421 // A '#' and a shift amount.
4422 const AsmToken &HashTok = Parser.getTok();
4423 if (HashTok.isNot(AsmToken::Hash) &&
4424 HashTok.isNot(AsmToken::Dollar))
4425 return Error(HashTok.getLoc(), "'#' expected");
4426 Parser.Lex(); // Eat hash token.
4429 if (getParser().parseExpression(Expr))
4431 // Range check the immediate.
4432 // lsl, ror: 0 <= imm <= 31
4433 // lsr, asr: 0 <= imm <= 32
4434 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4436 return Error(Loc, "shift amount must be an immediate");
4437 int64_t Imm = CE->getValue();
4439 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4440 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4441 return Error(Loc, "immediate shift value out of range");
4442 // If <ShiftTy> #0, turn it into a no_shift.
4445 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4454 /// parseFPImm - A floating point immediate expression operand.
4455 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4456 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4457 // Anything that can accept a floating point constant as an operand
4458 // needs to go through here, as the regular parseExpression is
4461 // This routine still creates a generic Immediate operand, containing
4462 // a bitcast of the 64-bit floating point value. The various operands
4463 // that accept floats can check whether the value is valid for them
4464 // via the standard is*() predicates.
4466 SMLoc S = Parser.getTok().getLoc();
4468 if (Parser.getTok().isNot(AsmToken::Hash) &&
4469 Parser.getTok().isNot(AsmToken::Dollar))
4470 return MatchOperand_NoMatch;
4472 // Disambiguate the VMOV forms that can accept an FP immediate.
4473 // vmov.f32 <sreg>, #imm
4474 // vmov.f64 <dreg>, #imm
4475 // vmov.f32 <dreg>, #imm @ vector f32x2
4476 // vmov.f32 <qreg>, #imm @ vector f32x4
4478 // There are also the NEON VMOV instructions which expect an
4479 // integer constant. Make sure we don't try to parse an FPImm
4481 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4482 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4483 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4484 TyOp->getToken() != ".f64"))
4485 return MatchOperand_NoMatch;
4487 Parser.Lex(); // Eat '#' or '$'.
4489 // Handle negation, as that still comes through as a separate token.
4490 bool isNegative = false;
4491 if (Parser.getTok().is(AsmToken::Minus)) {
4495 const AsmToken &Tok = Parser.getTok();
4496 SMLoc Loc = Tok.getLoc();
4497 if (Tok.is(AsmToken::Real)) {
4498 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4499 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4500 // If we had a '-' in front, toggle the sign bit.
4501 IntVal ^= (uint64_t)isNegative << 31;
4502 Parser.Lex(); // Eat the token.
4503 Operands.push_back(ARMOperand::CreateImm(
4504 MCConstantExpr::Create(IntVal, getContext()),
4505 S, Parser.getTok().getLoc()));
4506 return MatchOperand_Success;
4508 // Also handle plain integers. Instructions which allow floating point
4509 // immediates also allow a raw encoded 8-bit value.
4510 if (Tok.is(AsmToken::Integer)) {
4511 int64_t Val = Tok.getIntVal();
4512 Parser.Lex(); // Eat the token.
4513 if (Val > 255 || Val < 0) {
4514 Error(Loc, "encoded floating point value out of range");
4515 return MatchOperand_ParseFail;
4517 double RealVal = ARM_AM::getFPImmFloat(Val);
4518 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4519 Operands.push_back(ARMOperand::CreateImm(
4520 MCConstantExpr::Create(Val, getContext()), S,
4521 Parser.getTok().getLoc()));
4522 return MatchOperand_Success;
4525 Error(Loc, "invalid floating point immediate");
4526 return MatchOperand_ParseFail;
4529 /// Parse a arm instruction operand. For now this parses the operand regardless
4530 /// of the mnemonic.
4531 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4532 StringRef Mnemonic) {
4535 // Check if the current operand has a custom associated parser, if so, try to
4536 // custom parse the operand, or fallback to the general approach.
4537 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4538 if (ResTy == MatchOperand_Success)
4540 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4541 // there was a match, but an error occurred, in which case, just return that
4542 // the operand parsing failed.
4543 if (ResTy == MatchOperand_ParseFail)
4546 switch (getLexer().getKind()) {
4548 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4550 case AsmToken::Identifier: {
4551 // If we've seen a branch mnemonic, the next operand must be a label. This
4552 // is true even if the label is a register name. So "br r1" means branch to
4554 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4556 if (!tryParseRegisterWithWriteBack(Operands))
4558 int Res = tryParseShiftRegister(Operands);
4559 if (Res == 0) // success
4561 else if (Res == -1) // irrecoverable error
4563 // If this is VMRS, check for the apsr_nzcv operand.
4564 if (Mnemonic == "vmrs" &&
4565 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4566 S = Parser.getTok().getLoc();
4568 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4573 // Fall though for the Identifier case that is not a register or a
4576 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4577 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4578 case AsmToken::String: // quoted label names.
4579 case AsmToken::Dot: { // . as a branch target
4580 // This was not a register so parse other operands that start with an
4581 // identifier (like labels) as expressions and create them as immediates.
4582 const MCExpr *IdVal;
4583 S = Parser.getTok().getLoc();
4584 if (getParser().parseExpression(IdVal))
4586 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4587 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4590 case AsmToken::LBrac:
4591 return parseMemory(Operands);
4592 case AsmToken::LCurly:
4593 return parseRegisterList(Operands);
4594 case AsmToken::Dollar:
4595 case AsmToken::Hash: {
4596 // #42 -> immediate.
4597 S = Parser.getTok().getLoc();
4600 if (Parser.getTok().isNot(AsmToken::Colon)) {
4601 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4602 const MCExpr *ImmVal;
4603 if (getParser().parseExpression(ImmVal))
4605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4607 int32_t Val = CE->getValue();
4608 if (isNegative && Val == 0)
4609 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4611 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4612 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4614 // There can be a trailing '!' on operands that we want as a separate
4615 // '!' Token operand. Handle that here. For example, the compatibilty
4616 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4617 if (Parser.getTok().is(AsmToken::Exclaim)) {
4618 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4619 Parser.getTok().getLoc()));
4620 Parser.Lex(); // Eat exclaim token
4624 // w/ a ':' after the '#', it's just like a plain ':'.
4627 case AsmToken::Colon: {
4628 // ":lower16:" and ":upper16:" expression prefixes
4629 // FIXME: Check it's an expression prefix,
4630 // e.g. (FOO - :lower16:BAR) isn't legal.
4631 ARMMCExpr::VariantKind RefKind;
4632 if (parsePrefix(RefKind))
4635 const MCExpr *SubExprVal;
4636 if (getParser().parseExpression(SubExprVal))
4639 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4641 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4642 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4648 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4649 // :lower16: and :upper16:.
4650 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4651 RefKind = ARMMCExpr::VK_ARM_None;
4653 // :lower16: and :upper16: modifiers
4654 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4655 Parser.Lex(); // Eat ':'
4657 if (getLexer().isNot(AsmToken::Identifier)) {
4658 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4662 StringRef IDVal = Parser.getTok().getIdentifier();
4663 if (IDVal == "lower16") {
4664 RefKind = ARMMCExpr::VK_ARM_LO16;
4665 } else if (IDVal == "upper16") {
4666 RefKind = ARMMCExpr::VK_ARM_HI16;
4668 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4673 if (getLexer().isNot(AsmToken::Colon)) {
4674 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4677 Parser.Lex(); // Eat the last ':'
4681 /// \brief Given a mnemonic, split out possible predication code and carry
4682 /// setting letters to form a canonical mnemonic and flags.
4684 // FIXME: Would be nice to autogen this.
4685 // FIXME: This is a bit of a maze of special cases.
4686 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4687 unsigned &PredicationCode,
4689 unsigned &ProcessorIMod,
4690 StringRef &ITMask) {
4691 PredicationCode = ARMCC::AL;
4692 CarrySetting = false;
4695 // Ignore some mnemonics we know aren't predicated forms.
4697 // FIXME: Would be nice to autogen this.
4698 if ((Mnemonic == "movs" && isThumb()) ||
4699 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4700 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4701 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4702 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4703 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
4704 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4705 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4706 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4707 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
4708 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4709 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4710 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
4713 // First, split out any predication code. Ignore mnemonics we know aren't
4714 // predicated but do have a carry-set and so weren't caught above.
4715 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4716 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4717 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4718 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4719 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4720 .Case("eq", ARMCC::EQ)
4721 .Case("ne", ARMCC::NE)
4722 .Case("hs", ARMCC::HS)
4723 .Case("cs", ARMCC::HS)
4724 .Case("lo", ARMCC::LO)
4725 .Case("cc", ARMCC::LO)
4726 .Case("mi", ARMCC::MI)
4727 .Case("pl", ARMCC::PL)
4728 .Case("vs", ARMCC::VS)
4729 .Case("vc", ARMCC::VC)
4730 .Case("hi", ARMCC::HI)
4731 .Case("ls", ARMCC::LS)
4732 .Case("ge", ARMCC::GE)
4733 .Case("lt", ARMCC::LT)
4734 .Case("gt", ARMCC::GT)
4735 .Case("le", ARMCC::LE)
4736 .Case("al", ARMCC::AL)
4739 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4740 PredicationCode = CC;
4744 // Next, determine if we have a carry setting bit. We explicitly ignore all
4745 // the instructions we know end in 's'.
4746 if (Mnemonic.endswith("s") &&
4747 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4748 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4749 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4750 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4751 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4752 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4753 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4754 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4755 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4756 (Mnemonic == "movs" && isThumb()))) {
4757 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4758 CarrySetting = true;
4761 // The "cps" instruction can have a interrupt mode operand which is glued into
4762 // the mnemonic. Check if this is the case, split it and parse the imod op
4763 if (Mnemonic.startswith("cps")) {
4764 // Split out any imod code.
4766 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4767 .Case("ie", ARM_PROC::IE)
4768 .Case("id", ARM_PROC::ID)
4771 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4772 ProcessorIMod = IMod;
4776 // The "it" instruction has the condition mask on the end of the mnemonic.
4777 if (Mnemonic.startswith("it")) {
4778 ITMask = Mnemonic.slice(2, Mnemonic.size());
4779 Mnemonic = Mnemonic.slice(0, 2);
4785 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4786 /// inclusion of carry set or predication code operands.
4788 // FIXME: It would be nice to autogen this.
4790 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4791 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
4792 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4793 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4794 Mnemonic == "add" || Mnemonic == "adc" ||
4795 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4796 Mnemonic == "orr" || Mnemonic == "mvn" ||
4797 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4798 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4799 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4800 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4801 Mnemonic == "mla" || Mnemonic == "smlal" ||
4802 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4803 CanAcceptCarrySet = true;
4805 CanAcceptCarrySet = false;
4807 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4808 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4809 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
4810 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4811 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
4812 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4813 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4814 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4815 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4816 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
4817 // These mnemonics are never predicable
4818 CanAcceptPredicationCode = false;
4819 } else if (!isThumb()) {
4820 // Some instructions are only predicable in Thumb mode
4821 CanAcceptPredicationCode
4822 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4823 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4824 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4825 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4826 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4827 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4828 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4829 } else if (isThumbOne()) {
4831 CanAcceptPredicationCode = Mnemonic != "movs";
4833 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4835 CanAcceptPredicationCode = true;
4838 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4839 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4840 // FIXME: This is all horribly hacky. We really need a better way to deal
4841 // with optional operands like this in the matcher table.
4843 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4844 // another does not. Specifically, the MOVW instruction does not. So we
4845 // special case it here and remove the defaulted (non-setting) cc_out
4846 // operand if that's the instruction we're trying to match.
4848 // We do this as post-processing of the explicit operands rather than just
4849 // conditionally adding the cc_out in the first place because we need
4850 // to check the type of the parsed immediate operand.
4851 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4852 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4853 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4854 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4857 // Register-register 'add' for thumb does not have a cc_out operand
4858 // when there are only two register operands.
4859 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4860 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4861 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4862 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4864 // Register-register 'add' for thumb does not have a cc_out operand
4865 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4866 // have to check the immediate range here since Thumb2 has a variant
4867 // that can handle a different range and has a cc_out operand.
4868 if (((isThumb() && Mnemonic == "add") ||
4869 (isThumbTwo() && Mnemonic == "sub")) &&
4870 Operands.size() == 6 &&
4871 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4872 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4873 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4874 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4875 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4876 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4878 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4879 // imm0_4095 variant. That's the least-preferred variant when
4880 // selecting via the generic "add" mnemonic, so to know that we
4881 // should remove the cc_out operand, we have to explicitly check that
4882 // it's not one of the other variants. Ugh.
4883 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4884 Operands.size() == 6 &&
4885 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4886 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4887 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4888 // Nest conditions rather than one big 'if' statement for readability.
4890 // If both registers are low, we're in an IT block, and the immediate is
4891 // in range, we should use encoding T1 instead, which has a cc_out.
4893 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4894 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4895 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4897 // Check against T3. If the second register is the PC, this is an
4898 // alternate form of ADR, which uses encoding T4, so check for that too.
4899 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4900 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4903 // Otherwise, we use encoding T4, which does not have a cc_out
4908 // The thumb2 multiply instruction doesn't have a CCOut register, so
4909 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4910 // use the 16-bit encoding or not.
4911 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4912 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4913 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4914 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4915 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4916 // If the registers aren't low regs, the destination reg isn't the
4917 // same as one of the source regs, or the cc_out operand is zero
4918 // outside of an IT block, we have to use the 32-bit encoding, so
4919 // remove the cc_out operand.
4920 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4921 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4922 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4924 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4925 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4926 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4927 static_cast<ARMOperand*>(Operands[4])->getReg())))
4930 // Also check the 'mul' syntax variant that doesn't specify an explicit
4931 // destination register.
4932 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4933 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4934 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4935 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4936 // If the registers aren't low regs or the cc_out operand is zero
4937 // outside of an IT block, we have to use the 32-bit encoding, so
4938 // remove the cc_out operand.
4939 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4940 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4946 // Register-register 'add/sub' for thumb does not have a cc_out operand
4947 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4948 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4949 // right, this will result in better diagnostics (which operand is off)
4951 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4952 (Operands.size() == 5 || Operands.size() == 6) &&
4953 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4954 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4955 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4956 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4957 (Operands.size() == 6 &&
4958 static_cast<ARMOperand*>(Operands[5])->isImm())))
4964 bool ARMAsmParser::shouldOmitPredicateOperand(
4965 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4966 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4967 unsigned RegIdx = 3;
4968 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4969 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4970 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4971 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4974 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4975 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4976 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4977 ARMMCRegisterClasses[ARM::QPRRegClassID]
4978 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4984 static bool isDataTypeToken(StringRef Tok) {
4985 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4986 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4987 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4988 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4989 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4990 Tok == ".f" || Tok == ".d";
4993 // FIXME: This bit should probably be handled via an explicit match class
4994 // in the .td files that matches the suffix instead of having it be
4995 // a literal string token the way it is now.
4996 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4997 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4999 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5000 unsigned VariantID);
5001 /// Parse an arm instruction mnemonic followed by its operands.
5002 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5004 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5005 // Apply mnemonic aliases before doing anything else, as the destination
5006 // mnemnonic may include suffices and we want to handle them normally.
5007 // The generic tblgen'erated code does this later, at the start of
5008 // MatchInstructionImpl(), but that's too late for aliases that include
5009 // any sort of suffix.
5010 unsigned AvailableFeatures = getAvailableFeatures();
5011 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5012 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5014 // First check for the ARM-specific .req directive.
5015 if (Parser.getTok().is(AsmToken::Identifier) &&
5016 Parser.getTok().getIdentifier() == ".req") {
5017 parseDirectiveReq(Name, NameLoc);
5018 // We always return 'error' for this, as we're done with this
5019 // statement and don't need to match the 'instruction."
5023 // Create the leading tokens for the mnemonic, split by '.' characters.
5024 size_t Start = 0, Next = Name.find('.');
5025 StringRef Mnemonic = Name.slice(Start, Next);
5027 // Split out the predication code and carry setting flag from the mnemonic.
5028 unsigned PredicationCode;
5029 unsigned ProcessorIMod;
5032 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5033 ProcessorIMod, ITMask);
5035 // In Thumb1, only the branch (B) instruction can be predicated.
5036 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5037 Parser.eatToEndOfStatement();
5038 return Error(NameLoc, "conditional execution not supported in Thumb1");
5041 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5043 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5044 // is the mask as it will be for the IT encoding if the conditional
5045 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5046 // where the conditional bit0 is zero, the instruction post-processing
5047 // will adjust the mask accordingly.
5048 if (Mnemonic == "it") {
5049 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5050 if (ITMask.size() > 3) {
5051 Parser.eatToEndOfStatement();
5052 return Error(Loc, "too many conditions on IT instruction");
5055 for (unsigned i = ITMask.size(); i != 0; --i) {
5056 char pos = ITMask[i - 1];
5057 if (pos != 't' && pos != 'e') {
5058 Parser.eatToEndOfStatement();
5059 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5062 if (ITMask[i - 1] == 't')
5065 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5068 // FIXME: This is all a pretty gross hack. We should automatically handle
5069 // optional operands like this via tblgen.
5071 // Next, add the CCOut and ConditionCode operands, if needed.
5073 // For mnemonics which can ever incorporate a carry setting bit or predication
5074 // code, our matching model involves us always generating CCOut and
5075 // ConditionCode operands to match the mnemonic "as written" and then we let
5076 // the matcher deal with finding the right instruction or generating an
5077 // appropriate error.
5078 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5079 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5081 // If we had a carry-set on an instruction that can't do that, issue an
5083 if (!CanAcceptCarrySet && CarrySetting) {
5084 Parser.eatToEndOfStatement();
5085 return Error(NameLoc, "instruction '" + Mnemonic +
5086 "' can not set flags, but 's' suffix specified");
5088 // If we had a predication code on an instruction that can't do that, issue an
5090 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5091 Parser.eatToEndOfStatement();
5092 return Error(NameLoc, "instruction '" + Mnemonic +
5093 "' is not predicable, but condition code specified");
5096 // Add the carry setting operand, if necessary.
5097 if (CanAcceptCarrySet) {
5098 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5099 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5103 // Add the predication code operand, if necessary.
5104 if (CanAcceptPredicationCode) {
5105 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5107 Operands.push_back(ARMOperand::CreateCondCode(
5108 ARMCC::CondCodes(PredicationCode), Loc));
5111 // Add the processor imod operand, if necessary.
5112 if (ProcessorIMod) {
5113 Operands.push_back(ARMOperand::CreateImm(
5114 MCConstantExpr::Create(ProcessorIMod, getContext()),
5118 // Add the remaining tokens in the mnemonic.
5119 while (Next != StringRef::npos) {
5121 Next = Name.find('.', Start + 1);
5122 StringRef ExtraToken = Name.slice(Start, Next);
5124 // Some NEON instructions have an optional datatype suffix that is
5125 // completely ignored. Check for that.
5126 if (isDataTypeToken(ExtraToken) &&
5127 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5130 // For for ARM mode generate an error if the .n qualifier is used.
5131 if (ExtraToken == ".n" && !isThumb()) {
5132 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5133 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5137 // The .n qualifier is always discarded as that is what the tables
5138 // and matcher expect. In ARM mode the .w qualifier has no effect,
5139 // so discard it to avoid errors that can be caused by the matcher.
5140 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5141 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5142 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5146 // Read the remaining operands.
5147 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5148 // Read the first operand.
5149 if (parseOperand(Operands, Mnemonic)) {
5150 Parser.eatToEndOfStatement();
5154 while (getLexer().is(AsmToken::Comma)) {
5155 Parser.Lex(); // Eat the comma.
5157 // Parse and remember the operand.
5158 if (parseOperand(Operands, Mnemonic)) {
5159 Parser.eatToEndOfStatement();
5165 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5166 SMLoc Loc = getLexer().getLoc();
5167 Parser.eatToEndOfStatement();
5168 return Error(Loc, "unexpected token in argument list");
5171 Parser.Lex(); // Consume the EndOfStatement
5173 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5174 // do and don't have a cc_out optional-def operand. With some spot-checks
5175 // of the operand list, we can figure out which variant we're trying to
5176 // parse and adjust accordingly before actually matching. We shouldn't ever
5177 // try to remove a cc_out operand that was explicitly set on the the
5178 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5179 // table driven matcher doesn't fit well with the ARM instruction set.
5180 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5181 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5182 Operands.erase(Operands.begin() + 1);
5186 // Some instructions have the same mnemonic, but don't always
5187 // have a predicate. Distinguish them here and delete the
5188 // predicate if needed.
5189 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5190 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5191 Operands.erase(Operands.begin() + 1);
5195 // ARM mode 'blx' need special handling, as the register operand version
5196 // is predicable, but the label operand version is not. So, we can't rely
5197 // on the Mnemonic based checking to correctly figure out when to put
5198 // a k_CondCode operand in the list. If we're trying to match the label
5199 // version, remove the k_CondCode operand here.
5200 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5201 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5202 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5203 Operands.erase(Operands.begin() + 1);
5207 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5208 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5209 // a single GPRPair reg operand is used in the .td file to replace the two
5210 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5211 // expressed as a GPRPair, so we have to manually merge them.
5212 // FIXME: We would really like to be able to tablegen'erate this.
5213 if (!isThumb() && Operands.size() > 4 &&
5214 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5215 Mnemonic == "stlexd")) {
5216 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5217 unsigned Idx = isLoad ? 2 : 3;
5218 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5219 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5221 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5222 // Adjust only if Op1 and Op2 are GPRs.
5223 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5224 MRC.contains(Op2->getReg())) {
5225 unsigned Reg1 = Op1->getReg();
5226 unsigned Reg2 = Op2->getReg();
5227 unsigned Rt = MRI->getEncodingValue(Reg1);
5228 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5230 // Rt2 must be Rt + 1 and Rt must be even.
5231 if (Rt + 1 != Rt2 || (Rt & 1)) {
5232 Error(Op2->getStartLoc(), isLoad ?
5233 "destination operands must be sequential" :
5234 "source operands must be sequential");
5237 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5238 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5239 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5240 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5241 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5247 // FIXME: As said above, this is all a pretty gross hack. This instruction
5248 // does not fit with other "subs" and tblgen.
5249 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5250 // so the Mnemonic is the original name "subs" and delete the predicate
5251 // operand so it will match the table entry.
5252 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5253 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5254 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5255 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5256 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5257 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5258 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5259 Operands.erase(Operands.begin());
5261 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5263 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5264 Operands.erase(Operands.begin() + 1);
5270 // Validate context-sensitive operand constraints.
5272 // return 'true' if register list contains non-low GPR registers,
5273 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5274 // 'containsReg' to true.
5275 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5276 unsigned HiReg, bool &containsReg) {
5277 containsReg = false;
5278 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5279 unsigned OpReg = Inst.getOperand(i).getReg();
5282 // Anything other than a low register isn't legal here.
5283 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5289 // Check if the specified regisgter is in the register list of the inst,
5290 // starting at the indicated operand number.
5291 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5292 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5293 unsigned OpReg = Inst.getOperand(i).getReg();
5300 // Return true if instruction has the interesting property of being
5301 // allowed in IT blocks, but not being predicable.
5302 static bool instIsBreakpoint(const MCInst &Inst) {
5303 return Inst.getOpcode() == ARM::tBKPT ||
5304 Inst.getOpcode() == ARM::BKPT ||
5305 Inst.getOpcode() == ARM::tHLT ||
5306 Inst.getOpcode() == ARM::HLT;
5310 // FIXME: We would really like to be able to tablegen'erate this.
5312 validateInstruction(MCInst &Inst,
5313 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5314 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
5315 SMLoc Loc = Operands[0]->getStartLoc();
5317 // Check the IT block state first.
5318 // NOTE: BKPT and HLT instructions have the interesting property of being
5319 // allowed in IT blocks, but not being predicable. They just always execute.
5320 if (inITBlock() && !instIsBreakpoint(Inst)) {
5322 if (ITState.FirstCond)
5323 ITState.FirstCond = false;
5325 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5326 // The instruction must be predicable.
5327 if (!MCID.isPredicable())
5328 return Error(Loc, "instructions in IT block must be predicable");
5329 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5330 unsigned ITCond = Bit ? ITState.Cond :
5331 ARMCC::getOppositeCondition(ITState.Cond);
5332 if (Cond != ITCond) {
5333 // Find the condition code Operand to get its SMLoc information.
5335 for (unsigned I = 1; I < Operands.size(); ++I)
5336 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5337 CondLoc = Operands[I]->getStartLoc();
5338 return Error(CondLoc, "incorrect condition in IT block; got '" +
5339 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5340 "', but expected '" +
5341 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5343 // Check for non-'al' condition codes outside of the IT block.
5344 } else if (isThumbTwo() && MCID.isPredicable() &&
5345 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5346 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5347 Inst.getOpcode() != ARM::t2Bcc)
5348 return Error(Loc, "predicated instructions must be in IT block");
5350 const unsigned Opcode = Inst.getOpcode();
5354 case ARM::LDRD_POST: {
5355 const unsigned RtReg = Inst.getOperand(0).getReg();
5358 if (RtReg == ARM::LR)
5359 return Error(Operands[3]->getStartLoc(),
5362 const unsigned Rt = MRI->getEncodingValue(RtReg);
5363 // Rt must be even-numbered.
5365 return Error(Operands[3]->getStartLoc(),
5366 "Rt must be even-numbered");
5368 // Rt2 must be Rt + 1.
5369 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5371 return Error(Operands[3]->getStartLoc(),
5372 "destination operands must be sequential");
5374 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5375 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5376 // For addressing modes with writeback, the base register needs to be
5377 // different from the destination registers.
5378 if (Rn == Rt || Rn == Rt2)
5379 return Error(Operands[3]->getStartLoc(),
5380 "base register needs to be different from destination "
5387 case ARM::t2LDRD_PRE:
5388 case ARM::t2LDRD_POST: {
5389 // Rt2 must be different from Rt.
5390 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5391 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5393 return Error(Operands[3]->getStartLoc(),
5394 "destination operands can't be identical");
5398 // Rt2 must be Rt + 1.
5399 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5400 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5402 return Error(Operands[3]->getStartLoc(),
5403 "source operands must be sequential");
5407 case ARM::STRD_POST: {
5408 // Rt2 must be Rt + 1.
5409 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5410 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5412 return Error(Operands[3]->getStartLoc(),
5413 "source operands must be sequential");
5418 // Width must be in range [1, 32-lsb].
5419 unsigned LSB = Inst.getOperand(2).getImm();
5420 unsigned Widthm1 = Inst.getOperand(3).getImm();
5421 if (Widthm1 >= 32 - LSB)
5422 return Error(Operands[5]->getStartLoc(),
5423 "bitfield width must be in range [1,32-lsb]");
5426 // Notionally handles ARM::tLDMIA_UPD too.
5428 // If we're parsing Thumb2, the .w variant is available and handles
5429 // most cases that are normally illegal for a Thumb1 LDM instruction.
5430 // We'll make the transformation in processInstruction() if necessary.
5432 // Thumb LDM instructions are writeback iff the base register is not
5433 // in the register list.
5434 unsigned Rn = Inst.getOperand(0).getReg();
5435 bool HasWritebackToken =
5436 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5437 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5438 bool ListContainsBase;
5439 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5440 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
5441 "registers must be in range r0-r7");
5442 // If we should have writeback, then there should be a '!' token.
5443 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
5444 return Error(Operands[2]->getStartLoc(),
5445 "writeback operator '!' expected");
5446 // If we should not have writeback, there must not be a '!'. This is
5447 // true even for the 32-bit wide encodings.
5448 if (ListContainsBase && HasWritebackToken)
5449 return Error(Operands[3]->getStartLoc(),
5450 "writeback operator '!' not allowed when base register "
5451 "in register list");
5455 case ARM::LDMIA_UPD:
5456 case ARM::LDMDB_UPD:
5457 case ARM::LDMIB_UPD:
5458 case ARM::LDMDA_UPD:
5459 // ARM variants loading and updating the same register are only officially
5460 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5464 case ARM::t2LDMIA_UPD:
5465 case ARM::t2LDMDB_UPD:
5466 case ARM::t2STMIA_UPD:
5467 case ARM::t2STMDB_UPD: {
5468 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5469 return Error(Operands[4]->getStartLoc(),
5470 "writeback operator '!' not allowed when base register "
5471 "in register list");
5475 // The second source operand must be the same register as the destination
5478 // In this case, we must directly check the parsed operands because the
5479 // cvtThumbMultiply() function is written in such a way that it guarantees
5480 // this first statement is always true for the new Inst. Essentially, the
5481 // destination is unconditionally copied into the second source operand
5482 // without checking to see if it matches what we actually parsed.
5483 if (Operands.size() == 6 &&
5484 (((ARMOperand*)Operands[3])->getReg() !=
5485 ((ARMOperand*)Operands[5])->getReg()) &&
5486 (((ARMOperand*)Operands[3])->getReg() !=
5487 ((ARMOperand*)Operands[4])->getReg())) {
5488 return Error(Operands[3]->getStartLoc(),
5489 "destination register must match source register");
5493 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5494 // so only issue a diagnostic for thumb1. The instructions will be
5495 // switched to the t2 encodings in processInstruction() if necessary.
5497 bool ListContainsBase;
5498 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
5500 return Error(Operands[2]->getStartLoc(),
5501 "registers must be in range r0-r7 or pc");
5505 bool ListContainsBase;
5506 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
5508 return Error(Operands[2]->getStartLoc(),
5509 "registers must be in range r0-r7 or lr");
5512 case ARM::tSTMIA_UPD: {
5513 bool ListContainsBase, InvalidLowList;
5514 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5515 0, ListContainsBase);
5516 if (InvalidLowList && !isThumbTwo())
5517 return Error(Operands[4]->getStartLoc(),
5518 "registers must be in range r0-r7");
5520 // This would be converted to a 32-bit stm, but that's not valid if the
5521 // writeback register is in the list.
5522 if (InvalidLowList && ListContainsBase)
5523 return Error(Operands[4]->getStartLoc(),
5524 "writeback operator '!' not allowed when base register "
5525 "in register list");
5528 case ARM::tADDrSP: {
5529 // If the non-SP source operand and the destination operand are not the
5530 // same, we need thumb2 (for the wide encoding), or we have an error.
5531 if (!isThumbTwo() &&
5532 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5533 return Error(Operands[4]->getStartLoc(),
5534 "source register must be the same as destination");
5538 // Final range checking for Thumb unconditional branch instructions.
5540 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5541 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5544 int op = (Operands[2]->isImm()) ? 2 : 3;
5545 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5546 return Error(Operands[op]->getStartLoc(), "branch target out of range");
5549 // Final range checking for Thumb conditional branch instructions.
5551 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5552 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5555 int Op = (Operands[2]->isImm()) ? 2 : 3;
5556 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5557 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
5565 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5567 default: llvm_unreachable("unexpected opcode!");
5569 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5570 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5571 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5572 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5573 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5574 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5575 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5576 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5577 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5580 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5581 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5582 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5583 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5584 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5586 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5587 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5588 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5589 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5590 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5592 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5593 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5594 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5595 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5596 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5599 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5600 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5601 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5602 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5603 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5604 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5605 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5606 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5607 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5608 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5609 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5610 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5611 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5612 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5613 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5616 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5617 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5618 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5619 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5620 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5621 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5622 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5623 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5624 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5625 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5626 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5627 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5628 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5629 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5630 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5631 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5632 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5633 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5636 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5637 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5638 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5639 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5640 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5641 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5642 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5643 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5644 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5645 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5646 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5647 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5648 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5649 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5650 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5653 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5654 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5655 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5656 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5657 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5658 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5659 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5660 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5661 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5662 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5663 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5664 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5665 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5666 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5667 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5668 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5669 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5670 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5674 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5676 default: llvm_unreachable("unexpected opcode!");
5678 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5679 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5680 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5681 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5682 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5683 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5684 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5685 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5686 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5689 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5690 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5691 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5692 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5693 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5694 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5695 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5696 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5697 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5698 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5699 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5700 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5701 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5702 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5703 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5706 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5707 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5708 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5709 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5710 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5711 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5712 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5713 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5714 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5715 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5716 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5717 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5718 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5719 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5720 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5721 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5722 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5723 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5726 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5727 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5728 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5729 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5730 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5731 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5732 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5733 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5734 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5735 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5736 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5737 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5738 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5739 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5740 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5743 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5744 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5745 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5746 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5747 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5748 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5749 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5750 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5751 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5752 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5753 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5754 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5755 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5756 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5757 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5758 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5759 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5760 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5763 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5764 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5765 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5766 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5767 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5768 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5769 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5770 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5771 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5772 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5773 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5774 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5775 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5776 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5777 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5780 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5781 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5782 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5783 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5784 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5785 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5786 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5787 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5788 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5789 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5790 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5791 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5792 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5793 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5794 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5795 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5796 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5797 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5800 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5801 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5802 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5803 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5804 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5805 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5806 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5807 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5808 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5809 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5810 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5811 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5812 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5813 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5814 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5815 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5816 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5817 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5822 processInstruction(MCInst &Inst,
5823 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5824 switch (Inst.getOpcode()) {
5825 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5827 if (Inst.getOperand(1).getReg() != ARM::PC ||
5828 Inst.getOperand(5).getReg() != 0)
5831 TmpInst.setOpcode(ARM::ADR);
5832 TmpInst.addOperand(Inst.getOperand(0));
5833 TmpInst.addOperand(Inst.getOperand(2));
5834 TmpInst.addOperand(Inst.getOperand(3));
5835 TmpInst.addOperand(Inst.getOperand(4));
5839 // Aliases for alternate PC+imm syntax of LDR instructions.
5840 case ARM::t2LDRpcrel:
5841 // Select the narrow version if the immediate will fit.
5842 if (Inst.getOperand(1).getImm() > 0 &&
5843 Inst.getOperand(1).getImm() <= 0xff &&
5844 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5845 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
5846 Inst.setOpcode(ARM::tLDRpci);
5848 Inst.setOpcode(ARM::t2LDRpci);
5850 case ARM::t2LDRBpcrel:
5851 Inst.setOpcode(ARM::t2LDRBpci);
5853 case ARM::t2LDRHpcrel:
5854 Inst.setOpcode(ARM::t2LDRHpci);
5856 case ARM::t2LDRSBpcrel:
5857 Inst.setOpcode(ARM::t2LDRSBpci);
5859 case ARM::t2LDRSHpcrel:
5860 Inst.setOpcode(ARM::t2LDRSHpci);
5862 // Handle NEON VST complex aliases.
5863 case ARM::VST1LNdWB_register_Asm_8:
5864 case ARM::VST1LNdWB_register_Asm_16:
5865 case ARM::VST1LNdWB_register_Asm_32: {
5867 // Shuffle the operands around so the lane index operand is in the
5870 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5871 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5872 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5873 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5874 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5875 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5876 TmpInst.addOperand(Inst.getOperand(1)); // lane
5877 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5878 TmpInst.addOperand(Inst.getOperand(6));
5883 case ARM::VST2LNdWB_register_Asm_8:
5884 case ARM::VST2LNdWB_register_Asm_16:
5885 case ARM::VST2LNdWB_register_Asm_32:
5886 case ARM::VST2LNqWB_register_Asm_16:
5887 case ARM::VST2LNqWB_register_Asm_32: {
5889 // Shuffle the operands around so the lane index operand is in the
5892 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5893 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5894 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5895 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5896 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5897 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5898 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5900 TmpInst.addOperand(Inst.getOperand(1)); // lane
5901 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5902 TmpInst.addOperand(Inst.getOperand(6));
5907 case ARM::VST3LNdWB_register_Asm_8:
5908 case ARM::VST3LNdWB_register_Asm_16:
5909 case ARM::VST3LNdWB_register_Asm_32:
5910 case ARM::VST3LNqWB_register_Asm_16:
5911 case ARM::VST3LNqWB_register_Asm_32: {
5913 // Shuffle the operands around so the lane index operand is in the
5916 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5917 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5918 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5919 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5920 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5921 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5922 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5924 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5926 TmpInst.addOperand(Inst.getOperand(1)); // lane
5927 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5928 TmpInst.addOperand(Inst.getOperand(6));
5933 case ARM::VST4LNdWB_register_Asm_8:
5934 case ARM::VST4LNdWB_register_Asm_16:
5935 case ARM::VST4LNdWB_register_Asm_32:
5936 case ARM::VST4LNqWB_register_Asm_16:
5937 case ARM::VST4LNqWB_register_Asm_32: {
5939 // Shuffle the operands around so the lane index operand is in the
5942 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5943 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5944 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5945 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5946 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5947 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5948 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5950 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5952 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5954 TmpInst.addOperand(Inst.getOperand(1)); // lane
5955 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5956 TmpInst.addOperand(Inst.getOperand(6));
5961 case ARM::VST1LNdWB_fixed_Asm_8:
5962 case ARM::VST1LNdWB_fixed_Asm_16:
5963 case ARM::VST1LNdWB_fixed_Asm_32: {
5965 // Shuffle the operands around so the lane index operand is in the
5968 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5969 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5970 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5971 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5972 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5973 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5974 TmpInst.addOperand(Inst.getOperand(1)); // lane
5975 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5976 TmpInst.addOperand(Inst.getOperand(5));
5981 case ARM::VST2LNdWB_fixed_Asm_8:
5982 case ARM::VST2LNdWB_fixed_Asm_16:
5983 case ARM::VST2LNdWB_fixed_Asm_32:
5984 case ARM::VST2LNqWB_fixed_Asm_16:
5985 case ARM::VST2LNqWB_fixed_Asm_32: {
5987 // Shuffle the operands around so the lane index operand is in the
5990 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5991 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5992 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5993 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5994 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5995 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5996 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5998 TmpInst.addOperand(Inst.getOperand(1)); // lane
5999 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6000 TmpInst.addOperand(Inst.getOperand(5));
6005 case ARM::VST3LNdWB_fixed_Asm_8:
6006 case ARM::VST3LNdWB_fixed_Asm_16:
6007 case ARM::VST3LNdWB_fixed_Asm_32:
6008 case ARM::VST3LNqWB_fixed_Asm_16:
6009 case ARM::VST3LNqWB_fixed_Asm_32: {
6011 // Shuffle the operands around so the lane index operand is in the
6014 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6015 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6016 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6017 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6018 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6019 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6020 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6022 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6024 TmpInst.addOperand(Inst.getOperand(1)); // lane
6025 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6026 TmpInst.addOperand(Inst.getOperand(5));
6031 case ARM::VST4LNdWB_fixed_Asm_8:
6032 case ARM::VST4LNdWB_fixed_Asm_16:
6033 case ARM::VST4LNdWB_fixed_Asm_32:
6034 case ARM::VST4LNqWB_fixed_Asm_16:
6035 case ARM::VST4LNqWB_fixed_Asm_32: {
6037 // Shuffle the operands around so the lane index operand is in the
6040 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6041 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6042 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6043 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6044 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6045 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6046 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6048 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
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::VST1LNdAsm_8:
6060 case ARM::VST1LNdAsm_16:
6061 case ARM::VST1LNdAsm_32: {
6063 // Shuffle the operands around so the lane index operand is in the
6066 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6067 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6068 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6069 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6070 TmpInst.addOperand(Inst.getOperand(1)); // lane
6071 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6072 TmpInst.addOperand(Inst.getOperand(5));
6077 case ARM::VST2LNdAsm_8:
6078 case ARM::VST2LNdAsm_16:
6079 case ARM::VST2LNdAsm_32:
6080 case ARM::VST2LNqAsm_16:
6081 case ARM::VST2LNqAsm_32: {
6083 // Shuffle the operands around so the lane index operand is in the
6086 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6087 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6088 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6089 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6090 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6092 TmpInst.addOperand(Inst.getOperand(1)); // lane
6093 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6094 TmpInst.addOperand(Inst.getOperand(5));
6099 case ARM::VST3LNdAsm_8:
6100 case ARM::VST3LNdAsm_16:
6101 case ARM::VST3LNdAsm_32:
6102 case ARM::VST3LNqAsm_16:
6103 case ARM::VST3LNqAsm_32: {
6105 // Shuffle the operands around so the lane index operand is in the
6108 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6109 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6110 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6111 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6112 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6114 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6116 TmpInst.addOperand(Inst.getOperand(1)); // lane
6117 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6118 TmpInst.addOperand(Inst.getOperand(5));
6123 case ARM::VST4LNdAsm_8:
6124 case ARM::VST4LNdAsm_16:
6125 case ARM::VST4LNdAsm_32:
6126 case ARM::VST4LNqAsm_16:
6127 case ARM::VST4LNqAsm_32: {
6129 // Shuffle the operands around so the lane index operand is in the
6132 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6133 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6134 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6135 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6136 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6138 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6140 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6142 TmpInst.addOperand(Inst.getOperand(1)); // lane
6143 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6144 TmpInst.addOperand(Inst.getOperand(5));
6149 // Handle NEON VLD complex aliases.
6150 case ARM::VLD1LNdWB_register_Asm_8:
6151 case ARM::VLD1LNdWB_register_Asm_16:
6152 case ARM::VLD1LNdWB_register_Asm_32: {
6154 // Shuffle the operands around so the lane index operand is in the
6157 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6158 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6159 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6160 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6161 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6162 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6163 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6164 TmpInst.addOperand(Inst.getOperand(1)); // lane
6165 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6166 TmpInst.addOperand(Inst.getOperand(6));
6171 case ARM::VLD2LNdWB_register_Asm_8:
6172 case ARM::VLD2LNdWB_register_Asm_16:
6173 case ARM::VLD2LNdWB_register_Asm_32:
6174 case ARM::VLD2LNqWB_register_Asm_16:
6175 case ARM::VLD2LNqWB_register_Asm_32: {
6177 // Shuffle the operands around so the lane index operand is in the
6180 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6181 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6182 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6184 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6185 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6186 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6187 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6188 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6191 TmpInst.addOperand(Inst.getOperand(1)); // lane
6192 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6193 TmpInst.addOperand(Inst.getOperand(6));
6198 case ARM::VLD3LNdWB_register_Asm_8:
6199 case ARM::VLD3LNdWB_register_Asm_16:
6200 case ARM::VLD3LNdWB_register_Asm_32:
6201 case ARM::VLD3LNqWB_register_Asm_16:
6202 case ARM::VLD3LNqWB_register_Asm_32: {
6204 // Shuffle the operands around so the lane index operand is in the
6207 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6208 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6209 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6211 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6213 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6214 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6215 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6216 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6217 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6218 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6220 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6222 TmpInst.addOperand(Inst.getOperand(1)); // lane
6223 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6224 TmpInst.addOperand(Inst.getOperand(6));
6229 case ARM::VLD4LNdWB_register_Asm_8:
6230 case ARM::VLD4LNdWB_register_Asm_16:
6231 case ARM::VLD4LNdWB_register_Asm_32:
6232 case ARM::VLD4LNqWB_register_Asm_16:
6233 case ARM::VLD4LNqWB_register_Asm_32: {
6235 // Shuffle the operands around so the lane index operand is in the
6238 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6239 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6240 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6242 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6244 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6246 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6247 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6248 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6249 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6250 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6251 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6253 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6255 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6257 TmpInst.addOperand(Inst.getOperand(1)); // lane
6258 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6259 TmpInst.addOperand(Inst.getOperand(6));
6264 case ARM::VLD1LNdWB_fixed_Asm_8:
6265 case ARM::VLD1LNdWB_fixed_Asm_16:
6266 case ARM::VLD1LNdWB_fixed_Asm_32: {
6268 // Shuffle the operands around so the lane index operand is in the
6271 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6272 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6273 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6274 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6275 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6276 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6277 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6278 TmpInst.addOperand(Inst.getOperand(1)); // lane
6279 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6280 TmpInst.addOperand(Inst.getOperand(5));
6285 case ARM::VLD2LNdWB_fixed_Asm_8:
6286 case ARM::VLD2LNdWB_fixed_Asm_16:
6287 case ARM::VLD2LNdWB_fixed_Asm_32:
6288 case ARM::VLD2LNqWB_fixed_Asm_16:
6289 case ARM::VLD2LNqWB_fixed_Asm_32: {
6291 // Shuffle the operands around so the lane index operand is in the
6294 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6295 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6298 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6299 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6300 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6301 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6302 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6303 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6305 TmpInst.addOperand(Inst.getOperand(1)); // lane
6306 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6307 TmpInst.addOperand(Inst.getOperand(5));
6312 case ARM::VLD3LNdWB_fixed_Asm_8:
6313 case ARM::VLD3LNdWB_fixed_Asm_16:
6314 case ARM::VLD3LNdWB_fixed_Asm_32:
6315 case ARM::VLD3LNqWB_fixed_Asm_16:
6316 case ARM::VLD3LNqWB_fixed_Asm_32: {
6318 // Shuffle the operands around so the lane index operand is in the
6321 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6322 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6323 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6325 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6327 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6328 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6329 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6330 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6331 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6332 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6334 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6336 TmpInst.addOperand(Inst.getOperand(1)); // lane
6337 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6338 TmpInst.addOperand(Inst.getOperand(5));
6343 case ARM::VLD4LNdWB_fixed_Asm_8:
6344 case ARM::VLD4LNdWB_fixed_Asm_16:
6345 case ARM::VLD4LNdWB_fixed_Asm_32:
6346 case ARM::VLD4LNqWB_fixed_Asm_16:
6347 case ARM::VLD4LNqWB_fixed_Asm_32: {
6349 // Shuffle the operands around so the lane index operand is in the
6352 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6353 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6354 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6356 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6360 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6361 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6362 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6363 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6364 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6365 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6367 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6369 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6371 TmpInst.addOperand(Inst.getOperand(1)); // lane
6372 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6373 TmpInst.addOperand(Inst.getOperand(5));
6378 case ARM::VLD1LNdAsm_8:
6379 case ARM::VLD1LNdAsm_16:
6380 case ARM::VLD1LNdAsm_32: {
6382 // Shuffle the operands around so the lane index operand is in the
6385 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6386 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6387 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6388 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6389 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6390 TmpInst.addOperand(Inst.getOperand(1)); // lane
6391 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6392 TmpInst.addOperand(Inst.getOperand(5));
6397 case ARM::VLD2LNdAsm_8:
6398 case ARM::VLD2LNdAsm_16:
6399 case ARM::VLD2LNdAsm_32:
6400 case ARM::VLD2LNqAsm_16:
6401 case ARM::VLD2LNqAsm_32: {
6403 // Shuffle the operands around so the lane index operand is in the
6406 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6407 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6408 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6410 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6411 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6412 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6413 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6415 TmpInst.addOperand(Inst.getOperand(1)); // lane
6416 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6417 TmpInst.addOperand(Inst.getOperand(5));
6422 case ARM::VLD3LNdAsm_8:
6423 case ARM::VLD3LNdAsm_16:
6424 case ARM::VLD3LNdAsm_32:
6425 case ARM::VLD3LNqAsm_16:
6426 case ARM::VLD3LNqAsm_32: {
6428 // Shuffle the operands around so the lane index operand is in the
6431 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6432 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6433 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6435 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6437 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6438 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6439 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6440 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6442 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6444 TmpInst.addOperand(Inst.getOperand(1)); // lane
6445 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6446 TmpInst.addOperand(Inst.getOperand(5));
6451 case ARM::VLD4LNdAsm_8:
6452 case ARM::VLD4LNdAsm_16:
6453 case ARM::VLD4LNdAsm_32:
6454 case ARM::VLD4LNqAsm_16:
6455 case ARM::VLD4LNqAsm_32: {
6457 // Shuffle the operands around so the lane index operand is in the
6460 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6461 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6462 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6464 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6466 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6468 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6469 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6470 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6477 TmpInst.addOperand(Inst.getOperand(1)); // lane
6478 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6479 TmpInst.addOperand(Inst.getOperand(5));
6484 // VLD3DUP single 3-element structure to all lanes instructions.
6485 case ARM::VLD3DUPdAsm_8:
6486 case ARM::VLD3DUPdAsm_16:
6487 case ARM::VLD3DUPdAsm_32:
6488 case ARM::VLD3DUPqAsm_8:
6489 case ARM::VLD3DUPqAsm_16:
6490 case ARM::VLD3DUPqAsm_32: {
6493 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6494 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6499 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6500 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6501 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6502 TmpInst.addOperand(Inst.getOperand(4));
6507 case ARM::VLD3DUPdWB_fixed_Asm_8:
6508 case ARM::VLD3DUPdWB_fixed_Asm_16:
6509 case ARM::VLD3DUPdWB_fixed_Asm_32:
6510 case ARM::VLD3DUPqWB_fixed_Asm_8:
6511 case ARM::VLD3DUPqWB_fixed_Asm_16:
6512 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6515 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6516 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6517 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6519 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6521 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6522 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6523 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6524 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6525 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6526 TmpInst.addOperand(Inst.getOperand(4));
6531 case ARM::VLD3DUPdWB_register_Asm_8:
6532 case ARM::VLD3DUPdWB_register_Asm_16:
6533 case ARM::VLD3DUPdWB_register_Asm_32:
6534 case ARM::VLD3DUPqWB_register_Asm_8:
6535 case ARM::VLD3DUPqWB_register_Asm_16:
6536 case ARM::VLD3DUPqWB_register_Asm_32: {
6539 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6540 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6541 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6543 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6545 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6546 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6547 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6548 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6549 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6550 TmpInst.addOperand(Inst.getOperand(5));
6555 // VLD3 multiple 3-element structure instructions.
6556 case ARM::VLD3dAsm_8:
6557 case ARM::VLD3dAsm_16:
6558 case ARM::VLD3dAsm_32:
6559 case ARM::VLD3qAsm_8:
6560 case ARM::VLD3qAsm_16:
6561 case ARM::VLD3qAsm_32: {
6564 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6565 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6566 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6568 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6570 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6571 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6572 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6573 TmpInst.addOperand(Inst.getOperand(4));
6578 case ARM::VLD3dWB_fixed_Asm_8:
6579 case ARM::VLD3dWB_fixed_Asm_16:
6580 case ARM::VLD3dWB_fixed_Asm_32:
6581 case ARM::VLD3qWB_fixed_Asm_8:
6582 case ARM::VLD3qWB_fixed_Asm_16:
6583 case ARM::VLD3qWB_fixed_Asm_32: {
6586 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6587 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6588 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6590 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6592 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6593 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6594 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6595 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6596 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6597 TmpInst.addOperand(Inst.getOperand(4));
6602 case ARM::VLD3dWB_register_Asm_8:
6603 case ARM::VLD3dWB_register_Asm_16:
6604 case ARM::VLD3dWB_register_Asm_32:
6605 case ARM::VLD3qWB_register_Asm_8:
6606 case ARM::VLD3qWB_register_Asm_16:
6607 case ARM::VLD3qWB_register_Asm_32: {
6610 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6611 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6612 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6614 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6616 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6617 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6618 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6619 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6620 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6621 TmpInst.addOperand(Inst.getOperand(5));
6626 // VLD4DUP single 3-element structure to all lanes instructions.
6627 case ARM::VLD4DUPdAsm_8:
6628 case ARM::VLD4DUPdAsm_16:
6629 case ARM::VLD4DUPdAsm_32:
6630 case ARM::VLD4DUPqAsm_8:
6631 case ARM::VLD4DUPqAsm_16:
6632 case ARM::VLD4DUPqAsm_32: {
6635 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6636 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6637 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6639 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6643 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6644 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6645 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6646 TmpInst.addOperand(Inst.getOperand(4));
6651 case ARM::VLD4DUPdWB_fixed_Asm_8:
6652 case ARM::VLD4DUPdWB_fixed_Asm_16:
6653 case ARM::VLD4DUPdWB_fixed_Asm_32:
6654 case ARM::VLD4DUPqWB_fixed_Asm_8:
6655 case ARM::VLD4DUPqWB_fixed_Asm_16:
6656 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6659 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6660 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6661 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6663 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6665 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6667 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6668 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6669 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6670 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6671 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6672 TmpInst.addOperand(Inst.getOperand(4));
6677 case ARM::VLD4DUPdWB_register_Asm_8:
6678 case ARM::VLD4DUPdWB_register_Asm_16:
6679 case ARM::VLD4DUPdWB_register_Asm_32:
6680 case ARM::VLD4DUPqWB_register_Asm_8:
6681 case ARM::VLD4DUPqWB_register_Asm_16:
6682 case ARM::VLD4DUPqWB_register_Asm_32: {
6685 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6686 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6687 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6689 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6691 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6693 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6694 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6695 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6696 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6697 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6698 TmpInst.addOperand(Inst.getOperand(5));
6703 // VLD4 multiple 4-element structure instructions.
6704 case ARM::VLD4dAsm_8:
6705 case ARM::VLD4dAsm_16:
6706 case ARM::VLD4dAsm_32:
6707 case ARM::VLD4qAsm_8:
6708 case ARM::VLD4qAsm_16:
6709 case ARM::VLD4qAsm_32: {
6712 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6713 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6714 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6716 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6718 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6720 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6721 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6722 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6723 TmpInst.addOperand(Inst.getOperand(4));
6728 case ARM::VLD4dWB_fixed_Asm_8:
6729 case ARM::VLD4dWB_fixed_Asm_16:
6730 case ARM::VLD4dWB_fixed_Asm_32:
6731 case ARM::VLD4qWB_fixed_Asm_8:
6732 case ARM::VLD4qWB_fixed_Asm_16:
6733 case ARM::VLD4qWB_fixed_Asm_32: {
6736 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6737 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6738 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6740 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6742 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6744 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6745 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6746 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6747 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6748 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6749 TmpInst.addOperand(Inst.getOperand(4));
6754 case ARM::VLD4dWB_register_Asm_8:
6755 case ARM::VLD4dWB_register_Asm_16:
6756 case ARM::VLD4dWB_register_Asm_32:
6757 case ARM::VLD4qWB_register_Asm_8:
6758 case ARM::VLD4qWB_register_Asm_16:
6759 case ARM::VLD4qWB_register_Asm_32: {
6762 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6763 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6764 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6766 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6768 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6770 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6771 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6772 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6773 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6774 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6775 TmpInst.addOperand(Inst.getOperand(5));
6780 // VST3 multiple 3-element structure instructions.
6781 case ARM::VST3dAsm_8:
6782 case ARM::VST3dAsm_16:
6783 case ARM::VST3dAsm_32:
6784 case ARM::VST3qAsm_8:
6785 case ARM::VST3qAsm_16:
6786 case ARM::VST3qAsm_32: {
6789 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6790 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6791 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6792 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6793 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6795 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6797 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6798 TmpInst.addOperand(Inst.getOperand(4));
6803 case ARM::VST3dWB_fixed_Asm_8:
6804 case ARM::VST3dWB_fixed_Asm_16:
6805 case ARM::VST3dWB_fixed_Asm_32:
6806 case ARM::VST3qWB_fixed_Asm_8:
6807 case ARM::VST3qWB_fixed_Asm_16:
6808 case ARM::VST3qWB_fixed_Asm_32: {
6811 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6812 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6813 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6814 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6815 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6816 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6817 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6819 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6821 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6822 TmpInst.addOperand(Inst.getOperand(4));
6827 case ARM::VST3dWB_register_Asm_8:
6828 case ARM::VST3dWB_register_Asm_16:
6829 case ARM::VST3dWB_register_Asm_32:
6830 case ARM::VST3qWB_register_Asm_8:
6831 case ARM::VST3qWB_register_Asm_16:
6832 case ARM::VST3qWB_register_Asm_32: {
6835 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6836 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6837 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6838 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6839 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6840 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6841 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6843 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6845 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6846 TmpInst.addOperand(Inst.getOperand(5));
6851 // VST4 multiple 3-element structure instructions.
6852 case ARM::VST4dAsm_8:
6853 case ARM::VST4dAsm_16:
6854 case ARM::VST4dAsm_32:
6855 case ARM::VST4qAsm_8:
6856 case ARM::VST4qAsm_16:
6857 case ARM::VST4qAsm_32: {
6860 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6861 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6862 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6863 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6864 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6866 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6868 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6870 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6871 TmpInst.addOperand(Inst.getOperand(4));
6876 case ARM::VST4dWB_fixed_Asm_8:
6877 case ARM::VST4dWB_fixed_Asm_16:
6878 case ARM::VST4dWB_fixed_Asm_32:
6879 case ARM::VST4qWB_fixed_Asm_8:
6880 case ARM::VST4qWB_fixed_Asm_16:
6881 case ARM::VST4qWB_fixed_Asm_32: {
6884 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6885 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6886 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6887 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6888 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6889 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6890 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6892 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6894 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6896 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6897 TmpInst.addOperand(Inst.getOperand(4));
6902 case ARM::VST4dWB_register_Asm_8:
6903 case ARM::VST4dWB_register_Asm_16:
6904 case ARM::VST4dWB_register_Asm_32:
6905 case ARM::VST4qWB_register_Asm_8:
6906 case ARM::VST4qWB_register_Asm_16:
6907 case ARM::VST4qWB_register_Asm_32: {
6910 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6911 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6912 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6913 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6914 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6915 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6916 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6918 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6920 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6922 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6923 TmpInst.addOperand(Inst.getOperand(5));
6928 // Handle encoding choice for the shift-immediate instructions.
6931 case ARM::t2ASRri: {
6932 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6933 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6934 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6935 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6936 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6938 switch (Inst.getOpcode()) {
6939 default: llvm_unreachable("unexpected opcode");
6940 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6941 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6942 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6944 // The Thumb1 operands aren't in the same order. Awesome, eh?
6946 TmpInst.setOpcode(NewOpc);
6947 TmpInst.addOperand(Inst.getOperand(0));
6948 TmpInst.addOperand(Inst.getOperand(5));
6949 TmpInst.addOperand(Inst.getOperand(1));
6950 TmpInst.addOperand(Inst.getOperand(2));
6951 TmpInst.addOperand(Inst.getOperand(3));
6952 TmpInst.addOperand(Inst.getOperand(4));
6959 // Handle the Thumb2 mode MOV complex aliases.
6961 case ARM::t2MOVSsr: {
6962 // Which instruction to expand to depends on the CCOut operand and
6963 // whether we're in an IT block if the register operands are low
6965 bool isNarrow = false;
6966 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6967 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6968 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6969 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6970 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6974 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6975 default: llvm_unreachable("unexpected opcode!");
6976 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6977 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6978 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6979 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6981 TmpInst.setOpcode(newOpc);
6982 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6984 TmpInst.addOperand(MCOperand::CreateReg(
6985 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6986 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6987 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6988 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6989 TmpInst.addOperand(Inst.getOperand(5));
6991 TmpInst.addOperand(MCOperand::CreateReg(
6992 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6997 case ARM::t2MOVSsi: {
6998 // Which instruction to expand to depends on the CCOut operand and
6999 // whether we're in an IT block if the register operands are low
7001 bool isNarrow = false;
7002 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7003 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7004 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7008 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7009 default: llvm_unreachable("unexpected opcode!");
7010 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7011 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7012 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7013 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7014 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7016 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7017 if (Amount == 32) Amount = 0;
7018 TmpInst.setOpcode(newOpc);
7019 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7021 TmpInst.addOperand(MCOperand::CreateReg(
7022 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7023 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7024 if (newOpc != ARM::t2RRX)
7025 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7026 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7027 TmpInst.addOperand(Inst.getOperand(4));
7029 TmpInst.addOperand(MCOperand::CreateReg(
7030 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7034 // Handle the ARM mode MOV complex aliases.
7039 ARM_AM::ShiftOpc ShiftTy;
7040 switch(Inst.getOpcode()) {
7041 default: llvm_unreachable("unexpected opcode!");
7042 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7043 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7044 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7045 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7047 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7049 TmpInst.setOpcode(ARM::MOVsr);
7050 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7051 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7052 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7053 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7054 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7055 TmpInst.addOperand(Inst.getOperand(4));
7056 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7064 ARM_AM::ShiftOpc ShiftTy;
7065 switch(Inst.getOpcode()) {
7066 default: llvm_unreachable("unexpected opcode!");
7067 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7068 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7069 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7070 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7072 // A shift by zero is a plain MOVr, not a MOVsi.
7073 unsigned Amt = Inst.getOperand(2).getImm();
7074 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7075 // A shift by 32 should be encoded as 0 when permitted
7076 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7078 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7080 TmpInst.setOpcode(Opc);
7081 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7082 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7083 if (Opc == ARM::MOVsi)
7084 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7085 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7086 TmpInst.addOperand(Inst.getOperand(4));
7087 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7092 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7094 TmpInst.setOpcode(ARM::MOVsi);
7095 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7096 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7097 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7098 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7099 TmpInst.addOperand(Inst.getOperand(3));
7100 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7104 case ARM::t2LDMIA_UPD: {
7105 // If this is a load of a single register, then we should use
7106 // a post-indexed LDR instruction instead, per the ARM ARM.
7107 if (Inst.getNumOperands() != 5)
7110 TmpInst.setOpcode(ARM::t2LDR_POST);
7111 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7112 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7113 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7114 TmpInst.addOperand(MCOperand::CreateImm(4));
7115 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7116 TmpInst.addOperand(Inst.getOperand(3));
7120 case ARM::t2STMDB_UPD: {
7121 // If this is a store of a single register, then we should use
7122 // a pre-indexed STR instruction instead, per the ARM ARM.
7123 if (Inst.getNumOperands() != 5)
7126 TmpInst.setOpcode(ARM::t2STR_PRE);
7127 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7128 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7129 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7130 TmpInst.addOperand(MCOperand::CreateImm(-4));
7131 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7132 TmpInst.addOperand(Inst.getOperand(3));
7136 case ARM::LDMIA_UPD:
7137 // If this is a load of a single register via a 'pop', then we should use
7138 // a post-indexed LDR instruction instead, per the ARM ARM.
7139 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7140 Inst.getNumOperands() == 5) {
7142 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7143 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7144 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7145 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7146 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7147 TmpInst.addOperand(MCOperand::CreateImm(4));
7148 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7149 TmpInst.addOperand(Inst.getOperand(3));
7154 case ARM::STMDB_UPD:
7155 // If this is a store of a single register via a 'push', then we should use
7156 // a pre-indexed STR instruction instead, per the ARM ARM.
7157 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7158 Inst.getNumOperands() == 5) {
7160 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7161 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7162 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7163 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7164 TmpInst.addOperand(MCOperand::CreateImm(-4));
7165 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7166 TmpInst.addOperand(Inst.getOperand(3));
7170 case ARM::t2ADDri12:
7171 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7172 // mnemonic was used (not "addw"), encoding T3 is preferred.
7173 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7174 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7176 Inst.setOpcode(ARM::t2ADDri);
7177 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7179 case ARM::t2SUBri12:
7180 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7181 // mnemonic was used (not "subw"), encoding T3 is preferred.
7182 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7183 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7185 Inst.setOpcode(ARM::t2SUBri);
7186 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7189 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7190 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7191 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7192 // to encoding T1 if <Rd> is omitted."
7193 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7194 Inst.setOpcode(ARM::tADDi3);
7199 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7200 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7201 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7202 // to encoding T1 if <Rd> is omitted."
7203 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7204 Inst.setOpcode(ARM::tSUBi3);
7209 case ARM::t2SUBri: {
7210 // If the destination and first source operand are the same, and
7211 // the flags are compatible with the current IT status, use encoding T2
7212 // instead of T3. For compatibility with the system 'as'. Make sure the
7213 // wide encoding wasn't explicit.
7214 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7215 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7216 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7217 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7218 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7219 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7220 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7223 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7224 ARM::tADDi8 : ARM::tSUBi8);
7225 TmpInst.addOperand(Inst.getOperand(0));
7226 TmpInst.addOperand(Inst.getOperand(5));
7227 TmpInst.addOperand(Inst.getOperand(0));
7228 TmpInst.addOperand(Inst.getOperand(2));
7229 TmpInst.addOperand(Inst.getOperand(3));
7230 TmpInst.addOperand(Inst.getOperand(4));
7234 case ARM::t2ADDrr: {
7235 // If the destination and first source operand are the same, and
7236 // there's no setting of the flags, use encoding T2 instead of T3.
7237 // Note that this is only for ADD, not SUB. This mirrors the system
7238 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7239 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7240 Inst.getOperand(5).getReg() != 0 ||
7241 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7242 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7245 TmpInst.setOpcode(ARM::tADDhirr);
7246 TmpInst.addOperand(Inst.getOperand(0));
7247 TmpInst.addOperand(Inst.getOperand(0));
7248 TmpInst.addOperand(Inst.getOperand(2));
7249 TmpInst.addOperand(Inst.getOperand(3));
7250 TmpInst.addOperand(Inst.getOperand(4));
7254 case ARM::tADDrSP: {
7255 // If the non-SP source operand and the destination operand are not the
7256 // same, we need to use the 32-bit encoding if it's available.
7257 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7258 Inst.setOpcode(ARM::t2ADDrr);
7259 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7265 // A Thumb conditional branch outside of an IT block is a tBcc.
7266 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7267 Inst.setOpcode(ARM::tBcc);
7272 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7273 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7274 Inst.setOpcode(ARM::t2Bcc);
7279 // If the conditional is AL or we're in an IT block, we really want t2B.
7280 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7281 Inst.setOpcode(ARM::t2B);
7286 // If the conditional is AL, we really want tB.
7287 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7288 Inst.setOpcode(ARM::tB);
7293 // If the register list contains any high registers, or if the writeback
7294 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7295 // instead if we're in Thumb2. Otherwise, this should have generated
7296 // an error in validateInstruction().
7297 unsigned Rn = Inst.getOperand(0).getReg();
7298 bool hasWritebackToken =
7299 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7300 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7301 bool listContainsBase;
7302 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7303 (!listContainsBase && !hasWritebackToken) ||
7304 (listContainsBase && hasWritebackToken)) {
7305 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7306 assert (isThumbTwo());
7307 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7308 // If we're switching to the updating version, we need to insert
7309 // the writeback tied operand.
7310 if (hasWritebackToken)
7311 Inst.insert(Inst.begin(),
7312 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7317 case ARM::tSTMIA_UPD: {
7318 // If the register list contains any high registers, we need to use
7319 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7320 // should have generated an error in validateInstruction().
7321 unsigned Rn = Inst.getOperand(0).getReg();
7322 bool listContainsBase;
7323 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7324 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7325 assert (isThumbTwo());
7326 Inst.setOpcode(ARM::t2STMIA_UPD);
7332 bool listContainsBase;
7333 // If the register list contains any high registers, we need to use
7334 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7335 // should have generated an error in validateInstruction().
7336 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7338 assert (isThumbTwo());
7339 Inst.setOpcode(ARM::t2LDMIA_UPD);
7340 // Add the base register and writeback operands.
7341 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7342 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7346 bool listContainsBase;
7347 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7349 assert (isThumbTwo());
7350 Inst.setOpcode(ARM::t2STMDB_UPD);
7351 // Add the base register and writeback operands.
7352 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7353 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7357 // If we can use the 16-bit encoding and the user didn't explicitly
7358 // request the 32-bit variant, transform it here.
7359 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7360 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7361 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7362 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7363 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7364 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7365 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7366 // The operands aren't in the same order for tMOVi8...
7368 TmpInst.setOpcode(ARM::tMOVi8);
7369 TmpInst.addOperand(Inst.getOperand(0));
7370 TmpInst.addOperand(Inst.getOperand(4));
7371 TmpInst.addOperand(Inst.getOperand(1));
7372 TmpInst.addOperand(Inst.getOperand(2));
7373 TmpInst.addOperand(Inst.getOperand(3));
7380 // If we can use the 16-bit encoding and the user didn't explicitly
7381 // request the 32-bit variant, transform it here.
7382 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7383 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7384 Inst.getOperand(2).getImm() == ARMCC::AL &&
7385 Inst.getOperand(4).getReg() == ARM::CPSR &&
7386 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7387 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7388 // The operands aren't the same for tMOV[S]r... (no cc_out)
7390 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7391 TmpInst.addOperand(Inst.getOperand(0));
7392 TmpInst.addOperand(Inst.getOperand(1));
7393 TmpInst.addOperand(Inst.getOperand(2));
7394 TmpInst.addOperand(Inst.getOperand(3));
7404 // If we can use the 16-bit encoding and the user didn't explicitly
7405 // request the 32-bit variant, transform it here.
7406 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7407 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7408 Inst.getOperand(2).getImm() == 0 &&
7409 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7410 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7412 switch (Inst.getOpcode()) {
7413 default: llvm_unreachable("Illegal opcode!");
7414 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7415 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7416 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7417 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7419 // The operands aren't the same for thumb1 (no rotate operand).
7421 TmpInst.setOpcode(NewOpc);
7422 TmpInst.addOperand(Inst.getOperand(0));
7423 TmpInst.addOperand(Inst.getOperand(1));
7424 TmpInst.addOperand(Inst.getOperand(3));
7425 TmpInst.addOperand(Inst.getOperand(4));
7432 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7433 // rrx shifts and asr/lsr of #32 is encoded as 0
7434 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7436 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7437 // Shifting by zero is accepted as a vanilla 'MOVr'
7439 TmpInst.setOpcode(ARM::MOVr);
7440 TmpInst.addOperand(Inst.getOperand(0));
7441 TmpInst.addOperand(Inst.getOperand(1));
7442 TmpInst.addOperand(Inst.getOperand(3));
7443 TmpInst.addOperand(Inst.getOperand(4));
7444 TmpInst.addOperand(Inst.getOperand(5));
7457 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7458 if (SOpc == ARM_AM::rrx) return false;
7459 switch (Inst.getOpcode()) {
7460 default: llvm_unreachable("unexpected opcode!");
7461 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7462 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7463 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7464 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7465 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7466 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7468 // If the shift is by zero, use the non-shifted instruction definition.
7469 // The exception is for right shifts, where 0 == 32
7470 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7471 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7473 TmpInst.setOpcode(newOpc);
7474 TmpInst.addOperand(Inst.getOperand(0));
7475 TmpInst.addOperand(Inst.getOperand(1));
7476 TmpInst.addOperand(Inst.getOperand(2));
7477 TmpInst.addOperand(Inst.getOperand(4));
7478 TmpInst.addOperand(Inst.getOperand(5));
7479 TmpInst.addOperand(Inst.getOperand(6));
7487 // The mask bits for all but the first condition are represented as
7488 // the low bit of the condition code value implies 't'. We currently
7489 // always have 1 implies 't', so XOR toggle the bits if the low bit
7490 // of the condition code is zero.
7491 MCOperand &MO = Inst.getOperand(1);
7492 unsigned Mask = MO.getImm();
7493 unsigned OrigMask = Mask;
7494 unsigned TZ = countTrailingZeros(Mask);
7495 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7496 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7497 Mask ^= (0xE << TZ) & 0xF;
7501 // Set up the IT block state according to the IT instruction we just
7503 assert(!inITBlock() && "nested IT blocks?!");
7504 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7505 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7506 ITState.CurPosition = 0;
7507 ITState.FirstCond = true;
7517 // Assemblers should use the narrow encodings of these instructions when permissible.
7518 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7519 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7520 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7521 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7522 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7523 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7524 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7526 switch (Inst.getOpcode()) {
7527 default: llvm_unreachable("unexpected opcode");
7528 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7529 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7530 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7531 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7532 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7533 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7536 TmpInst.setOpcode(NewOpc);
7537 TmpInst.addOperand(Inst.getOperand(0));
7538 TmpInst.addOperand(Inst.getOperand(5));
7539 TmpInst.addOperand(Inst.getOperand(1));
7540 TmpInst.addOperand(Inst.getOperand(2));
7541 TmpInst.addOperand(Inst.getOperand(3));
7542 TmpInst.addOperand(Inst.getOperand(4));
7553 // Assemblers should use the narrow encodings of these instructions when permissible.
7554 // These instructions are special in that they are commutable, so shorter encodings
7555 // are available more often.
7556 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7557 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7558 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7559 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7560 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7561 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7562 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7563 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7565 switch (Inst.getOpcode()) {
7566 default: llvm_unreachable("unexpected opcode");
7567 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7568 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7569 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7570 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7573 TmpInst.setOpcode(NewOpc);
7574 TmpInst.addOperand(Inst.getOperand(0));
7575 TmpInst.addOperand(Inst.getOperand(5));
7576 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7577 TmpInst.addOperand(Inst.getOperand(1));
7578 TmpInst.addOperand(Inst.getOperand(2));
7580 TmpInst.addOperand(Inst.getOperand(2));
7581 TmpInst.addOperand(Inst.getOperand(1));
7583 TmpInst.addOperand(Inst.getOperand(3));
7584 TmpInst.addOperand(Inst.getOperand(4));
7594 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7595 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7596 // suffix depending on whether they're in an IT block or not.
7597 unsigned Opc = Inst.getOpcode();
7598 const MCInstrDesc &MCID = MII.get(Opc);
7599 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7600 assert(MCID.hasOptionalDef() &&
7601 "optionally flag setting instruction missing optional def operand");
7602 assert(MCID.NumOperands == Inst.getNumOperands() &&
7603 "operand count mismatch!");
7604 // Find the optional-def operand (cc_out).
7607 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7610 // If we're parsing Thumb1, reject it completely.
7611 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7612 return Match_MnemonicFail;
7613 // If we're parsing Thumb2, which form is legal depends on whether we're
7615 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7617 return Match_RequiresITBlock;
7618 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7620 return Match_RequiresNotITBlock;
7622 // Some high-register supporting Thumb1 encodings only allow both registers
7623 // to be from r0-r7 when in Thumb2.
7624 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7625 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7626 isARMLowRegister(Inst.getOperand(2).getReg()))
7627 return Match_RequiresThumb2;
7628 // Others only require ARMv6 or later.
7629 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7630 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7631 isARMLowRegister(Inst.getOperand(1).getReg()))
7632 return Match_RequiresV6;
7633 return Match_Success;
7636 static const char *getSubtargetFeatureName(unsigned Val);
7638 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7639 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7640 MCStreamer &Out, unsigned &ErrorInfo,
7641 bool MatchingInlineAsm) {
7643 unsigned MatchResult;
7645 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7647 switch (MatchResult) {
7650 // Context sensitive operand constraints aren't handled by the matcher,
7651 // so check them here.
7652 if (validateInstruction(Inst, Operands)) {
7653 // Still progress the IT block, otherwise one wrong condition causes
7654 // nasty cascading errors.
7655 forwardITPosition();
7659 { // processInstruction() updates inITBlock state, we need to save it away
7660 bool wasInITBlock = inITBlock();
7662 // Some instructions need post-processing to, for example, tweak which
7663 // encoding is selected. Loop on it while changes happen so the
7664 // individual transformations can chain off each other. E.g.,
7665 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7666 while (processInstruction(Inst, Operands))
7669 // Only after the instruction is fully processed, we can validate it
7670 if (wasInITBlock && hasV8Ops() && isThumb() &&
7671 !isV8EligibleForIT(&Inst, 2)) {
7672 Warning(IDLoc, "deprecated instruction in IT block");
7676 // Only move forward at the very end so that everything in validate
7677 // and process gets a consistent answer about whether we're in an IT
7679 forwardITPosition();
7681 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7682 // doesn't actually encode.
7683 if (Inst.getOpcode() == ARM::ITasm)
7687 Out.EmitInstruction(Inst);
7689 case Match_MissingFeature: {
7690 assert(ErrorInfo && "Unknown missing feature!");
7691 // Special case the error message for the very common case where only
7692 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7693 std::string Msg = "instruction requires:";
7695 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7696 if (ErrorInfo & Mask) {
7698 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7702 return Error(IDLoc, Msg);
7704 case Match_InvalidOperand: {
7705 SMLoc ErrorLoc = IDLoc;
7706 if (ErrorInfo != ~0U) {
7707 if (ErrorInfo >= Operands.size())
7708 return Error(IDLoc, "too few operands for instruction");
7710 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7711 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7714 return Error(ErrorLoc, "invalid operand for instruction");
7716 case Match_MnemonicFail:
7717 return Error(IDLoc, "invalid instruction",
7718 ((ARMOperand*)Operands[0])->getLocRange());
7719 case Match_RequiresNotITBlock:
7720 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7721 case Match_RequiresITBlock:
7722 return Error(IDLoc, "instruction only valid inside IT block");
7723 case Match_RequiresV6:
7724 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7725 case Match_RequiresThumb2:
7726 return Error(IDLoc, "instruction variant requires Thumb2");
7727 case Match_ImmRange0_15: {
7728 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7729 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7730 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7732 case Match_ImmRange0_239: {
7733 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7734 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7735 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7739 llvm_unreachable("Implement any new match types added!");
7742 /// parseDirective parses the arm specific directives
7743 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7744 StringRef IDVal = DirectiveID.getIdentifier();
7745 if (IDVal == ".word")
7746 return parseDirectiveWord(4, DirectiveID.getLoc());
7747 else if (IDVal == ".thumb")
7748 return parseDirectiveThumb(DirectiveID.getLoc());
7749 else if (IDVal == ".arm")
7750 return parseDirectiveARM(DirectiveID.getLoc());
7751 else if (IDVal == ".thumb_func")
7752 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7753 else if (IDVal == ".code")
7754 return parseDirectiveCode(DirectiveID.getLoc());
7755 else if (IDVal == ".syntax")
7756 return parseDirectiveSyntax(DirectiveID.getLoc());
7757 else if (IDVal == ".unreq")
7758 return parseDirectiveUnreq(DirectiveID.getLoc());
7759 else if (IDVal == ".arch")
7760 return parseDirectiveArch(DirectiveID.getLoc());
7761 else if (IDVal == ".eabi_attribute")
7762 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7763 else if (IDVal == ".fnstart")
7764 return parseDirectiveFnStart(DirectiveID.getLoc());
7765 else if (IDVal == ".fnend")
7766 return parseDirectiveFnEnd(DirectiveID.getLoc());
7767 else if (IDVal == ".cantunwind")
7768 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7769 else if (IDVal == ".personality")
7770 return parseDirectivePersonality(DirectiveID.getLoc());
7771 else if (IDVal == ".handlerdata")
7772 return parseDirectiveHandlerData(DirectiveID.getLoc());
7773 else if (IDVal == ".setfp")
7774 return parseDirectiveSetFP(DirectiveID.getLoc());
7775 else if (IDVal == ".pad")
7776 return parseDirectivePad(DirectiveID.getLoc());
7777 else if (IDVal == ".save")
7778 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7779 else if (IDVal == ".vsave")
7780 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7784 /// parseDirectiveWord
7785 /// ::= .word [ expression (, expression)* ]
7786 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7787 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7789 const MCExpr *Value;
7790 if (getParser().parseExpression(Value))
7793 getParser().getStreamer().EmitValue(Value, Size);
7795 if (getLexer().is(AsmToken::EndOfStatement))
7798 // FIXME: Improve diagnostic.
7799 if (getLexer().isNot(AsmToken::Comma))
7800 return Error(L, "unexpected token in directive");
7809 /// parseDirectiveThumb
7811 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7812 if (getLexer().isNot(AsmToken::EndOfStatement))
7813 return Error(L, "unexpected token in directive");
7817 return Error(L, "target does not support Thumb mode");
7821 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7825 /// parseDirectiveARM
7827 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7828 if (getLexer().isNot(AsmToken::EndOfStatement))
7829 return Error(L, "unexpected token in directive");
7833 return Error(L, "target does not support ARM mode");
7837 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7841 /// parseDirectiveThumbFunc
7842 /// ::= .thumbfunc symbol_name
7843 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7844 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7845 bool isMachO = MAI->hasSubsectionsViaSymbols();
7847 bool needFuncName = true;
7849 // Darwin asm has (optionally) function name after .thumb_func direction
7852 const AsmToken &Tok = Parser.getTok();
7853 if (Tok.isNot(AsmToken::EndOfStatement)) {
7854 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7855 return Error(L, "unexpected token in .thumb_func directive");
7856 Name = Tok.getIdentifier();
7857 Parser.Lex(); // Consume the identifier token.
7858 needFuncName = false;
7862 if (getLexer().isNot(AsmToken::EndOfStatement))
7863 return Error(L, "unexpected token in directive");
7865 // Eat the end of statement and any blank lines that follow.
7866 while (getLexer().is(AsmToken::EndOfStatement))
7869 // FIXME: assuming function name will be the line following .thumb_func
7870 // We really should be checking the next symbol definition even if there's
7871 // stuff in between.
7873 Name = Parser.getTok().getIdentifier();
7876 // Mark symbol as a thumb symbol.
7877 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7878 getParser().getStreamer().EmitThumbFunc(Func);
7882 /// parseDirectiveSyntax
7883 /// ::= .syntax unified | divided
7884 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7885 const AsmToken &Tok = Parser.getTok();
7886 if (Tok.isNot(AsmToken::Identifier))
7887 return Error(L, "unexpected token in .syntax directive");
7888 StringRef Mode = Tok.getString();
7889 if (Mode == "unified" || Mode == "UNIFIED")
7891 else if (Mode == "divided" || Mode == "DIVIDED")
7892 return Error(L, "'.syntax divided' arm asssembly not supported");
7894 return Error(L, "unrecognized syntax mode in .syntax directive");
7896 if (getLexer().isNot(AsmToken::EndOfStatement))
7897 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7900 // TODO tell the MC streamer the mode
7901 // getParser().getStreamer().Emit???();
7905 /// parseDirectiveCode
7906 /// ::= .code 16 | 32
7907 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7908 const AsmToken &Tok = Parser.getTok();
7909 if (Tok.isNot(AsmToken::Integer))
7910 return Error(L, "unexpected token in .code directive");
7911 int64_t Val = Parser.getTok().getIntVal();
7917 return Error(L, "invalid operand to .code directive");
7919 if (getLexer().isNot(AsmToken::EndOfStatement))
7920 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7925 return Error(L, "target does not support Thumb mode");
7929 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7932 return Error(L, "target does not support ARM mode");
7936 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7942 /// parseDirectiveReq
7943 /// ::= name .req registername
7944 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7945 Parser.Lex(); // Eat the '.req' token.
7947 SMLoc SRegLoc, ERegLoc;
7948 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7949 Parser.eatToEndOfStatement();
7950 return Error(SRegLoc, "register name expected");
7953 // Shouldn't be anything else.
7954 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7955 Parser.eatToEndOfStatement();
7956 return Error(Parser.getTok().getLoc(),
7957 "unexpected input in .req directive.");
7960 Parser.Lex(); // Consume the EndOfStatement
7962 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7963 return Error(SRegLoc, "redefinition of '" + Name +
7964 "' does not match original.");
7969 /// parseDirectiveUneq
7970 /// ::= .unreq registername
7971 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7972 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7973 Parser.eatToEndOfStatement();
7974 return Error(L, "unexpected input in .unreq directive.");
7976 RegisterReqs.erase(Parser.getTok().getIdentifier());
7977 Parser.Lex(); // Eat the identifier.
7981 /// parseDirectiveArch
7983 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7987 /// parseDirectiveEabiAttr
7988 /// ::= .eabi_attribute int, int
7989 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7993 /// parseDirectiveFnStart
7995 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7996 if (FnStartLoc.isValid()) {
7997 Error(L, ".fnstart starts before the end of previous one");
7998 Error(FnStartLoc, "previous .fnstart starts here");
8003 getTargetStreamer().emitFnStart();
8007 /// parseDirectiveFnEnd
8009 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8010 // Check the ordering of unwind directives
8011 if (!FnStartLoc.isValid())
8012 return Error(L, ".fnstart must precede .fnend directive");
8014 // Reset the unwind directives parser state
8015 resetUnwindDirectiveParserState();
8016 getTargetStreamer().emitFnEnd();
8020 /// parseDirectiveCantUnwind
8022 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8023 // Check the ordering of unwind directives
8025 if (!FnStartLoc.isValid())
8026 return Error(L, ".fnstart must precede .cantunwind directive");
8027 if (HandlerDataLoc.isValid()) {
8028 Error(L, ".cantunwind can't be used with .handlerdata directive");
8029 Error(HandlerDataLoc, ".handlerdata was specified here");
8032 if (PersonalityLoc.isValid()) {
8033 Error(L, ".cantunwind can't be used with .personality directive");
8034 Error(PersonalityLoc, ".personality was specified here");
8038 getTargetStreamer().emitCantUnwind();
8042 /// parseDirectivePersonality
8043 /// ::= .personality name
8044 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8045 // Check the ordering of unwind directives
8047 if (!FnStartLoc.isValid())
8048 return Error(L, ".fnstart must precede .personality directive");
8049 if (CantUnwindLoc.isValid()) {
8050 Error(L, ".personality can't be used with .cantunwind directive");
8051 Error(CantUnwindLoc, ".cantunwind was specified here");
8054 if (HandlerDataLoc.isValid()) {
8055 Error(L, ".personality must precede .handlerdata directive");
8056 Error(HandlerDataLoc, ".handlerdata was specified here");
8060 // Parse the name of the personality routine
8061 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8062 Parser.eatToEndOfStatement();
8063 return Error(L, "unexpected input in .personality directive.");
8065 StringRef Name(Parser.getTok().getIdentifier());
8068 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8069 getTargetStreamer().emitPersonality(PR);
8073 /// parseDirectiveHandlerData
8074 /// ::= .handlerdata
8075 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8076 // Check the ordering of unwind directives
8078 if (!FnStartLoc.isValid())
8079 return Error(L, ".fnstart must precede .personality directive");
8080 if (CantUnwindLoc.isValid()) {
8081 Error(L, ".handlerdata can't be used with .cantunwind directive");
8082 Error(CantUnwindLoc, ".cantunwind was specified here");
8086 getTargetStreamer().emitHandlerData();
8090 /// parseDirectiveSetFP
8091 /// ::= .setfp fpreg, spreg [, offset]
8092 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8093 // Check the ordering of unwind directives
8094 if (!FnStartLoc.isValid())
8095 return Error(L, ".fnstart must precede .setfp directive");
8096 if (HandlerDataLoc.isValid())
8097 return Error(L, ".setfp must precede .handlerdata directive");
8100 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8101 int NewFPReg = tryParseRegister();
8103 return Error(NewFPRegLoc, "frame pointer register expected");
8106 if (!Parser.getTok().is(AsmToken::Comma))
8107 return Error(Parser.getTok().getLoc(), "comma expected");
8108 Parser.Lex(); // skip comma
8111 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8112 int NewSPReg = tryParseRegister();
8114 return Error(NewSPRegLoc, "stack pointer register expected");
8116 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8117 return Error(NewSPRegLoc,
8118 "register should be either $sp or the latest fp register");
8120 // Update the frame pointer register
8125 if (Parser.getTok().is(AsmToken::Comma)) {
8126 Parser.Lex(); // skip comma
8128 if (Parser.getTok().isNot(AsmToken::Hash) &&
8129 Parser.getTok().isNot(AsmToken::Dollar)) {
8130 return Error(Parser.getTok().getLoc(), "'#' expected");
8132 Parser.Lex(); // skip hash token.
8134 const MCExpr *OffsetExpr;
8135 SMLoc ExLoc = Parser.getTok().getLoc();
8137 if (getParser().parseExpression(OffsetExpr, EndLoc))
8138 return Error(ExLoc, "malformed setfp offset");
8139 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8141 return Error(ExLoc, "setfp offset must be an immediate");
8143 Offset = CE->getValue();
8146 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8147 static_cast<unsigned>(NewSPReg), Offset);
8153 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8154 // Check the ordering of unwind directives
8155 if (!FnStartLoc.isValid())
8156 return Error(L, ".fnstart must precede .pad directive");
8157 if (HandlerDataLoc.isValid())
8158 return Error(L, ".pad must precede .handlerdata directive");
8161 if (Parser.getTok().isNot(AsmToken::Hash) &&
8162 Parser.getTok().isNot(AsmToken::Dollar)) {
8163 return Error(Parser.getTok().getLoc(), "'#' expected");
8165 Parser.Lex(); // skip hash token.
8167 const MCExpr *OffsetExpr;
8168 SMLoc ExLoc = Parser.getTok().getLoc();
8170 if (getParser().parseExpression(OffsetExpr, EndLoc))
8171 return Error(ExLoc, "malformed pad offset");
8172 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8174 return Error(ExLoc, "pad offset must be an immediate");
8176 getTargetStreamer().emitPad(CE->getValue());
8180 /// parseDirectiveRegSave
8181 /// ::= .save { registers }
8182 /// ::= .vsave { registers }
8183 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8184 // Check the ordering of unwind directives
8185 if (!FnStartLoc.isValid())
8186 return Error(L, ".fnstart must precede .save or .vsave directives");
8187 if (HandlerDataLoc.isValid())
8188 return Error(L, ".save or .vsave must precede .handlerdata directive");
8190 // RAII object to make sure parsed operands are deleted.
8191 struct CleanupObject {
8192 SmallVector<MCParsedAsmOperand *, 1> Operands;
8194 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8199 // Parse the register list
8200 if (parseRegisterList(CO.Operands))
8202 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
8203 if (!IsVector && !Op->isRegList())
8204 return Error(L, ".save expects GPR registers");
8205 if (IsVector && !Op->isDPRRegList())
8206 return Error(L, ".vsave expects DPR registers");
8208 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
8212 /// Force static initialization.
8213 extern "C" void LLVMInitializeARMAsmParser() {
8214 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8215 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8218 #define GET_REGISTER_MATCHER
8219 #define GET_SUBTARGET_FEATURE_NAME
8220 #define GET_MATCHER_IMPLEMENTATION
8221 #include "ARMGenAsmMatcher.inc"
8223 // Define this matcher function after the auto-generated include so we
8224 // have the match class enum definitions.
8225 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8227 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8228 // If the kind is a token for a literal immediate, check if our asm
8229 // operand matches. This is for InstAliases which have a fixed-value
8230 // immediate in the syntax.
8231 if (Kind == MCK__35_0 && Op->isImm()) {
8232 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8234 return Match_InvalidOperand;
8235 if (CE->getValue() == 0)
8236 return Match_Success;
8238 return Match_InvalidOperand;