1 //===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "ARMBuildAttrs.h"
11 #include "ARMFPUName.h"
12 #include "ARMFeatures.h"
13 #include "llvm/MC/MCTargetAsmParser.h"
14 #include "MCTargetDesc/ARMAddressingModes.h"
15 #include "MCTargetDesc/ARMBaseInfo.h"
16 #include "MCTargetDesc/ARMMCExpr.h"
17 #include "llvm/ADT/BitVector.h"
18 #include "llvm/ADT/OwningPtr.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringSwitch.h"
22 #include "llvm/ADT/Twine.h"
23 #include "llvm/MC/MCAsmInfo.h"
24 #include "llvm/MC/MCAssembler.h"
25 #include "llvm/MC/MCContext.h"
26 #include "llvm/MC/MCELFStreamer.h"
27 #include "llvm/MC/MCExpr.h"
28 #include "llvm/MC/MCInst.h"
29 #include "llvm/MC/MCInstrDesc.h"
30 #include "llvm/MC/MCInstrInfo.h"
31 #include "llvm/MC/MCParser/MCAsmLexer.h"
32 #include "llvm/MC/MCParser/MCAsmParser.h"
33 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
34 #include "llvm/MC/MCRegisterInfo.h"
35 #include "llvm/MC/MCStreamer.h"
36 #include "llvm/MC/MCSubtargetInfo.h"
37 #include "llvm/Support/ELF.h"
38 #include "llvm/Support/MathExtras.h"
39 #include "llvm/Support/SourceMgr.h"
40 #include "llvm/Support/TargetRegistry.h"
41 #include "llvm/Support/raw_ostream.h"
49 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
51 class ARMAsmParser : public MCTargetAsmParser {
54 const MCInstrInfo &MII;
55 const MCRegisterInfo *MRI;
57 ARMTargetStreamer &getTargetStreamer() {
58 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
59 return static_cast<ARMTargetStreamer &>(TS);
62 // Unwind directives state
68 void resetUnwindDirectiveParserState() {
70 CantUnwindLoc = SMLoc();
71 PersonalityLoc = SMLoc();
72 HandlerDataLoc = SMLoc();
76 // Map of register aliases registers via the .req directive.
77 StringMap<unsigned> RegisterReqs;
79 bool NextSymbolIsThumb;
82 ARMCC::CondCodes Cond; // Condition for IT block.
83 unsigned Mask:4; // Condition mask for instructions.
84 // Starting at first 1 (from lsb).
85 // '1' condition as indicated in IT.
86 // '0' inverse of condition (else).
87 // Count of instructions in IT block is
88 // 4 - trailingzeroes(mask)
90 bool FirstCond; // Explicit flag for when we're parsing the
91 // First instruction in the IT block. It's
92 // implied in the mask, so needs special
95 unsigned CurPosition; // Current position in parsing of IT
96 // block. In range [0,3]. Initialized
97 // according to count of instructions in block.
98 // ~0U if no active IT block.
100 bool inITBlock() { return ITState.CurPosition != ~0U;}
101 void forwardITPosition() {
102 if (!inITBlock()) return;
103 // Move to the next instruction in the IT block, if there is one. If not,
104 // mark the block as done.
105 unsigned TZ = countTrailingZeros(ITState.Mask);
106 if (++ITState.CurPosition == 5 - TZ)
107 ITState.CurPosition = ~0U; // Done with the IT block after this.
111 MCAsmParser &getParser() const { return Parser; }
112 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
114 bool Warning(SMLoc L, const Twine &Msg,
115 ArrayRef<SMRange> Ranges = None) {
116 return Parser.Warning(L, Msg, Ranges);
118 bool Error(SMLoc L, const Twine &Msg,
119 ArrayRef<SMRange> Ranges = None) {
120 return Parser.Error(L, Msg, Ranges);
123 int tryParseRegister();
124 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
125 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
126 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
127 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
128 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
129 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
130 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
131 unsigned &ShiftAmount);
132 bool parseDirectiveWord(unsigned Size, SMLoc L);
133 bool parseDirectiveThumb(SMLoc L);
134 bool parseDirectiveARM(SMLoc L);
135 bool parseDirectiveThumbFunc(SMLoc L);
136 bool parseDirectiveCode(SMLoc L);
137 bool parseDirectiveSyntax(SMLoc L);
138 bool parseDirectiveReq(StringRef Name, SMLoc L);
139 bool parseDirectiveUnreq(SMLoc L);
140 bool parseDirectiveArch(SMLoc L);
141 bool parseDirectiveEabiAttr(SMLoc L);
142 bool parseDirectiveCPU(SMLoc L);
143 bool parseDirectiveFPU(SMLoc L);
144 bool parseDirectiveFnStart(SMLoc L);
145 bool parseDirectiveFnEnd(SMLoc L);
146 bool parseDirectiveCantUnwind(SMLoc L);
147 bool parseDirectivePersonality(SMLoc L);
148 bool parseDirectiveHandlerData(SMLoc L);
149 bool parseDirectiveSetFP(SMLoc L);
150 bool parseDirectivePad(SMLoc L);
151 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
153 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
154 bool &CarrySetting, unsigned &ProcessorIMod,
156 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
157 bool &CanAcceptCarrySet,
158 bool &CanAcceptPredicationCode);
160 bool isThumb() const {
161 // FIXME: Can tablegen auto-generate this?
162 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
164 bool isThumbOne() const {
165 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
167 bool isThumbTwo() const {
168 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
170 bool hasThumb() const {
171 return STI.getFeatureBits() & ARM::HasV4TOps;
173 bool hasV6Ops() const {
174 return STI.getFeatureBits() & ARM::HasV6Ops;
176 bool hasV6MOps() const {
177 return STI.getFeatureBits() & ARM::HasV6MOps;
179 bool hasV7Ops() const {
180 return STI.getFeatureBits() & ARM::HasV7Ops;
182 bool hasV8Ops() const {
183 return STI.getFeatureBits() & ARM::HasV8Ops;
185 bool hasARM() const {
186 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
190 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
191 setAvailableFeatures(FB);
193 bool isMClass() const {
194 return STI.getFeatureBits() & ARM::FeatureMClass;
197 /// @name Auto-generated Match Functions
200 #define GET_ASSEMBLER_HEADER
201 #include "ARMGenAsmMatcher.inc"
205 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
206 OperandMatchResultTy parseCoprocNumOperand(
207 SmallVectorImpl<MCParsedAsmOperand*>&);
208 OperandMatchResultTy parseCoprocRegOperand(
209 SmallVectorImpl<MCParsedAsmOperand*>&);
210 OperandMatchResultTy parseCoprocOptionOperand(
211 SmallVectorImpl<MCParsedAsmOperand*>&);
212 OperandMatchResultTy parseMemBarrierOptOperand(
213 SmallVectorImpl<MCParsedAsmOperand*>&);
214 OperandMatchResultTy parseInstSyncBarrierOptOperand(
215 SmallVectorImpl<MCParsedAsmOperand*>&);
216 OperandMatchResultTy parseProcIFlagsOperand(
217 SmallVectorImpl<MCParsedAsmOperand*>&);
218 OperandMatchResultTy parseMSRMaskOperand(
219 SmallVectorImpl<MCParsedAsmOperand*>&);
220 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
221 StringRef Op, int Low, int High);
222 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
223 return parsePKHImm(O, "lsl", 0, 31);
225 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
226 return parsePKHImm(O, "asr", 1, 32);
228 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
229 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
230 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
231 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
232 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
233 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
234 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
235 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
236 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
239 // Asm Match Converter Methods
240 void cvtThumbMultiply(MCInst &Inst,
241 const SmallVectorImpl<MCParsedAsmOperand*> &);
242 void cvtThumbBranches(MCInst &Inst,
243 const SmallVectorImpl<MCParsedAsmOperand*> &);
245 bool validateInstruction(MCInst &Inst,
246 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
247 bool processInstruction(MCInst &Inst,
248 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
249 bool shouldOmitCCOutOperand(StringRef Mnemonic,
250 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
251 bool shouldOmitPredicateOperand(StringRef Mnemonic,
252 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
254 enum ARMMatchResultTy {
255 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
256 Match_RequiresNotITBlock,
258 Match_RequiresThumb2,
259 #define GET_OPERAND_DIAGNOSTIC_TYPES
260 #include "ARMGenAsmMatcher.inc"
264 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
265 const MCInstrInfo &MII)
266 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
267 MCAsmParserExtension::Initialize(_Parser);
269 // Cache the MCRegisterInfo.
270 MRI = getContext().getRegisterInfo();
272 // Initialize the set of available features.
273 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
275 // Not in an ITBlock to start with.
276 ITState.CurPosition = ~0U;
278 NextSymbolIsThumb = false;
281 // Implementation of the MCTargetAsmParser interface:
282 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
283 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
285 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
286 bool ParseDirective(AsmToken DirectiveID);
288 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
289 unsigned checkTargetMatchPredicate(MCInst &Inst);
291 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
292 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
293 MCStreamer &Out, unsigned &ErrorInfo,
294 bool MatchingInlineAsm);
295 void onLabelParsed(MCSymbol *Symbol);
298 } // end anonymous namespace
302 /// ARMOperand - Instances of this class represent a parsed ARM machine
304 class ARMOperand : public MCParsedAsmOperand {
314 k_InstSyncBarrierOpt,
325 k_VectorListAllLanes,
331 k_BitfieldDescriptor,
335 SMLoc StartLoc, EndLoc;
336 SmallVector<unsigned, 8> Registers;
339 ARMCC::CondCodes Val;
346 struct CoprocOptionOp {
359 ARM_ISB::InstSyncBOpt Val;
363 ARM_PROC::IFlags Val;
379 // A vector register list is a sequential list of 1 to 4 registers.
380 struct VectorListOp {
387 struct VectorIndexOp {
395 /// Combined record for all forms of ARM address expressions.
398 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
400 const MCConstantExpr *OffsetImm; // Offset immediate value
401 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
402 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
403 unsigned ShiftImm; // shift for OffsetReg.
404 unsigned Alignment; // 0 = no alignment specified
405 // n = alignment in bytes (2, 4, 8, 16, or 32)
406 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
409 struct PostIdxRegOp {
412 ARM_AM::ShiftOpc ShiftTy;
416 struct ShifterImmOp {
421 struct RegShiftedRegOp {
422 ARM_AM::ShiftOpc ShiftTy;
428 struct RegShiftedImmOp {
429 ARM_AM::ShiftOpc ShiftTy;
446 struct CoprocOptionOp CoprocOption;
447 struct MBOptOp MBOpt;
448 struct ISBOptOp ISBOpt;
449 struct ITMaskOp ITMask;
450 struct IFlagsOp IFlags;
451 struct MMaskOp MMask;
454 struct VectorListOp VectorList;
455 struct VectorIndexOp VectorIndex;
457 struct MemoryOp Memory;
458 struct PostIdxRegOp PostIdxReg;
459 struct ShifterImmOp ShifterImm;
460 struct RegShiftedRegOp RegShiftedReg;
461 struct RegShiftedImmOp RegShiftedImm;
462 struct RotImmOp RotImm;
463 struct BitfieldOp Bitfield;
466 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
468 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
470 StartLoc = o.StartLoc;
487 case k_DPRRegisterList:
488 case k_SPRRegisterList:
489 Registers = o.Registers;
492 case k_VectorListAllLanes:
493 case k_VectorListIndexed:
494 VectorList = o.VectorList;
501 CoprocOption = o.CoprocOption;
506 case k_MemBarrierOpt:
509 case k_InstSyncBarrierOpt:
514 case k_PostIndexRegister:
515 PostIdxReg = o.PostIdxReg;
523 case k_ShifterImmediate:
524 ShifterImm = o.ShifterImm;
526 case k_ShiftedRegister:
527 RegShiftedReg = o.RegShiftedReg;
529 case k_ShiftedImmediate:
530 RegShiftedImm = o.RegShiftedImm;
532 case k_RotateImmediate:
535 case k_BitfieldDescriptor:
536 Bitfield = o.Bitfield;
539 VectorIndex = o.VectorIndex;
544 /// getStartLoc - Get the location of the first token of this operand.
545 SMLoc getStartLoc() const { return StartLoc; }
546 /// getEndLoc - Get the location of the last token of this operand.
547 SMLoc getEndLoc() const { return EndLoc; }
548 /// getLocRange - Get the range between the first and last token of this
550 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
552 ARMCC::CondCodes getCondCode() const {
553 assert(Kind == k_CondCode && "Invalid access!");
557 unsigned getCoproc() const {
558 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
562 StringRef getToken() const {
563 assert(Kind == k_Token && "Invalid access!");
564 return StringRef(Tok.Data, Tok.Length);
567 unsigned getReg() const {
568 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
572 const SmallVectorImpl<unsigned> &getRegList() const {
573 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
574 Kind == k_SPRRegisterList) && "Invalid access!");
578 const MCExpr *getImm() const {
579 assert(isImm() && "Invalid access!");
583 unsigned getVectorIndex() const {
584 assert(Kind == k_VectorIndex && "Invalid access!");
585 return VectorIndex.Val;
588 ARM_MB::MemBOpt getMemBarrierOpt() const {
589 assert(Kind == k_MemBarrierOpt && "Invalid access!");
593 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
594 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
598 ARM_PROC::IFlags getProcIFlags() const {
599 assert(Kind == k_ProcIFlags && "Invalid access!");
603 unsigned getMSRMask() const {
604 assert(Kind == k_MSRMask && "Invalid access!");
608 bool isCoprocNum() const { return Kind == k_CoprocNum; }
609 bool isCoprocReg() const { return Kind == k_CoprocReg; }
610 bool isCoprocOption() const { return Kind == k_CoprocOption; }
611 bool isCondCode() const { return Kind == k_CondCode; }
612 bool isCCOut() const { return Kind == k_CCOut; }
613 bool isITMask() const { return Kind == k_ITCondMask; }
614 bool isITCondCode() const { return Kind == k_CondCode; }
615 bool isImm() const { return Kind == k_Immediate; }
616 // checks whether this operand is an unsigned offset which fits is a field
617 // of specified width and scaled by a specific number of bits
618 template<unsigned width, unsigned scale>
619 bool isUnsignedOffset() const {
620 if (!isImm()) return false;
621 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
622 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
623 int64_t Val = CE->getValue();
624 int64_t Align = 1LL << scale;
625 int64_t Max = Align * ((1LL << width) - 1);
626 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
630 // checks whether this operand is an signed offset which fits is a field
631 // of specified width and scaled by a specific number of bits
632 template<unsigned width, unsigned scale>
633 bool isSignedOffset() const {
634 if (!isImm()) return false;
635 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
636 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
637 int64_t Val = CE->getValue();
638 int64_t Align = 1LL << scale;
639 int64_t Max = Align * ((1LL << (width-1)) - 1);
640 int64_t Min = -Align * (1LL << (width-1));
641 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
646 // checks whether this operand is a memory operand computed as an offset
647 // applied to PC. the offset may have 8 bits of magnitude and is represented
648 // with two bits of shift. textually it may be either [pc, #imm], #imm or
649 // relocable expression...
650 bool isThumbMemPC() const {
653 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
655 if (!CE) return false;
656 Val = CE->getValue();
659 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
660 if(Memory.BaseRegNum != ARM::PC) return false;
661 Val = Memory.OffsetImm->getValue();
664 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
666 bool isFPImm() const {
667 if (!isImm()) return false;
668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
669 if (!CE) return false;
670 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
673 bool isFBits16() const {
674 if (!isImm()) return false;
675 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
676 if (!CE) return false;
677 int64_t Value = CE->getValue();
678 return Value >= 0 && Value <= 16;
680 bool isFBits32() const {
681 if (!isImm()) return false;
682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
683 if (!CE) return false;
684 int64_t Value = CE->getValue();
685 return Value >= 1 && Value <= 32;
687 bool isImm8s4() const {
688 if (!isImm()) return false;
689 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
690 if (!CE) return false;
691 int64_t Value = CE->getValue();
692 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
694 bool isImm0_1020s4() const {
695 if (!isImm()) return false;
696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
697 if (!CE) return false;
698 int64_t Value = CE->getValue();
699 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
701 bool isImm0_508s4() const {
702 if (!isImm()) return false;
703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
704 if (!CE) return false;
705 int64_t Value = CE->getValue();
706 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
708 bool isImm0_508s4Neg() const {
709 if (!isImm()) return false;
710 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
711 if (!CE) return false;
712 int64_t Value = -CE->getValue();
713 // explicitly exclude zero. we want that to use the normal 0_508 version.
714 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
716 bool isImm0_239() const {
717 if (!isImm()) return false;
718 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
719 if (!CE) return false;
720 int64_t Value = CE->getValue();
721 return Value >= 0 && Value < 240;
723 bool isImm0_255() const {
724 if (!isImm()) return false;
725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
726 if (!CE) return false;
727 int64_t Value = CE->getValue();
728 return Value >= 0 && Value < 256;
730 bool isImm0_4095() const {
731 if (!isImm()) return false;
732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
733 if (!CE) return false;
734 int64_t Value = CE->getValue();
735 return Value >= 0 && Value < 4096;
737 bool isImm0_4095Neg() const {
738 if (!isImm()) return false;
739 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
740 if (!CE) return false;
741 int64_t Value = -CE->getValue();
742 return Value > 0 && Value < 4096;
744 bool isImm0_1() const {
745 if (!isImm()) return false;
746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
747 if (!CE) return false;
748 int64_t Value = CE->getValue();
749 return Value >= 0 && Value < 2;
751 bool isImm0_3() const {
752 if (!isImm()) return false;
753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
754 if (!CE) return false;
755 int64_t Value = CE->getValue();
756 return Value >= 0 && Value < 4;
758 bool isImm0_7() const {
759 if (!isImm()) return false;
760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
761 if (!CE) return false;
762 int64_t Value = CE->getValue();
763 return Value >= 0 && Value < 8;
765 bool isImm0_15() const {
766 if (!isImm()) return false;
767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
768 if (!CE) return false;
769 int64_t Value = CE->getValue();
770 return Value >= 0 && Value < 16;
772 bool isImm0_31() const {
773 if (!isImm()) return false;
774 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
775 if (!CE) return false;
776 int64_t Value = CE->getValue();
777 return Value >= 0 && Value < 32;
779 bool isImm0_63() const {
780 if (!isImm()) return false;
781 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
782 if (!CE) return false;
783 int64_t Value = CE->getValue();
784 return Value >= 0 && Value < 64;
786 bool isImm8() const {
787 if (!isImm()) return false;
788 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
789 if (!CE) return false;
790 int64_t Value = CE->getValue();
793 bool isImm16() const {
794 if (!isImm()) return false;
795 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
796 if (!CE) return false;
797 int64_t Value = CE->getValue();
800 bool isImm32() const {
801 if (!isImm()) return false;
802 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
803 if (!CE) return false;
804 int64_t Value = CE->getValue();
807 bool isShrImm8() const {
808 if (!isImm()) return false;
809 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
810 if (!CE) return false;
811 int64_t Value = CE->getValue();
812 return Value > 0 && Value <= 8;
814 bool isShrImm16() const {
815 if (!isImm()) return false;
816 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
817 if (!CE) return false;
818 int64_t Value = CE->getValue();
819 return Value > 0 && Value <= 16;
821 bool isShrImm32() const {
822 if (!isImm()) return false;
823 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
824 if (!CE) return false;
825 int64_t Value = CE->getValue();
826 return Value > 0 && Value <= 32;
828 bool isShrImm64() const {
829 if (!isImm()) return false;
830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
831 if (!CE) return false;
832 int64_t Value = CE->getValue();
833 return Value > 0 && Value <= 64;
835 bool isImm1_7() const {
836 if (!isImm()) return false;
837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
838 if (!CE) return false;
839 int64_t Value = CE->getValue();
840 return Value > 0 && Value < 8;
842 bool isImm1_15() const {
843 if (!isImm()) return false;
844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
845 if (!CE) return false;
846 int64_t Value = CE->getValue();
847 return Value > 0 && Value < 16;
849 bool isImm1_31() const {
850 if (!isImm()) return false;
851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
852 if (!CE) return false;
853 int64_t Value = CE->getValue();
854 return Value > 0 && Value < 32;
856 bool isImm1_16() const {
857 if (!isImm()) return false;
858 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
859 if (!CE) return false;
860 int64_t Value = CE->getValue();
861 return Value > 0 && Value < 17;
863 bool isImm1_32() const {
864 if (!isImm()) return false;
865 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
866 if (!CE) return false;
867 int64_t Value = CE->getValue();
868 return Value > 0 && Value < 33;
870 bool isImm0_32() const {
871 if (!isImm()) return false;
872 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
873 if (!CE) return false;
874 int64_t Value = CE->getValue();
875 return Value >= 0 && Value < 33;
877 bool isImm0_65535() const {
878 if (!isImm()) return false;
879 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
880 if (!CE) return false;
881 int64_t Value = CE->getValue();
882 return Value >= 0 && Value < 65536;
884 bool isImm256_65535Expr() const {
885 if (!isImm()) return false;
886 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
887 // If it's not a constant expression, it'll generate a fixup and be
889 if (!CE) return true;
890 int64_t Value = CE->getValue();
891 return Value >= 256 && Value < 65536;
893 bool isImm0_65535Expr() const {
894 if (!isImm()) return false;
895 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
896 // If it's not a constant expression, it'll generate a fixup and be
898 if (!CE) return true;
899 int64_t Value = CE->getValue();
900 return Value >= 0 && Value < 65536;
902 bool isImm24bit() const {
903 if (!isImm()) return false;
904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
905 if (!CE) return false;
906 int64_t Value = CE->getValue();
907 return Value >= 0 && Value <= 0xffffff;
909 bool isImmThumbSR() const {
910 if (!isImm()) return false;
911 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
912 if (!CE) return false;
913 int64_t Value = CE->getValue();
914 return Value > 0 && Value < 33;
916 bool isPKHLSLImm() const {
917 if (!isImm()) return false;
918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
919 if (!CE) return false;
920 int64_t Value = CE->getValue();
921 return Value >= 0 && Value < 32;
923 bool isPKHASRImm() const {
924 if (!isImm()) return false;
925 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
926 if (!CE) return false;
927 int64_t Value = CE->getValue();
928 return Value > 0 && Value <= 32;
930 bool isAdrLabel() const {
931 // If we have an immediate that's not a constant, treat it as a label
932 // reference needing a fixup. If it is a constant, but it can't fit
933 // into shift immediate encoding, we reject it.
934 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
935 else return (isARMSOImm() || isARMSOImmNeg());
937 bool isARMSOImm() const {
938 if (!isImm()) return false;
939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
940 if (!CE) return false;
941 int64_t Value = CE->getValue();
942 return ARM_AM::getSOImmVal(Value) != -1;
944 bool isARMSOImmNot() const {
945 if (!isImm()) return false;
946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
947 if (!CE) return false;
948 int64_t Value = CE->getValue();
949 return ARM_AM::getSOImmVal(~Value) != -1;
951 bool isARMSOImmNeg() const {
952 if (!isImm()) return false;
953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
954 if (!CE) return false;
955 int64_t Value = CE->getValue();
956 // Only use this when not representable as a plain so_imm.
957 return ARM_AM::getSOImmVal(Value) == -1 &&
958 ARM_AM::getSOImmVal(-Value) != -1;
960 bool isT2SOImm() const {
961 if (!isImm()) return false;
962 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
963 if (!CE) return false;
964 int64_t Value = CE->getValue();
965 return ARM_AM::getT2SOImmVal(Value) != -1;
967 bool isT2SOImmNot() const {
968 if (!isImm()) return false;
969 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
970 if (!CE) return false;
971 int64_t Value = CE->getValue();
972 return ARM_AM::getT2SOImmVal(Value) == -1 &&
973 ARM_AM::getT2SOImmVal(~Value) != -1;
975 bool isT2SOImmNeg() const {
976 if (!isImm()) return false;
977 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
978 if (!CE) return false;
979 int64_t Value = CE->getValue();
980 // Only use this when not representable as a plain so_imm.
981 return ARM_AM::getT2SOImmVal(Value) == -1 &&
982 ARM_AM::getT2SOImmVal(-Value) != -1;
984 bool isSetEndImm() const {
985 if (!isImm()) return false;
986 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
987 if (!CE) return false;
988 int64_t Value = CE->getValue();
989 return Value == 1 || Value == 0;
991 bool isReg() const { return Kind == k_Register; }
992 bool isRegList() const { return Kind == k_RegisterList; }
993 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
994 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
995 bool isToken() const { return Kind == k_Token; }
996 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
997 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
998 bool isMem() const { return Kind == k_Memory; }
999 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1000 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1001 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1002 bool isRotImm() const { return Kind == k_RotateImmediate; }
1003 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1004 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
1005 bool isPostIdxReg() const {
1006 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
1008 bool isMemNoOffset(bool alignOK = false) const {
1011 // No offset of any kind.
1012 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1013 (alignOK || Memory.Alignment == 0);
1015 bool isMemPCRelImm12() const {
1016 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1018 // Base register must be PC.
1019 if (Memory.BaseRegNum != ARM::PC)
1021 // Immediate offset in range [-4095, 4095].
1022 if (!Memory.OffsetImm) return true;
1023 int64_t Val = Memory.OffsetImm->getValue();
1024 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1026 bool isAlignedMemory() const {
1027 return isMemNoOffset(true);
1029 bool isAddrMode2() const {
1030 if (!isMem() || Memory.Alignment != 0) return false;
1031 // Check for register offset.
1032 if (Memory.OffsetRegNum) return true;
1033 // Immediate offset in range [-4095, 4095].
1034 if (!Memory.OffsetImm) return true;
1035 int64_t Val = Memory.OffsetImm->getValue();
1036 return Val > -4096 && Val < 4096;
1038 bool isAM2OffsetImm() const {
1039 if (!isImm()) return false;
1040 // Immediate offset in range [-4095, 4095].
1041 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1042 if (!CE) return false;
1043 int64_t Val = CE->getValue();
1044 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1046 bool isAddrMode3() const {
1047 // If we have an immediate that's not a constant, treat it as a label
1048 // reference needing a fixup. If it is a constant, it's something else
1049 // and we reject it.
1050 if (isImm() && !isa<MCConstantExpr>(getImm()))
1052 if (!isMem() || Memory.Alignment != 0) return false;
1053 // No shifts are legal for AM3.
1054 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1055 // Check for register offset.
1056 if (Memory.OffsetRegNum) return true;
1057 // Immediate offset in range [-255, 255].
1058 if (!Memory.OffsetImm) return true;
1059 int64_t Val = Memory.OffsetImm->getValue();
1060 // The #-0 offset is encoded as INT32_MIN, and we have to check
1062 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1064 bool isAM3Offset() const {
1065 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1067 if (Kind == k_PostIndexRegister)
1068 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1069 // Immediate offset in range [-255, 255].
1070 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1071 if (!CE) return false;
1072 int64_t Val = CE->getValue();
1073 // Special case, #-0 is INT32_MIN.
1074 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1076 bool isAddrMode5() const {
1077 // If we have an immediate that's not a constant, treat it as a label
1078 // reference needing a fixup. If it is a constant, it's something else
1079 // and we reject it.
1080 if (isImm() && !isa<MCConstantExpr>(getImm()))
1082 if (!isMem() || Memory.Alignment != 0) return false;
1083 // Check for register offset.
1084 if (Memory.OffsetRegNum) return false;
1085 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1086 if (!Memory.OffsetImm) return true;
1087 int64_t Val = Memory.OffsetImm->getValue();
1088 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1091 bool isMemTBB() const {
1092 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1093 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1097 bool isMemTBH() const {
1098 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1099 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1100 Memory.Alignment != 0 )
1104 bool isMemRegOffset() const {
1105 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1109 bool isT2MemRegOffset() const {
1110 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1111 Memory.Alignment != 0)
1113 // Only lsl #{0, 1, 2, 3} allowed.
1114 if (Memory.ShiftType == ARM_AM::no_shift)
1116 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1120 bool isMemThumbRR() const {
1121 // Thumb reg+reg addressing is simple. Just two registers, a base and
1122 // an offset. No shifts, negations or any other complicating factors.
1123 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1124 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1126 return isARMLowRegister(Memory.BaseRegNum) &&
1127 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1129 bool isMemThumbRIs4() const {
1130 if (!isMem() || Memory.OffsetRegNum != 0 ||
1131 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1133 // Immediate offset, multiple of 4 in range [0, 124].
1134 if (!Memory.OffsetImm) return true;
1135 int64_t Val = Memory.OffsetImm->getValue();
1136 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1138 bool isMemThumbRIs2() const {
1139 if (!isMem() || Memory.OffsetRegNum != 0 ||
1140 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1142 // Immediate offset, multiple of 4 in range [0, 62].
1143 if (!Memory.OffsetImm) return true;
1144 int64_t Val = Memory.OffsetImm->getValue();
1145 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1147 bool isMemThumbRIs1() const {
1148 if (!isMem() || Memory.OffsetRegNum != 0 ||
1149 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1151 // Immediate offset in range [0, 31].
1152 if (!Memory.OffsetImm) return true;
1153 int64_t Val = Memory.OffsetImm->getValue();
1154 return Val >= 0 && Val <= 31;
1156 bool isMemThumbSPI() const {
1157 if (!isMem() || Memory.OffsetRegNum != 0 ||
1158 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1160 // Immediate offset, multiple of 4 in range [0, 1020].
1161 if (!Memory.OffsetImm) return true;
1162 int64_t Val = Memory.OffsetImm->getValue();
1163 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1165 bool isMemImm8s4Offset() const {
1166 // If we have an immediate that's not a constant, treat it as a label
1167 // reference needing a fixup. If it is a constant, it's something else
1168 // and we reject it.
1169 if (isImm() && !isa<MCConstantExpr>(getImm()))
1171 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1173 // Immediate offset a multiple of 4 in range [-1020, 1020].
1174 if (!Memory.OffsetImm) return true;
1175 int64_t Val = Memory.OffsetImm->getValue();
1176 // Special case, #-0 is INT32_MIN.
1177 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1179 bool isMemImm0_1020s4Offset() const {
1180 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1182 // Immediate offset a multiple of 4 in range [0, 1020].
1183 if (!Memory.OffsetImm) return true;
1184 int64_t Val = Memory.OffsetImm->getValue();
1185 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1187 bool isMemImm8Offset() const {
1188 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1190 // Base reg of PC isn't allowed for these encodings.
1191 if (Memory.BaseRegNum == ARM::PC) return false;
1192 // Immediate offset in range [-255, 255].
1193 if (!Memory.OffsetImm) return true;
1194 int64_t Val = Memory.OffsetImm->getValue();
1195 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1197 bool isMemPosImm8Offset() const {
1198 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1200 // Immediate offset in range [0, 255].
1201 if (!Memory.OffsetImm) return true;
1202 int64_t Val = Memory.OffsetImm->getValue();
1203 return Val >= 0 && Val < 256;
1205 bool isMemNegImm8Offset() const {
1206 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1208 // Base reg of PC isn't allowed for these encodings.
1209 if (Memory.BaseRegNum == ARM::PC) return false;
1210 // Immediate offset in range [-255, -1].
1211 if (!Memory.OffsetImm) return false;
1212 int64_t Val = Memory.OffsetImm->getValue();
1213 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1215 bool isMemUImm12Offset() const {
1216 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1218 // Immediate offset in range [0, 4095].
1219 if (!Memory.OffsetImm) return true;
1220 int64_t Val = Memory.OffsetImm->getValue();
1221 return (Val >= 0 && Val < 4096);
1223 bool isMemImm12Offset() const {
1224 // If we have an immediate that's not a constant, treat it as a label
1225 // reference needing a fixup. If it is a constant, it's something else
1226 // and we reject it.
1227 if (isImm() && !isa<MCConstantExpr>(getImm()))
1230 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1232 // Immediate offset in range [-4095, 4095].
1233 if (!Memory.OffsetImm) return true;
1234 int64_t Val = Memory.OffsetImm->getValue();
1235 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1237 bool isPostIdxImm8() const {
1238 if (!isImm()) return false;
1239 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1240 if (!CE) return false;
1241 int64_t Val = CE->getValue();
1242 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1244 bool isPostIdxImm8s4() const {
1245 if (!isImm()) return false;
1246 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1247 if (!CE) return false;
1248 int64_t Val = CE->getValue();
1249 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1253 bool isMSRMask() const { return Kind == k_MSRMask; }
1254 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1257 bool isSingleSpacedVectorList() const {
1258 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1260 bool isDoubleSpacedVectorList() const {
1261 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1263 bool isVecListOneD() const {
1264 if (!isSingleSpacedVectorList()) return false;
1265 return VectorList.Count == 1;
1268 bool isVecListDPair() const {
1269 if (!isSingleSpacedVectorList()) return false;
1270 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1271 .contains(VectorList.RegNum));
1274 bool isVecListThreeD() const {
1275 if (!isSingleSpacedVectorList()) return false;
1276 return VectorList.Count == 3;
1279 bool isVecListFourD() const {
1280 if (!isSingleSpacedVectorList()) return false;
1281 return VectorList.Count == 4;
1284 bool isVecListDPairSpaced() const {
1285 if (isSingleSpacedVectorList()) return false;
1286 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1287 .contains(VectorList.RegNum));
1290 bool isVecListThreeQ() const {
1291 if (!isDoubleSpacedVectorList()) return false;
1292 return VectorList.Count == 3;
1295 bool isVecListFourQ() const {
1296 if (!isDoubleSpacedVectorList()) return false;
1297 return VectorList.Count == 4;
1300 bool isSingleSpacedVectorAllLanes() const {
1301 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1303 bool isDoubleSpacedVectorAllLanes() const {
1304 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1306 bool isVecListOneDAllLanes() const {
1307 if (!isSingleSpacedVectorAllLanes()) return false;
1308 return VectorList.Count == 1;
1311 bool isVecListDPairAllLanes() const {
1312 if (!isSingleSpacedVectorAllLanes()) return false;
1313 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1314 .contains(VectorList.RegNum));
1317 bool isVecListDPairSpacedAllLanes() const {
1318 if (!isDoubleSpacedVectorAllLanes()) return false;
1319 return VectorList.Count == 2;
1322 bool isVecListThreeDAllLanes() const {
1323 if (!isSingleSpacedVectorAllLanes()) return false;
1324 return VectorList.Count == 3;
1327 bool isVecListThreeQAllLanes() const {
1328 if (!isDoubleSpacedVectorAllLanes()) return false;
1329 return VectorList.Count == 3;
1332 bool isVecListFourDAllLanes() const {
1333 if (!isSingleSpacedVectorAllLanes()) return false;
1334 return VectorList.Count == 4;
1337 bool isVecListFourQAllLanes() const {
1338 if (!isDoubleSpacedVectorAllLanes()) return false;
1339 return VectorList.Count == 4;
1342 bool isSingleSpacedVectorIndexed() const {
1343 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1345 bool isDoubleSpacedVectorIndexed() const {
1346 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1348 bool isVecListOneDByteIndexed() const {
1349 if (!isSingleSpacedVectorIndexed()) return false;
1350 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1353 bool isVecListOneDHWordIndexed() const {
1354 if (!isSingleSpacedVectorIndexed()) return false;
1355 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1358 bool isVecListOneDWordIndexed() const {
1359 if (!isSingleSpacedVectorIndexed()) return false;
1360 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1363 bool isVecListTwoDByteIndexed() const {
1364 if (!isSingleSpacedVectorIndexed()) return false;
1365 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1368 bool isVecListTwoDHWordIndexed() const {
1369 if (!isSingleSpacedVectorIndexed()) return false;
1370 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1373 bool isVecListTwoQWordIndexed() const {
1374 if (!isDoubleSpacedVectorIndexed()) return false;
1375 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1378 bool isVecListTwoQHWordIndexed() const {
1379 if (!isDoubleSpacedVectorIndexed()) return false;
1380 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1383 bool isVecListTwoDWordIndexed() const {
1384 if (!isSingleSpacedVectorIndexed()) return false;
1385 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1388 bool isVecListThreeDByteIndexed() const {
1389 if (!isSingleSpacedVectorIndexed()) return false;
1390 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1393 bool isVecListThreeDHWordIndexed() const {
1394 if (!isSingleSpacedVectorIndexed()) return false;
1395 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1398 bool isVecListThreeQWordIndexed() const {
1399 if (!isDoubleSpacedVectorIndexed()) return false;
1400 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1403 bool isVecListThreeQHWordIndexed() const {
1404 if (!isDoubleSpacedVectorIndexed()) return false;
1405 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1408 bool isVecListThreeDWordIndexed() const {
1409 if (!isSingleSpacedVectorIndexed()) return false;
1410 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1413 bool isVecListFourDByteIndexed() const {
1414 if (!isSingleSpacedVectorIndexed()) return false;
1415 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1418 bool isVecListFourDHWordIndexed() const {
1419 if (!isSingleSpacedVectorIndexed()) return false;
1420 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1423 bool isVecListFourQWordIndexed() const {
1424 if (!isDoubleSpacedVectorIndexed()) return false;
1425 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1428 bool isVecListFourQHWordIndexed() const {
1429 if (!isDoubleSpacedVectorIndexed()) return false;
1430 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1433 bool isVecListFourDWordIndexed() const {
1434 if (!isSingleSpacedVectorIndexed()) return false;
1435 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1438 bool isVectorIndex8() const {
1439 if (Kind != k_VectorIndex) return false;
1440 return VectorIndex.Val < 8;
1442 bool isVectorIndex16() const {
1443 if (Kind != k_VectorIndex) return false;
1444 return VectorIndex.Val < 4;
1446 bool isVectorIndex32() const {
1447 if (Kind != k_VectorIndex) return false;
1448 return VectorIndex.Val < 2;
1451 bool isNEONi8splat() const {
1452 if (!isImm()) return false;
1453 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1454 // Must be a constant.
1455 if (!CE) return false;
1456 int64_t Value = CE->getValue();
1457 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1459 return Value >= 0 && Value < 256;
1462 bool isNEONi16splat() 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 // i16 value in the range [0,255] or [0x0100, 0xff00]
1469 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1472 bool isNEONi32splat() const {
1473 if (!isImm()) return false;
1474 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1475 // Must be a constant.
1476 if (!CE) return false;
1477 int64_t Value = CE->getValue();
1478 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1479 return (Value >= 0 && Value < 256) ||
1480 (Value >= 0x0100 && Value <= 0xff00) ||
1481 (Value >= 0x010000 && Value <= 0xff0000) ||
1482 (Value >= 0x01000000 && Value <= 0xff000000);
1485 bool isNEONi32vmov() const {
1486 if (!isImm()) return false;
1487 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1488 // Must be a constant.
1489 if (!CE) return false;
1490 int64_t Value = CE->getValue();
1491 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1492 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1493 return (Value >= 0 && Value < 256) ||
1494 (Value >= 0x0100 && Value <= 0xff00) ||
1495 (Value >= 0x010000 && Value <= 0xff0000) ||
1496 (Value >= 0x01000000 && Value <= 0xff000000) ||
1497 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1498 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1500 bool isNEONi32vmovNeg() const {
1501 if (!isImm()) return false;
1502 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1503 // Must be a constant.
1504 if (!CE) return false;
1505 int64_t Value = ~CE->getValue();
1506 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1507 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1508 return (Value >= 0 && Value < 256) ||
1509 (Value >= 0x0100 && Value <= 0xff00) ||
1510 (Value >= 0x010000 && Value <= 0xff0000) ||
1511 (Value >= 0x01000000 && Value <= 0xff000000) ||
1512 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1513 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1516 bool isNEONi64splat() const {
1517 if (!isImm()) return false;
1518 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1519 // Must be a constant.
1520 if (!CE) return false;
1521 uint64_t Value = CE->getValue();
1522 // i64 value with each byte being either 0 or 0xff.
1523 for (unsigned i = 0; i < 8; ++i)
1524 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1528 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1529 // Add as immediates when possible. Null MCExpr = 0.
1531 Inst.addOperand(MCOperand::CreateImm(0));
1532 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1533 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1535 Inst.addOperand(MCOperand::CreateExpr(Expr));
1538 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1539 assert(N == 2 && "Invalid number of operands!");
1540 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1541 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1542 Inst.addOperand(MCOperand::CreateReg(RegNum));
1545 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1546 assert(N == 1 && "Invalid number of operands!");
1547 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1550 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1551 assert(N == 1 && "Invalid number of operands!");
1552 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1555 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1556 assert(N == 1 && "Invalid number of operands!");
1557 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1560 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1561 assert(N == 1 && "Invalid number of operands!");
1562 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1565 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1566 assert(N == 1 && "Invalid number of operands!");
1567 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1570 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1571 assert(N == 1 && "Invalid number of operands!");
1572 Inst.addOperand(MCOperand::CreateReg(getReg()));
1575 void addRegOperands(MCInst &Inst, unsigned N) const {
1576 assert(N == 1 && "Invalid number of operands!");
1577 Inst.addOperand(MCOperand::CreateReg(getReg()));
1580 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1581 assert(N == 3 && "Invalid number of operands!");
1582 assert(isRegShiftedReg() &&
1583 "addRegShiftedRegOperands() on non RegShiftedReg!");
1584 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1585 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1586 Inst.addOperand(MCOperand::CreateImm(
1587 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1590 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1591 assert(N == 2 && "Invalid number of operands!");
1592 assert(isRegShiftedImm() &&
1593 "addRegShiftedImmOperands() on non RegShiftedImm!");
1594 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1595 // Shift of #32 is encoded as 0 where permitted
1596 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1597 Inst.addOperand(MCOperand::CreateImm(
1598 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1601 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1602 assert(N == 1 && "Invalid number of operands!");
1603 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1607 void addRegListOperands(MCInst &Inst, unsigned N) const {
1608 assert(N == 1 && "Invalid number of operands!");
1609 const SmallVectorImpl<unsigned> &RegList = getRegList();
1610 for (SmallVectorImpl<unsigned>::const_iterator
1611 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1612 Inst.addOperand(MCOperand::CreateReg(*I));
1615 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1616 addRegListOperands(Inst, N);
1619 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1620 addRegListOperands(Inst, N);
1623 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1624 assert(N == 1 && "Invalid number of operands!");
1625 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1626 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1629 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1630 assert(N == 1 && "Invalid number of operands!");
1631 // Munge the lsb/width into a bitfield mask.
1632 unsigned lsb = Bitfield.LSB;
1633 unsigned width = Bitfield.Width;
1634 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1635 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1636 (32 - (lsb + width)));
1637 Inst.addOperand(MCOperand::CreateImm(Mask));
1640 void addImmOperands(MCInst &Inst, unsigned N) const {
1641 assert(N == 1 && "Invalid number of operands!");
1642 addExpr(Inst, getImm());
1645 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1646 assert(N == 1 && "Invalid number of operands!");
1647 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1648 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1651 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1652 assert(N == 1 && "Invalid number of operands!");
1653 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1654 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1657 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1658 assert(N == 1 && "Invalid number of operands!");
1659 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1660 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1661 Inst.addOperand(MCOperand::CreateImm(Val));
1664 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1665 assert(N == 1 && "Invalid number of operands!");
1666 // FIXME: We really want to scale the value here, but the LDRD/STRD
1667 // instruction don't encode operands that way yet.
1668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1669 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1672 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1673 assert(N == 1 && "Invalid number of operands!");
1674 // The immediate is scaled by four in the encoding and is stored
1675 // in the MCInst as such. Lop off the low two bits here.
1676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1677 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1680 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1681 assert(N == 1 && "Invalid number of operands!");
1682 // The immediate is scaled by four in the encoding and is stored
1683 // in the MCInst as such. Lop off the low two bits here.
1684 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1685 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1688 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1689 assert(N == 1 && "Invalid number of operands!");
1690 // The immediate is scaled by four in the encoding and is stored
1691 // in the MCInst as such. Lop off the low two bits here.
1692 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1693 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1696 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1697 assert(N == 1 && "Invalid number of operands!");
1698 // The constant encodes as the immediate-1, and we store in the instruction
1699 // the bits as encoded, so subtract off one here.
1700 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1701 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1704 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1705 assert(N == 1 && "Invalid number of operands!");
1706 // The constant encodes as the immediate-1, and we store in the instruction
1707 // the bits as encoded, so subtract off one here.
1708 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1709 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1712 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1713 assert(N == 1 && "Invalid number of operands!");
1714 // The constant encodes as the immediate, except for 32, which encodes as
1716 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1717 unsigned Imm = CE->getValue();
1718 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1721 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1722 assert(N == 1 && "Invalid number of operands!");
1723 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1724 // the instruction as well.
1725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1726 int Val = CE->getValue();
1727 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1730 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1731 assert(N == 1 && "Invalid number of operands!");
1732 // The operand is actually a t2_so_imm, but we have its bitwise
1733 // negation in the assembly source, so twiddle it here.
1734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1735 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1738 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1739 assert(N == 1 && "Invalid number of operands!");
1740 // The operand is actually a t2_so_imm, but we have its
1741 // negation in the assembly source, so twiddle it here.
1742 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1743 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1746 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1747 assert(N == 1 && "Invalid number of operands!");
1748 // The operand is actually an imm0_4095, but we have its
1749 // negation in the assembly source, so twiddle it here.
1750 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1751 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1754 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1755 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1756 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1760 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1761 assert(SR && "Unknown value type!");
1762 Inst.addOperand(MCOperand::CreateExpr(SR));
1765 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1766 assert(N == 1 && "Invalid number of operands!");
1768 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1770 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1774 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1775 assert(SR && "Unknown value type!");
1776 Inst.addOperand(MCOperand::CreateExpr(SR));
1780 assert(isMem() && "Unknown value type!");
1781 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1782 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1785 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1786 assert(N == 1 && "Invalid number of operands!");
1787 // The operand is actually a so_imm, but we have its bitwise
1788 // negation in the assembly source, so twiddle it here.
1789 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1790 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1793 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1794 assert(N == 1 && "Invalid number of operands!");
1795 // The operand is actually a so_imm, but we have its
1796 // negation in the assembly source, so twiddle it here.
1797 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1798 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1801 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1802 assert(N == 1 && "Invalid number of operands!");
1803 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1806 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1807 assert(N == 1 && "Invalid number of operands!");
1808 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1811 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1812 assert(N == 1 && "Invalid number of operands!");
1813 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1816 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1817 assert(N == 1 && "Invalid number of operands!");
1818 int32_t Imm = Memory.OffsetImm->getValue();
1819 Inst.addOperand(MCOperand::CreateImm(Imm));
1822 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1823 assert(N == 1 && "Invalid number of operands!");
1824 assert(isImm() && "Not an immediate!");
1826 // If we have an immediate that's not a constant, treat it as a label
1827 // reference needing a fixup.
1828 if (!isa<MCConstantExpr>(getImm())) {
1829 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1833 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1834 int Val = CE->getValue();
1835 Inst.addOperand(MCOperand::CreateImm(Val));
1838 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1839 assert(N == 2 && "Invalid number of operands!");
1840 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1841 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1844 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1845 assert(N == 3 && "Invalid number of operands!");
1846 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1847 if (!Memory.OffsetRegNum) {
1848 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1849 // Special case for #-0
1850 if (Val == INT32_MIN) Val = 0;
1851 if (Val < 0) Val = -Val;
1852 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1854 // For register offset, we encode the shift type and negation flag
1856 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1857 Memory.ShiftImm, Memory.ShiftType);
1859 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1860 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1861 Inst.addOperand(MCOperand::CreateImm(Val));
1864 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1865 assert(N == 2 && "Invalid number of operands!");
1866 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1867 assert(CE && "non-constant AM2OffsetImm operand!");
1868 int32_t Val = CE->getValue();
1869 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1870 // Special case for #-0
1871 if (Val == INT32_MIN) Val = 0;
1872 if (Val < 0) Val = -Val;
1873 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1874 Inst.addOperand(MCOperand::CreateReg(0));
1875 Inst.addOperand(MCOperand::CreateImm(Val));
1878 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1879 assert(N == 3 && "Invalid number of operands!");
1880 // If we have an immediate that's not a constant, treat it as a label
1881 // reference needing a fixup. If it is a constant, it's something else
1882 // and we reject it.
1884 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1885 Inst.addOperand(MCOperand::CreateReg(0));
1886 Inst.addOperand(MCOperand::CreateImm(0));
1890 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1891 if (!Memory.OffsetRegNum) {
1892 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1893 // Special case for #-0
1894 if (Val == INT32_MIN) Val = 0;
1895 if (Val < 0) Val = -Val;
1896 Val = ARM_AM::getAM3Opc(AddSub, Val);
1898 // For register offset, we encode the shift type and negation flag
1900 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1902 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1903 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1904 Inst.addOperand(MCOperand::CreateImm(Val));
1907 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1908 assert(N == 2 && "Invalid number of operands!");
1909 if (Kind == k_PostIndexRegister) {
1911 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1912 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1913 Inst.addOperand(MCOperand::CreateImm(Val));
1918 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1919 int32_t Val = CE->getValue();
1920 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1921 // Special case for #-0
1922 if (Val == INT32_MIN) Val = 0;
1923 if (Val < 0) Val = -Val;
1924 Val = ARM_AM::getAM3Opc(AddSub, Val);
1925 Inst.addOperand(MCOperand::CreateReg(0));
1926 Inst.addOperand(MCOperand::CreateImm(Val));
1929 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1930 assert(N == 2 && "Invalid number of operands!");
1931 // If we have an immediate that's not a constant, treat it as a label
1932 // reference needing a fixup. If it is a constant, it's something else
1933 // and we reject it.
1935 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1936 Inst.addOperand(MCOperand::CreateImm(0));
1940 // The lower two bits are always zero and as such are not encoded.
1941 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1942 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1943 // Special case for #-0
1944 if (Val == INT32_MIN) Val = 0;
1945 if (Val < 0) Val = -Val;
1946 Val = ARM_AM::getAM5Opc(AddSub, Val);
1947 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1948 Inst.addOperand(MCOperand::CreateImm(Val));
1951 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1952 assert(N == 2 && "Invalid number of operands!");
1953 // If we have an immediate that's not a constant, treat it as a label
1954 // reference needing a fixup. If it is a constant, it's something else
1955 // and we reject it.
1957 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1958 Inst.addOperand(MCOperand::CreateImm(0));
1962 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1963 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1964 Inst.addOperand(MCOperand::CreateImm(Val));
1967 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1968 assert(N == 2 && "Invalid number of operands!");
1969 // The lower two bits are always zero and as such are not encoded.
1970 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1971 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1972 Inst.addOperand(MCOperand::CreateImm(Val));
1975 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1976 assert(N == 2 && "Invalid number of operands!");
1977 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1978 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1979 Inst.addOperand(MCOperand::CreateImm(Val));
1982 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1983 addMemImm8OffsetOperands(Inst, N);
1986 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1987 addMemImm8OffsetOperands(Inst, N);
1990 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1991 assert(N == 2 && "Invalid number of operands!");
1992 // If this is an immediate, it's a label reference.
1994 addExpr(Inst, getImm());
1995 Inst.addOperand(MCOperand::CreateImm(0));
1999 // Otherwise, it's a normal memory reg+offset.
2000 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2001 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2002 Inst.addOperand(MCOperand::CreateImm(Val));
2005 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2006 assert(N == 2 && "Invalid number of operands!");
2007 // If this is an immediate, it's a label reference.
2009 addExpr(Inst, getImm());
2010 Inst.addOperand(MCOperand::CreateImm(0));
2014 // Otherwise, it's a normal memory reg+offset.
2015 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2016 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2017 Inst.addOperand(MCOperand::CreateImm(Val));
2020 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2021 assert(N == 2 && "Invalid number of operands!");
2022 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2023 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2026 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2027 assert(N == 2 && "Invalid number of operands!");
2028 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2029 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2032 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2033 assert(N == 3 && "Invalid number of operands!");
2035 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2036 Memory.ShiftImm, Memory.ShiftType);
2037 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2038 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2039 Inst.addOperand(MCOperand::CreateImm(Val));
2042 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2043 assert(N == 3 && "Invalid number of operands!");
2044 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2045 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2046 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2049 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2050 assert(N == 2 && "Invalid number of operands!");
2051 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2052 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2055 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2056 assert(N == 2 && "Invalid number of operands!");
2057 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2058 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2059 Inst.addOperand(MCOperand::CreateImm(Val));
2062 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2063 assert(N == 2 && "Invalid number of operands!");
2064 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2065 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2066 Inst.addOperand(MCOperand::CreateImm(Val));
2069 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2070 assert(N == 2 && "Invalid number of operands!");
2071 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2072 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2073 Inst.addOperand(MCOperand::CreateImm(Val));
2076 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2077 assert(N == 2 && "Invalid number of operands!");
2078 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2079 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2080 Inst.addOperand(MCOperand::CreateImm(Val));
2083 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2084 assert(N == 1 && "Invalid number of operands!");
2085 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2086 assert(CE && "non-constant post-idx-imm8 operand!");
2087 int Imm = CE->getValue();
2088 bool isAdd = Imm >= 0;
2089 if (Imm == INT32_MIN) Imm = 0;
2090 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2091 Inst.addOperand(MCOperand::CreateImm(Imm));
2094 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2095 assert(N == 1 && "Invalid number of operands!");
2096 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2097 assert(CE && "non-constant post-idx-imm8s4 operand!");
2098 int Imm = CE->getValue();
2099 bool isAdd = Imm >= 0;
2100 if (Imm == INT32_MIN) Imm = 0;
2101 // Immediate is scaled by 4.
2102 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2103 Inst.addOperand(MCOperand::CreateImm(Imm));
2106 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2107 assert(N == 2 && "Invalid number of operands!");
2108 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2109 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2112 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2113 assert(N == 2 && "Invalid number of operands!");
2114 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2115 // The sign, shift type, and shift amount are encoded in a single operand
2116 // using the AM2 encoding helpers.
2117 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2118 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2119 PostIdxReg.ShiftTy);
2120 Inst.addOperand(MCOperand::CreateImm(Imm));
2123 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2124 assert(N == 1 && "Invalid number of operands!");
2125 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2128 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2129 assert(N == 1 && "Invalid number of operands!");
2130 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2133 void addVecListOperands(MCInst &Inst, unsigned N) const {
2134 assert(N == 1 && "Invalid number of operands!");
2135 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2138 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2139 assert(N == 2 && "Invalid number of operands!");
2140 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2141 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2144 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2145 assert(N == 1 && "Invalid number of operands!");
2146 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2149 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2150 assert(N == 1 && "Invalid number of operands!");
2151 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2154 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2155 assert(N == 1 && "Invalid number of operands!");
2156 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2159 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2160 assert(N == 1 && "Invalid number of operands!");
2161 // The immediate encodes the type of constant as well as the value.
2162 // Mask in that this is an i8 splat.
2163 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2164 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2167 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2168 assert(N == 1 && "Invalid number of operands!");
2169 // The immediate encodes the type of constant as well as the value.
2170 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2171 unsigned Value = CE->getValue();
2173 Value = (Value >> 8) | 0xa00;
2176 Inst.addOperand(MCOperand::CreateImm(Value));
2179 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2180 assert(N == 1 && "Invalid number of operands!");
2181 // The immediate encodes the type of constant as well as the value.
2182 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2183 unsigned Value = CE->getValue();
2184 if (Value >= 256 && Value <= 0xff00)
2185 Value = (Value >> 8) | 0x200;
2186 else if (Value > 0xffff && Value <= 0xff0000)
2187 Value = (Value >> 16) | 0x400;
2188 else if (Value > 0xffffff)
2189 Value = (Value >> 24) | 0x600;
2190 Inst.addOperand(MCOperand::CreateImm(Value));
2193 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2194 assert(N == 1 && "Invalid number of operands!");
2195 // The immediate encodes the type of constant as well as the value.
2196 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2197 unsigned Value = CE->getValue();
2198 if (Value >= 256 && Value <= 0xffff)
2199 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2200 else if (Value > 0xffff && Value <= 0xffffff)
2201 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2202 else if (Value > 0xffffff)
2203 Value = (Value >> 24) | 0x600;
2204 Inst.addOperand(MCOperand::CreateImm(Value));
2207 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2208 assert(N == 1 && "Invalid number of operands!");
2209 // The immediate encodes the type of constant as well as the value.
2210 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2211 unsigned Value = ~CE->getValue();
2212 if (Value >= 256 && Value <= 0xffff)
2213 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2214 else if (Value > 0xffff && Value <= 0xffffff)
2215 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2216 else if (Value > 0xffffff)
2217 Value = (Value >> 24) | 0x600;
2218 Inst.addOperand(MCOperand::CreateImm(Value));
2221 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2222 assert(N == 1 && "Invalid number of operands!");
2223 // The immediate encodes the type of constant as well as the value.
2224 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2225 uint64_t Value = CE->getValue();
2227 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2228 Imm |= (Value & 1) << i;
2230 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2233 virtual void print(raw_ostream &OS) const;
2235 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2236 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2237 Op->ITMask.Mask = Mask;
2243 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2244 ARMOperand *Op = new ARMOperand(k_CondCode);
2251 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2252 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2253 Op->Cop.Val = CopVal;
2259 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2260 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2261 Op->Cop.Val = CopVal;
2267 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2268 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2275 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2276 ARMOperand *Op = new ARMOperand(k_CCOut);
2277 Op->Reg.RegNum = RegNum;
2283 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2284 ARMOperand *Op = new ARMOperand(k_Token);
2285 Op->Tok.Data = Str.data();
2286 Op->Tok.Length = Str.size();
2292 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2293 ARMOperand *Op = new ARMOperand(k_Register);
2294 Op->Reg.RegNum = RegNum;
2300 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2305 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2306 Op->RegShiftedReg.ShiftTy = ShTy;
2307 Op->RegShiftedReg.SrcReg = SrcReg;
2308 Op->RegShiftedReg.ShiftReg = ShiftReg;
2309 Op->RegShiftedReg.ShiftImm = ShiftImm;
2315 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2319 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2320 Op->RegShiftedImm.ShiftTy = ShTy;
2321 Op->RegShiftedImm.SrcReg = SrcReg;
2322 Op->RegShiftedImm.ShiftImm = ShiftImm;
2328 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2330 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2331 Op->ShifterImm.isASR = isASR;
2332 Op->ShifterImm.Imm = Imm;
2338 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2339 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2340 Op->RotImm.Imm = Imm;
2346 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2348 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2349 Op->Bitfield.LSB = LSB;
2350 Op->Bitfield.Width = Width;
2357 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2358 SMLoc StartLoc, SMLoc EndLoc) {
2359 assert (Regs.size() > 0 && "RegList contains no registers?");
2360 KindTy Kind = k_RegisterList;
2362 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2363 Kind = k_DPRRegisterList;
2364 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2365 contains(Regs.front().second))
2366 Kind = k_SPRRegisterList;
2368 // Sort based on the register encoding values.
2369 array_pod_sort(Regs.begin(), Regs.end());
2371 ARMOperand *Op = new ARMOperand(Kind);
2372 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2373 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2374 Op->Registers.push_back(I->second);
2375 Op->StartLoc = StartLoc;
2376 Op->EndLoc = EndLoc;
2380 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2381 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2382 ARMOperand *Op = new ARMOperand(k_VectorList);
2383 Op->VectorList.RegNum = RegNum;
2384 Op->VectorList.Count = Count;
2385 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2391 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2392 bool isDoubleSpaced,
2394 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2395 Op->VectorList.RegNum = RegNum;
2396 Op->VectorList.Count = Count;
2397 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2403 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2405 bool isDoubleSpaced,
2407 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2408 Op->VectorList.RegNum = RegNum;
2409 Op->VectorList.Count = Count;
2410 Op->VectorList.LaneIndex = Index;
2411 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2417 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2419 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2420 Op->VectorIndex.Val = Idx;
2426 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2427 ARMOperand *Op = new ARMOperand(k_Immediate);
2434 static ARMOperand *CreateMem(unsigned BaseRegNum,
2435 const MCConstantExpr *OffsetImm,
2436 unsigned OffsetRegNum,
2437 ARM_AM::ShiftOpc ShiftType,
2442 ARMOperand *Op = new ARMOperand(k_Memory);
2443 Op->Memory.BaseRegNum = BaseRegNum;
2444 Op->Memory.OffsetImm = OffsetImm;
2445 Op->Memory.OffsetRegNum = OffsetRegNum;
2446 Op->Memory.ShiftType = ShiftType;
2447 Op->Memory.ShiftImm = ShiftImm;
2448 Op->Memory.Alignment = Alignment;
2449 Op->Memory.isNegative = isNegative;
2455 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2456 ARM_AM::ShiftOpc ShiftTy,
2459 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2460 Op->PostIdxReg.RegNum = RegNum;
2461 Op->PostIdxReg.isAdd = isAdd;
2462 Op->PostIdxReg.ShiftTy = ShiftTy;
2463 Op->PostIdxReg.ShiftImm = ShiftImm;
2469 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2470 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2471 Op->MBOpt.Val = Opt;
2477 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2479 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2480 Op->ISBOpt.Val = Opt;
2486 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2487 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2488 Op->IFlags.Val = IFlags;
2494 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2495 ARMOperand *Op = new ARMOperand(k_MSRMask);
2496 Op->MMask.Val = MMask;
2503 } // end anonymous namespace.
2505 void ARMOperand::print(raw_ostream &OS) const {
2508 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2511 OS << "<ccout " << getReg() << ">";
2513 case k_ITCondMask: {
2514 static const char *const MaskStr[] = {
2515 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2516 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2518 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2519 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2523 OS << "<coprocessor number: " << getCoproc() << ">";
2526 OS << "<coprocessor register: " << getCoproc() << ">";
2528 case k_CoprocOption:
2529 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2532 OS << "<mask: " << getMSRMask() << ">";
2535 getImm()->print(OS);
2537 case k_MemBarrierOpt:
2538 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2540 case k_InstSyncBarrierOpt:
2541 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2545 << " base:" << Memory.BaseRegNum;
2548 case k_PostIndexRegister:
2549 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2550 << PostIdxReg.RegNum;
2551 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2552 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2553 << PostIdxReg.ShiftImm;
2556 case k_ProcIFlags: {
2557 OS << "<ARM_PROC::";
2558 unsigned IFlags = getProcIFlags();
2559 for (int i=2; i >= 0; --i)
2560 if (IFlags & (1 << i))
2561 OS << ARM_PROC::IFlagsToString(1 << i);
2566 OS << "<register " << getReg() << ">";
2568 case k_ShifterImmediate:
2569 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2570 << " #" << ShifterImm.Imm << ">";
2572 case k_ShiftedRegister:
2573 OS << "<so_reg_reg "
2574 << RegShiftedReg.SrcReg << " "
2575 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2576 << " " << RegShiftedReg.ShiftReg << ">";
2578 case k_ShiftedImmediate:
2579 OS << "<so_reg_imm "
2580 << RegShiftedImm.SrcReg << " "
2581 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2582 << " #" << RegShiftedImm.ShiftImm << ">";
2584 case k_RotateImmediate:
2585 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2587 case k_BitfieldDescriptor:
2588 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2589 << ", width: " << Bitfield.Width << ">";
2591 case k_RegisterList:
2592 case k_DPRRegisterList:
2593 case k_SPRRegisterList: {
2594 OS << "<register_list ";
2596 const SmallVectorImpl<unsigned> &RegList = getRegList();
2597 for (SmallVectorImpl<unsigned>::const_iterator
2598 I = RegList.begin(), E = RegList.end(); I != E; ) {
2600 if (++I < E) OS << ", ";
2607 OS << "<vector_list " << VectorList.Count << " * "
2608 << VectorList.RegNum << ">";
2610 case k_VectorListAllLanes:
2611 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2612 << VectorList.RegNum << ">";
2614 case k_VectorListIndexed:
2615 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2616 << VectorList.Count << " * " << VectorList.RegNum << ">";
2619 OS << "'" << getToken() << "'";
2622 OS << "<vectorindex " << getVectorIndex() << ">";
2627 /// @name Auto-generated Match Functions
2630 static unsigned MatchRegisterName(StringRef Name);
2634 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2635 SMLoc &StartLoc, SMLoc &EndLoc) {
2636 StartLoc = Parser.getTok().getLoc();
2637 EndLoc = Parser.getTok().getEndLoc();
2638 RegNo = tryParseRegister();
2640 return (RegNo == (unsigned)-1);
2643 /// Try to parse a register name. The token must be an Identifier when called,
2644 /// and if it is a register name the token is eaten and the register number is
2645 /// returned. Otherwise return -1.
2647 int ARMAsmParser::tryParseRegister() {
2648 const AsmToken &Tok = Parser.getTok();
2649 if (Tok.isNot(AsmToken::Identifier)) return -1;
2651 std::string lowerCase = Tok.getString().lower();
2652 unsigned RegNum = MatchRegisterName(lowerCase);
2654 RegNum = StringSwitch<unsigned>(lowerCase)
2655 .Case("r13", ARM::SP)
2656 .Case("r14", ARM::LR)
2657 .Case("r15", ARM::PC)
2658 .Case("ip", ARM::R12)
2659 // Additional register name aliases for 'gas' compatibility.
2660 .Case("a1", ARM::R0)
2661 .Case("a2", ARM::R1)
2662 .Case("a3", ARM::R2)
2663 .Case("a4", ARM::R3)
2664 .Case("v1", ARM::R4)
2665 .Case("v2", ARM::R5)
2666 .Case("v3", ARM::R6)
2667 .Case("v4", ARM::R7)
2668 .Case("v5", ARM::R8)
2669 .Case("v6", ARM::R9)
2670 .Case("v7", ARM::R10)
2671 .Case("v8", ARM::R11)
2672 .Case("sb", ARM::R9)
2673 .Case("sl", ARM::R10)
2674 .Case("fp", ARM::R11)
2678 // Check for aliases registered via .req. Canonicalize to lower case.
2679 // That's more consistent since register names are case insensitive, and
2680 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2681 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2682 // If no match, return failure.
2683 if (Entry == RegisterReqs.end())
2685 Parser.Lex(); // Eat identifier token.
2686 return Entry->getValue();
2689 Parser.Lex(); // Eat identifier token.
2694 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2695 // If a recoverable error occurs, return 1. If an irrecoverable error
2696 // occurs, return -1. An irrecoverable error is one where tokens have been
2697 // consumed in the process of trying to parse the shifter (i.e., when it is
2698 // indeed a shifter operand, but malformed).
2699 int ARMAsmParser::tryParseShiftRegister(
2700 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2701 SMLoc S = Parser.getTok().getLoc();
2702 const AsmToken &Tok = Parser.getTok();
2703 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2705 std::string lowerCase = Tok.getString().lower();
2706 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2707 .Case("asl", ARM_AM::lsl)
2708 .Case("lsl", ARM_AM::lsl)
2709 .Case("lsr", ARM_AM::lsr)
2710 .Case("asr", ARM_AM::asr)
2711 .Case("ror", ARM_AM::ror)
2712 .Case("rrx", ARM_AM::rrx)
2713 .Default(ARM_AM::no_shift);
2715 if (ShiftTy == ARM_AM::no_shift)
2718 Parser.Lex(); // Eat the operator.
2720 // The source register for the shift has already been added to the
2721 // operand list, so we need to pop it off and combine it into the shifted
2722 // register operand instead.
2723 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2724 if (!PrevOp->isReg())
2725 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2726 int SrcReg = PrevOp->getReg();
2731 if (ShiftTy == ARM_AM::rrx) {
2732 // RRX Doesn't have an explicit shift amount. The encoder expects
2733 // the shift register to be the same as the source register. Seems odd,
2737 // Figure out if this is shifted by a constant or a register (for non-RRX).
2738 if (Parser.getTok().is(AsmToken::Hash) ||
2739 Parser.getTok().is(AsmToken::Dollar)) {
2740 Parser.Lex(); // Eat hash.
2741 SMLoc ImmLoc = Parser.getTok().getLoc();
2742 const MCExpr *ShiftExpr = 0;
2743 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2744 Error(ImmLoc, "invalid immediate shift value");
2747 // The expression must be evaluatable as an immediate.
2748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2750 Error(ImmLoc, "invalid immediate shift value");
2753 // Range check the immediate.
2754 // lsl, ror: 0 <= imm <= 31
2755 // lsr, asr: 0 <= imm <= 32
2756 Imm = CE->getValue();
2758 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2759 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2760 Error(ImmLoc, "immediate shift value out of range");
2763 // shift by zero is a nop. Always send it through as lsl.
2764 // ('as' compatibility)
2766 ShiftTy = ARM_AM::lsl;
2767 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2768 SMLoc L = Parser.getTok().getLoc();
2769 EndLoc = Parser.getTok().getEndLoc();
2770 ShiftReg = tryParseRegister();
2771 if (ShiftReg == -1) {
2772 Error (L, "expected immediate or register in shift operand");
2776 Error (Parser.getTok().getLoc(),
2777 "expected immediate or register in shift operand");
2782 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2783 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2787 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2794 /// Try to parse a register name. The token must be an Identifier when called.
2795 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2796 /// if there is a "writeback". 'true' if it's not a register.
2798 /// TODO this is likely to change to allow different register types and or to
2799 /// parse for a specific register type.
2801 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2802 const AsmToken &RegTok = Parser.getTok();
2803 int RegNo = tryParseRegister();
2807 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2808 RegTok.getEndLoc()));
2810 const AsmToken &ExclaimTok = Parser.getTok();
2811 if (ExclaimTok.is(AsmToken::Exclaim)) {
2812 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2813 ExclaimTok.getLoc()));
2814 Parser.Lex(); // Eat exclaim token
2818 // Also check for an index operand. This is only legal for vector registers,
2819 // but that'll get caught OK in operand matching, so we don't need to
2820 // explicitly filter everything else out here.
2821 if (Parser.getTok().is(AsmToken::LBrac)) {
2822 SMLoc SIdx = Parser.getTok().getLoc();
2823 Parser.Lex(); // Eat left bracket token.
2825 const MCExpr *ImmVal;
2826 if (getParser().parseExpression(ImmVal))
2828 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2830 return TokError("immediate value expected for vector index");
2832 if (Parser.getTok().isNot(AsmToken::RBrac))
2833 return Error(Parser.getTok().getLoc(), "']' expected");
2835 SMLoc E = Parser.getTok().getEndLoc();
2836 Parser.Lex(); // Eat right bracket token.
2838 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2846 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2847 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2849 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2850 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2852 switch (Name.size()) {
2855 if (Name[0] != CoprocOp)
2871 if (Name[0] != CoprocOp || Name[1] != '1')
2875 case '0': return 10;
2876 case '1': return 11;
2877 case '2': return 12;
2878 case '3': return 13;
2879 case '4': return 14;
2880 case '5': return 15;
2885 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2886 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2887 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2888 SMLoc S = Parser.getTok().getLoc();
2889 const AsmToken &Tok = Parser.getTok();
2890 if (!Tok.is(AsmToken::Identifier))
2891 return MatchOperand_NoMatch;
2892 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2893 .Case("eq", ARMCC::EQ)
2894 .Case("ne", ARMCC::NE)
2895 .Case("hs", ARMCC::HS)
2896 .Case("cs", ARMCC::HS)
2897 .Case("lo", ARMCC::LO)
2898 .Case("cc", ARMCC::LO)
2899 .Case("mi", ARMCC::MI)
2900 .Case("pl", ARMCC::PL)
2901 .Case("vs", ARMCC::VS)
2902 .Case("vc", ARMCC::VC)
2903 .Case("hi", ARMCC::HI)
2904 .Case("ls", ARMCC::LS)
2905 .Case("ge", ARMCC::GE)
2906 .Case("lt", ARMCC::LT)
2907 .Case("gt", ARMCC::GT)
2908 .Case("le", ARMCC::LE)
2909 .Case("al", ARMCC::AL)
2912 return MatchOperand_NoMatch;
2913 Parser.Lex(); // Eat the token.
2915 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2917 return MatchOperand_Success;
2920 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2921 /// token must be an Identifier when called, and if it is a coprocessor
2922 /// number, the token is eaten and the operand is added to the operand list.
2923 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2924 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2925 SMLoc S = Parser.getTok().getLoc();
2926 const AsmToken &Tok = Parser.getTok();
2927 if (Tok.isNot(AsmToken::Identifier))
2928 return MatchOperand_NoMatch;
2930 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2932 return MatchOperand_NoMatch;
2934 Parser.Lex(); // Eat identifier token.
2935 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2936 return MatchOperand_Success;
2939 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2940 /// token must be an Identifier when called, and if it is a coprocessor
2941 /// number, the token is eaten and the operand is added to the operand list.
2942 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2943 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2944 SMLoc S = Parser.getTok().getLoc();
2945 const AsmToken &Tok = Parser.getTok();
2946 if (Tok.isNot(AsmToken::Identifier))
2947 return MatchOperand_NoMatch;
2949 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2951 return MatchOperand_NoMatch;
2953 Parser.Lex(); // Eat identifier token.
2954 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2955 return MatchOperand_Success;
2958 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2959 /// coproc_option : '{' imm0_255 '}'
2960 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2961 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2962 SMLoc S = Parser.getTok().getLoc();
2964 // If this isn't a '{', this isn't a coprocessor immediate operand.
2965 if (Parser.getTok().isNot(AsmToken::LCurly))
2966 return MatchOperand_NoMatch;
2967 Parser.Lex(); // Eat the '{'
2970 SMLoc Loc = Parser.getTok().getLoc();
2971 if (getParser().parseExpression(Expr)) {
2972 Error(Loc, "illegal expression");
2973 return MatchOperand_ParseFail;
2975 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2976 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2977 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2978 return MatchOperand_ParseFail;
2980 int Val = CE->getValue();
2982 // Check for and consume the closing '}'
2983 if (Parser.getTok().isNot(AsmToken::RCurly))
2984 return MatchOperand_ParseFail;
2985 SMLoc E = Parser.getTok().getEndLoc();
2986 Parser.Lex(); // Eat the '}'
2988 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2989 return MatchOperand_Success;
2992 // For register list parsing, we need to map from raw GPR register numbering
2993 // to the enumeration values. The enumeration values aren't sorted by
2994 // register number due to our using "sp", "lr" and "pc" as canonical names.
2995 static unsigned getNextRegister(unsigned Reg) {
2996 // If this is a GPR, we need to do it manually, otherwise we can rely
2997 // on the sort ordering of the enumeration since the other reg-classes
2999 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3002 default: llvm_unreachable("Invalid GPR number!");
3003 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3004 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3005 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3006 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3007 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3008 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3009 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3010 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3014 // Return the low-subreg of a given Q register.
3015 static unsigned getDRegFromQReg(unsigned QReg) {
3017 default: llvm_unreachable("expected a Q register!");
3018 case ARM::Q0: return ARM::D0;
3019 case ARM::Q1: return ARM::D2;
3020 case ARM::Q2: return ARM::D4;
3021 case ARM::Q3: return ARM::D6;
3022 case ARM::Q4: return ARM::D8;
3023 case ARM::Q5: return ARM::D10;
3024 case ARM::Q6: return ARM::D12;
3025 case ARM::Q7: return ARM::D14;
3026 case ARM::Q8: return ARM::D16;
3027 case ARM::Q9: return ARM::D18;
3028 case ARM::Q10: return ARM::D20;
3029 case ARM::Q11: return ARM::D22;
3030 case ARM::Q12: return ARM::D24;
3031 case ARM::Q13: return ARM::D26;
3032 case ARM::Q14: return ARM::D28;
3033 case ARM::Q15: return ARM::D30;
3037 /// Parse a register list.
3039 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3040 assert(Parser.getTok().is(AsmToken::LCurly) &&
3041 "Token is not a Left Curly Brace");
3042 SMLoc S = Parser.getTok().getLoc();
3043 Parser.Lex(); // Eat '{' token.
3044 SMLoc RegLoc = Parser.getTok().getLoc();
3046 // Check the first register in the list to see what register class
3047 // this is a list of.
3048 int Reg = tryParseRegister();
3050 return Error(RegLoc, "register expected");
3052 // The reglist instructions have at most 16 registers, so reserve
3053 // space for that many.
3055 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3057 // Allow Q regs and just interpret them as the two D sub-registers.
3058 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3059 Reg = getDRegFromQReg(Reg);
3060 EReg = MRI->getEncodingValue(Reg);
3061 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3064 const MCRegisterClass *RC;
3065 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3066 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3067 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3068 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3069 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3070 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3072 return Error(RegLoc, "invalid register in register list");
3074 // Store the register.
3075 EReg = MRI->getEncodingValue(Reg);
3076 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3078 // This starts immediately after the first register token in the list,
3079 // so we can see either a comma or a minus (range separator) as a legal
3081 while (Parser.getTok().is(AsmToken::Comma) ||
3082 Parser.getTok().is(AsmToken::Minus)) {
3083 if (Parser.getTok().is(AsmToken::Minus)) {
3084 Parser.Lex(); // Eat the minus.
3085 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3086 int EndReg = tryParseRegister();
3088 return Error(AfterMinusLoc, "register expected");
3089 // Allow Q regs and just interpret them as the two D sub-registers.
3090 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3091 EndReg = getDRegFromQReg(EndReg) + 1;
3092 // If the register is the same as the start reg, there's nothing
3096 // The register must be in the same register class as the first.
3097 if (!RC->contains(EndReg))
3098 return Error(AfterMinusLoc, "invalid register in register list");
3099 // Ranges must go from low to high.
3100 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3101 return Error(AfterMinusLoc, "bad range in register list");
3103 // Add all the registers in the range to the register list.
3104 while (Reg != EndReg) {
3105 Reg = getNextRegister(Reg);
3106 EReg = MRI->getEncodingValue(Reg);
3107 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3111 Parser.Lex(); // Eat the comma.
3112 RegLoc = Parser.getTok().getLoc();
3114 const AsmToken RegTok = Parser.getTok();
3115 Reg = tryParseRegister();
3117 return Error(RegLoc, "register expected");
3118 // Allow Q regs and just interpret them as the two D sub-registers.
3119 bool isQReg = false;
3120 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3121 Reg = getDRegFromQReg(Reg);
3124 // The register must be in the same register class as the first.
3125 if (!RC->contains(Reg))
3126 return Error(RegLoc, "invalid register in register list");
3127 // List must be monotonically increasing.
3128 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3129 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3130 Warning(RegLoc, "register list not in ascending order");
3132 return Error(RegLoc, "register list not in ascending order");
3134 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3135 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3136 ") in register list");
3139 // VFP register lists must also be contiguous.
3140 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3142 return Error(RegLoc, "non-contiguous register range");
3143 EReg = MRI->getEncodingValue(Reg);
3144 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3146 EReg = MRI->getEncodingValue(++Reg);
3147 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3151 if (Parser.getTok().isNot(AsmToken::RCurly))
3152 return Error(Parser.getTok().getLoc(), "'}' expected");
3153 SMLoc E = Parser.getTok().getEndLoc();
3154 Parser.Lex(); // Eat '}' token.
3156 // Push the register list operand.
3157 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3159 // The ARM system instruction variants for LDM/STM have a '^' token here.
3160 if (Parser.getTok().is(AsmToken::Caret)) {
3161 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3162 Parser.Lex(); // Eat '^' token.
3168 // Helper function to parse the lane index for vector lists.
3169 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3170 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3171 Index = 0; // Always return a defined index value.
3172 if (Parser.getTok().is(AsmToken::LBrac)) {
3173 Parser.Lex(); // Eat the '['.
3174 if (Parser.getTok().is(AsmToken::RBrac)) {
3175 // "Dn[]" is the 'all lanes' syntax.
3176 LaneKind = AllLanes;
3177 EndLoc = Parser.getTok().getEndLoc();
3178 Parser.Lex(); // Eat the ']'.
3179 return MatchOperand_Success;
3182 // There's an optional '#' token here. Normally there wouldn't be, but
3183 // inline assemble puts one in, and it's friendly to accept that.
3184 if (Parser.getTok().is(AsmToken::Hash))
3185 Parser.Lex(); // Eat '#' or '$'.
3187 const MCExpr *LaneIndex;
3188 SMLoc Loc = Parser.getTok().getLoc();
3189 if (getParser().parseExpression(LaneIndex)) {
3190 Error(Loc, "illegal expression");
3191 return MatchOperand_ParseFail;
3193 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3195 Error(Loc, "lane index must be empty or an integer");
3196 return MatchOperand_ParseFail;
3198 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3199 Error(Parser.getTok().getLoc(), "']' expected");
3200 return MatchOperand_ParseFail;
3202 EndLoc = Parser.getTok().getEndLoc();
3203 Parser.Lex(); // Eat the ']'.
3204 int64_t Val = CE->getValue();
3206 // FIXME: Make this range check context sensitive for .8, .16, .32.
3207 if (Val < 0 || Val > 7) {
3208 Error(Parser.getTok().getLoc(), "lane index out of range");
3209 return MatchOperand_ParseFail;
3212 LaneKind = IndexedLane;
3213 return MatchOperand_Success;
3216 return MatchOperand_Success;
3219 // parse a vector register list
3220 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3221 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3222 VectorLaneTy LaneKind;
3224 SMLoc S = Parser.getTok().getLoc();
3225 // As an extension (to match gas), support a plain D register or Q register
3226 // (without encosing curly braces) as a single or double entry list,
3228 if (Parser.getTok().is(AsmToken::Identifier)) {
3229 SMLoc E = Parser.getTok().getEndLoc();
3230 int Reg = tryParseRegister();
3232 return MatchOperand_NoMatch;
3233 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3234 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3235 if (Res != MatchOperand_Success)
3239 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3242 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3246 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3251 return MatchOperand_Success;
3253 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3254 Reg = getDRegFromQReg(Reg);
3255 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3256 if (Res != MatchOperand_Success)
3260 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3261 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3262 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3265 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3266 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3267 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3271 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3276 return MatchOperand_Success;
3278 Error(S, "vector register expected");
3279 return MatchOperand_ParseFail;
3282 if (Parser.getTok().isNot(AsmToken::LCurly))
3283 return MatchOperand_NoMatch;
3285 Parser.Lex(); // Eat '{' token.
3286 SMLoc RegLoc = Parser.getTok().getLoc();
3288 int Reg = tryParseRegister();
3290 Error(RegLoc, "register expected");
3291 return MatchOperand_ParseFail;
3295 unsigned FirstReg = Reg;
3296 // The list is of D registers, but we also allow Q regs and just interpret
3297 // them as the two D sub-registers.
3298 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3299 FirstReg = Reg = getDRegFromQReg(Reg);
3300 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3301 // it's ambiguous with four-register single spaced.
3307 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3308 return MatchOperand_ParseFail;
3310 while (Parser.getTok().is(AsmToken::Comma) ||
3311 Parser.getTok().is(AsmToken::Minus)) {
3312 if (Parser.getTok().is(AsmToken::Minus)) {
3314 Spacing = 1; // Register range implies a single spaced list.
3315 else if (Spacing == 2) {
3316 Error(Parser.getTok().getLoc(),
3317 "sequential registers in double spaced list");
3318 return MatchOperand_ParseFail;
3320 Parser.Lex(); // Eat the minus.
3321 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3322 int EndReg = tryParseRegister();
3324 Error(AfterMinusLoc, "register expected");
3325 return MatchOperand_ParseFail;
3327 // Allow Q regs and just interpret them as the two D sub-registers.
3328 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3329 EndReg = getDRegFromQReg(EndReg) + 1;
3330 // If the register is the same as the start reg, there's nothing
3334 // The register must be in the same register class as the first.
3335 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3336 Error(AfterMinusLoc, "invalid register in register list");
3337 return MatchOperand_ParseFail;
3339 // Ranges must go from low to high.
3341 Error(AfterMinusLoc, "bad range in register list");
3342 return MatchOperand_ParseFail;
3344 // Parse the lane specifier if present.
3345 VectorLaneTy NextLaneKind;
3346 unsigned NextLaneIndex;
3347 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3348 MatchOperand_Success)
3349 return MatchOperand_ParseFail;
3350 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3351 Error(AfterMinusLoc, "mismatched lane index in register list");
3352 return MatchOperand_ParseFail;
3355 // Add all the registers in the range to the register list.
3356 Count += EndReg - Reg;
3360 Parser.Lex(); // Eat the comma.
3361 RegLoc = Parser.getTok().getLoc();
3363 Reg = tryParseRegister();
3365 Error(RegLoc, "register expected");
3366 return MatchOperand_ParseFail;
3368 // vector register lists must be contiguous.
3369 // It's OK to use the enumeration values directly here rather, as the
3370 // VFP register classes have the enum sorted properly.
3372 // The list is of D registers, but we also allow Q regs and just interpret
3373 // them as the two D sub-registers.
3374 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3376 Spacing = 1; // Register range implies a single spaced list.
3377 else if (Spacing == 2) {
3379 "invalid register in double-spaced list (must be 'D' register')");
3380 return MatchOperand_ParseFail;
3382 Reg = getDRegFromQReg(Reg);
3383 if (Reg != OldReg + 1) {
3384 Error(RegLoc, "non-contiguous register range");
3385 return MatchOperand_ParseFail;
3389 // Parse the lane specifier if present.
3390 VectorLaneTy NextLaneKind;
3391 unsigned NextLaneIndex;
3392 SMLoc LaneLoc = Parser.getTok().getLoc();
3393 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3394 MatchOperand_Success)
3395 return MatchOperand_ParseFail;
3396 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3397 Error(LaneLoc, "mismatched lane index in register list");
3398 return MatchOperand_ParseFail;
3402 // Normal D register.
3403 // Figure out the register spacing (single or double) of the list if
3404 // we don't know it already.
3406 Spacing = 1 + (Reg == OldReg + 2);
3408 // Just check that it's contiguous and keep going.
3409 if (Reg != OldReg + Spacing) {
3410 Error(RegLoc, "non-contiguous register range");
3411 return MatchOperand_ParseFail;
3414 // Parse the lane specifier if present.
3415 VectorLaneTy NextLaneKind;
3416 unsigned NextLaneIndex;
3417 SMLoc EndLoc = Parser.getTok().getLoc();
3418 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3419 return MatchOperand_ParseFail;
3420 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3421 Error(EndLoc, "mismatched lane index in register list");
3422 return MatchOperand_ParseFail;
3426 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3427 Error(Parser.getTok().getLoc(), "'}' expected");
3428 return MatchOperand_ParseFail;
3430 E = Parser.getTok().getEndLoc();
3431 Parser.Lex(); // Eat '}' token.
3435 // Two-register operands have been converted to the
3436 // composite register classes.
3438 const MCRegisterClass *RC = (Spacing == 1) ?
3439 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3440 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3441 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3444 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3445 (Spacing == 2), S, E));
3448 // Two-register operands have been converted to the
3449 // composite register classes.
3451 const MCRegisterClass *RC = (Spacing == 1) ?
3452 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3453 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3454 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3456 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3461 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3467 return MatchOperand_Success;
3470 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3471 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3472 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3473 SMLoc S = Parser.getTok().getLoc();
3474 const AsmToken &Tok = Parser.getTok();
3477 if (Tok.is(AsmToken::Identifier)) {
3478 StringRef OptStr = Tok.getString();
3480 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3481 .Case("sy", ARM_MB::SY)
3482 .Case("st", ARM_MB::ST)
3483 .Case("ld", ARM_MB::LD)
3484 .Case("sh", ARM_MB::ISH)
3485 .Case("ish", ARM_MB::ISH)
3486 .Case("shst", ARM_MB::ISHST)
3487 .Case("ishst", ARM_MB::ISHST)
3488 .Case("ishld", ARM_MB::ISHLD)
3489 .Case("nsh", ARM_MB::NSH)
3490 .Case("un", ARM_MB::NSH)
3491 .Case("nshst", ARM_MB::NSHST)
3492 .Case("nshld", ARM_MB::NSHLD)
3493 .Case("unst", ARM_MB::NSHST)
3494 .Case("osh", ARM_MB::OSH)
3495 .Case("oshst", ARM_MB::OSHST)
3496 .Case("oshld", ARM_MB::OSHLD)
3499 // ishld, oshld, nshld and ld are only available from ARMv8.
3500 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3501 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3505 return MatchOperand_NoMatch;
3507 Parser.Lex(); // Eat identifier token.
3508 } else if (Tok.is(AsmToken::Hash) ||
3509 Tok.is(AsmToken::Dollar) ||
3510 Tok.is(AsmToken::Integer)) {
3511 if (Parser.getTok().isNot(AsmToken::Integer))
3512 Parser.Lex(); // Eat '#' or '$'.
3513 SMLoc Loc = Parser.getTok().getLoc();
3515 const MCExpr *MemBarrierID;
3516 if (getParser().parseExpression(MemBarrierID)) {
3517 Error(Loc, "illegal expression");
3518 return MatchOperand_ParseFail;
3521 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3523 Error(Loc, "constant expression expected");
3524 return MatchOperand_ParseFail;
3527 int Val = CE->getValue();
3529 Error(Loc, "immediate value out of range");
3530 return MatchOperand_ParseFail;
3533 Opt = ARM_MB::RESERVED_0 + Val;
3535 return MatchOperand_ParseFail;
3537 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3538 return MatchOperand_Success;
3541 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3542 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3543 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3544 SMLoc S = Parser.getTok().getLoc();
3545 const AsmToken &Tok = Parser.getTok();
3548 if (Tok.is(AsmToken::Identifier)) {
3549 StringRef OptStr = Tok.getString();
3551 if (OptStr.lower() == "sy")
3554 return MatchOperand_NoMatch;
3556 Parser.Lex(); // Eat identifier token.
3557 } else if (Tok.is(AsmToken::Hash) ||
3558 Tok.is(AsmToken::Dollar) ||
3559 Tok.is(AsmToken::Integer)) {
3560 if (Parser.getTok().isNot(AsmToken::Integer))
3561 Parser.Lex(); // Eat '#' or '$'.
3562 SMLoc Loc = Parser.getTok().getLoc();
3564 const MCExpr *ISBarrierID;
3565 if (getParser().parseExpression(ISBarrierID)) {
3566 Error(Loc, "illegal expression");
3567 return MatchOperand_ParseFail;
3570 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3572 Error(Loc, "constant expression expected");
3573 return MatchOperand_ParseFail;
3576 int Val = CE->getValue();
3578 Error(Loc, "immediate value out of range");
3579 return MatchOperand_ParseFail;
3582 Opt = ARM_ISB::RESERVED_0 + Val;
3584 return MatchOperand_ParseFail;
3586 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3587 (ARM_ISB::InstSyncBOpt)Opt, S));
3588 return MatchOperand_Success;
3592 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3593 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3594 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3595 SMLoc S = Parser.getTok().getLoc();
3596 const AsmToken &Tok = Parser.getTok();
3597 if (!Tok.is(AsmToken::Identifier))
3598 return MatchOperand_NoMatch;
3599 StringRef IFlagsStr = Tok.getString();
3601 // An iflags string of "none" is interpreted to mean that none of the AIF
3602 // bits are set. Not a terribly useful instruction, but a valid encoding.
3603 unsigned IFlags = 0;
3604 if (IFlagsStr != "none") {
3605 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3606 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3607 .Case("a", ARM_PROC::A)
3608 .Case("i", ARM_PROC::I)
3609 .Case("f", ARM_PROC::F)
3612 // If some specific iflag is already set, it means that some letter is
3613 // present more than once, this is not acceptable.
3614 if (Flag == ~0U || (IFlags & Flag))
3615 return MatchOperand_NoMatch;
3621 Parser.Lex(); // Eat identifier token.
3622 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3623 return MatchOperand_Success;
3626 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3627 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3628 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3629 SMLoc S = Parser.getTok().getLoc();
3630 const AsmToken &Tok = Parser.getTok();
3631 if (!Tok.is(AsmToken::Identifier))
3632 return MatchOperand_NoMatch;
3633 StringRef Mask = Tok.getString();
3636 // See ARMv6-M 10.1.1
3637 std::string Name = Mask.lower();
3638 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3639 // Note: in the documentation:
3640 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3641 // for MSR APSR_nzcvq.
3642 // but we do make it an alias here. This is so to get the "mask encoding"
3643 // bits correct on MSR APSR writes.
3645 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3646 // should really only be allowed when writing a special register. Note
3647 // they get dropped in the MRS instruction reading a special register as
3648 // the SYSm field is only 8 bits.
3650 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3651 // includes the DSP extension but that is not checked.
3652 .Case("apsr", 0x800)
3653 .Case("apsr_nzcvq", 0x800)
3654 .Case("apsr_g", 0x400)
3655 .Case("apsr_nzcvqg", 0xc00)
3656 .Case("iapsr", 0x801)
3657 .Case("iapsr_nzcvq", 0x801)
3658 .Case("iapsr_g", 0x401)
3659 .Case("iapsr_nzcvqg", 0xc01)
3660 .Case("eapsr", 0x802)
3661 .Case("eapsr_nzcvq", 0x802)
3662 .Case("eapsr_g", 0x402)
3663 .Case("eapsr_nzcvqg", 0xc02)
3664 .Case("xpsr", 0x803)
3665 .Case("xpsr_nzcvq", 0x803)
3666 .Case("xpsr_g", 0x403)
3667 .Case("xpsr_nzcvqg", 0xc03)
3668 .Case("ipsr", 0x805)
3669 .Case("epsr", 0x806)
3670 .Case("iepsr", 0x807)
3673 .Case("primask", 0x810)
3674 .Case("basepri", 0x811)
3675 .Case("basepri_max", 0x812)
3676 .Case("faultmask", 0x813)
3677 .Case("control", 0x814)
3680 if (FlagsVal == ~0U)
3681 return MatchOperand_NoMatch;
3683 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3684 // basepri, basepri_max and faultmask only valid for V7m.
3685 return MatchOperand_NoMatch;
3687 Parser.Lex(); // Eat identifier token.
3688 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3689 return MatchOperand_Success;
3692 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3693 size_t Start = 0, Next = Mask.find('_');
3694 StringRef Flags = "";
3695 std::string SpecReg = Mask.slice(Start, Next).lower();
3696 if (Next != StringRef::npos)
3697 Flags = Mask.slice(Next+1, Mask.size());
3699 // FlagsVal contains the complete mask:
3701 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3702 unsigned FlagsVal = 0;
3704 if (SpecReg == "apsr") {
3705 FlagsVal = StringSwitch<unsigned>(Flags)
3706 .Case("nzcvq", 0x8) // same as CPSR_f
3707 .Case("g", 0x4) // same as CPSR_s
3708 .Case("nzcvqg", 0xc) // same as CPSR_fs
3711 if (FlagsVal == ~0U) {
3713 return MatchOperand_NoMatch;
3715 FlagsVal = 8; // No flag
3717 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3718 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3719 if (Flags == "all" || Flags == "")
3721 for (int i = 0, e = Flags.size(); i != e; ++i) {
3722 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3729 // If some specific flag is already set, it means that some letter is
3730 // present more than once, this is not acceptable.
3731 if (FlagsVal == ~0U || (FlagsVal & Flag))
3732 return MatchOperand_NoMatch;
3735 } else // No match for special register.
3736 return MatchOperand_NoMatch;
3738 // Special register without flags is NOT equivalent to "fc" flags.
3739 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3740 // two lines would enable gas compatibility at the expense of breaking
3746 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3747 if (SpecReg == "spsr")
3750 Parser.Lex(); // Eat identifier token.
3751 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3752 return MatchOperand_Success;
3755 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3756 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3757 int Low, int High) {
3758 const AsmToken &Tok = Parser.getTok();
3759 if (Tok.isNot(AsmToken::Identifier)) {
3760 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3761 return MatchOperand_ParseFail;
3763 StringRef ShiftName = Tok.getString();
3764 std::string LowerOp = Op.lower();
3765 std::string UpperOp = Op.upper();
3766 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3767 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3768 return MatchOperand_ParseFail;
3770 Parser.Lex(); // Eat shift type token.
3772 // There must be a '#' and a shift amount.
3773 if (Parser.getTok().isNot(AsmToken::Hash) &&
3774 Parser.getTok().isNot(AsmToken::Dollar)) {
3775 Error(Parser.getTok().getLoc(), "'#' expected");
3776 return MatchOperand_ParseFail;
3778 Parser.Lex(); // Eat hash token.
3780 const MCExpr *ShiftAmount;
3781 SMLoc Loc = Parser.getTok().getLoc();
3783 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3784 Error(Loc, "illegal expression");
3785 return MatchOperand_ParseFail;
3787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3789 Error(Loc, "constant expression expected");
3790 return MatchOperand_ParseFail;
3792 int Val = CE->getValue();
3793 if (Val < Low || Val > High) {
3794 Error(Loc, "immediate value out of range");
3795 return MatchOperand_ParseFail;
3798 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3800 return MatchOperand_Success;
3803 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3804 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3805 const AsmToken &Tok = Parser.getTok();
3806 SMLoc S = Tok.getLoc();
3807 if (Tok.isNot(AsmToken::Identifier)) {
3808 Error(S, "'be' or 'le' operand expected");
3809 return MatchOperand_ParseFail;
3811 int Val = StringSwitch<int>(Tok.getString().lower())
3815 Parser.Lex(); // Eat the token.
3818 Error(S, "'be' or 'le' operand expected");
3819 return MatchOperand_ParseFail;
3821 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3823 S, Tok.getEndLoc()));
3824 return MatchOperand_Success;
3827 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3828 /// instructions. Legal values are:
3829 /// lsl #n 'n' in [0,31]
3830 /// asr #n 'n' in [1,32]
3831 /// n == 32 encoded as n == 0.
3832 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3833 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3834 const AsmToken &Tok = Parser.getTok();
3835 SMLoc S = Tok.getLoc();
3836 if (Tok.isNot(AsmToken::Identifier)) {
3837 Error(S, "shift operator 'asr' or 'lsl' expected");
3838 return MatchOperand_ParseFail;
3840 StringRef ShiftName = Tok.getString();
3842 if (ShiftName == "lsl" || ShiftName == "LSL")
3844 else if (ShiftName == "asr" || ShiftName == "ASR")
3847 Error(S, "shift operator 'asr' or 'lsl' expected");
3848 return MatchOperand_ParseFail;
3850 Parser.Lex(); // Eat the operator.
3852 // A '#' and a shift amount.
3853 if (Parser.getTok().isNot(AsmToken::Hash) &&
3854 Parser.getTok().isNot(AsmToken::Dollar)) {
3855 Error(Parser.getTok().getLoc(), "'#' expected");
3856 return MatchOperand_ParseFail;
3858 Parser.Lex(); // Eat hash token.
3859 SMLoc ExLoc = Parser.getTok().getLoc();
3861 const MCExpr *ShiftAmount;
3863 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3864 Error(ExLoc, "malformed shift expression");
3865 return MatchOperand_ParseFail;
3867 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3869 Error(ExLoc, "shift amount must be an immediate");
3870 return MatchOperand_ParseFail;
3873 int64_t Val = CE->getValue();
3875 // Shift amount must be in [1,32]
3876 if (Val < 1 || Val > 32) {
3877 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3878 return MatchOperand_ParseFail;
3880 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3881 if (isThumb() && Val == 32) {
3882 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3883 return MatchOperand_ParseFail;
3885 if (Val == 32) Val = 0;
3887 // Shift amount must be in [1,32]
3888 if (Val < 0 || Val > 31) {
3889 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3890 return MatchOperand_ParseFail;
3894 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3896 return MatchOperand_Success;
3899 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3900 /// of instructions. Legal values are:
3901 /// ror #n 'n' in {0, 8, 16, 24}
3902 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3903 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3904 const AsmToken &Tok = Parser.getTok();
3905 SMLoc S = Tok.getLoc();
3906 if (Tok.isNot(AsmToken::Identifier))
3907 return MatchOperand_NoMatch;
3908 StringRef ShiftName = Tok.getString();
3909 if (ShiftName != "ror" && ShiftName != "ROR")
3910 return MatchOperand_NoMatch;
3911 Parser.Lex(); // Eat the operator.
3913 // A '#' and a rotate amount.
3914 if (Parser.getTok().isNot(AsmToken::Hash) &&
3915 Parser.getTok().isNot(AsmToken::Dollar)) {
3916 Error(Parser.getTok().getLoc(), "'#' expected");
3917 return MatchOperand_ParseFail;
3919 Parser.Lex(); // Eat hash token.
3920 SMLoc ExLoc = Parser.getTok().getLoc();
3922 const MCExpr *ShiftAmount;
3924 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3925 Error(ExLoc, "malformed rotate expression");
3926 return MatchOperand_ParseFail;
3928 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3930 Error(ExLoc, "rotate amount must be an immediate");
3931 return MatchOperand_ParseFail;
3934 int64_t Val = CE->getValue();
3935 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3936 // normally, zero is represented in asm by omitting the rotate operand
3938 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3939 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
3940 return MatchOperand_ParseFail;
3943 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
3945 return MatchOperand_Success;
3948 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3949 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3950 SMLoc S = Parser.getTok().getLoc();
3951 // The bitfield descriptor is really two operands, the LSB and the width.
3952 if (Parser.getTok().isNot(AsmToken::Hash) &&
3953 Parser.getTok().isNot(AsmToken::Dollar)) {
3954 Error(Parser.getTok().getLoc(), "'#' expected");
3955 return MatchOperand_ParseFail;
3957 Parser.Lex(); // Eat hash token.
3959 const MCExpr *LSBExpr;
3960 SMLoc E = Parser.getTok().getLoc();
3961 if (getParser().parseExpression(LSBExpr)) {
3962 Error(E, "malformed immediate expression");
3963 return MatchOperand_ParseFail;
3965 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3967 Error(E, "'lsb' operand must be an immediate");
3968 return MatchOperand_ParseFail;
3971 int64_t LSB = CE->getValue();
3972 // The LSB must be in the range [0,31]
3973 if (LSB < 0 || LSB > 31) {
3974 Error(E, "'lsb' operand must be in the range [0,31]");
3975 return MatchOperand_ParseFail;
3977 E = Parser.getTok().getLoc();
3979 // Expect another immediate operand.
3980 if (Parser.getTok().isNot(AsmToken::Comma)) {
3981 Error(Parser.getTok().getLoc(), "too few operands");
3982 return MatchOperand_ParseFail;
3984 Parser.Lex(); // Eat hash token.
3985 if (Parser.getTok().isNot(AsmToken::Hash) &&
3986 Parser.getTok().isNot(AsmToken::Dollar)) {
3987 Error(Parser.getTok().getLoc(), "'#' expected");
3988 return MatchOperand_ParseFail;
3990 Parser.Lex(); // Eat hash token.
3992 const MCExpr *WidthExpr;
3994 if (getParser().parseExpression(WidthExpr, EndLoc)) {
3995 Error(E, "malformed immediate expression");
3996 return MatchOperand_ParseFail;
3998 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4000 Error(E, "'width' operand must be an immediate");
4001 return MatchOperand_ParseFail;
4004 int64_t Width = CE->getValue();
4005 // The LSB must be in the range [1,32-lsb]
4006 if (Width < 1 || Width > 32 - LSB) {
4007 Error(E, "'width' operand must be in the range [1,32-lsb]");
4008 return MatchOperand_ParseFail;
4011 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
4013 return MatchOperand_Success;
4016 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4017 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4018 // Check for a post-index addressing register operand. Specifically:
4019 // postidx_reg := '+' register {, shift}
4020 // | '-' register {, shift}
4021 // | register {, shift}
4023 // This method must return MatchOperand_NoMatch without consuming any tokens
4024 // in the case where there is no match, as other alternatives take other
4026 AsmToken Tok = Parser.getTok();
4027 SMLoc S = Tok.getLoc();
4028 bool haveEaten = false;
4030 if (Tok.is(AsmToken::Plus)) {
4031 Parser.Lex(); // Eat the '+' token.
4033 } else if (Tok.is(AsmToken::Minus)) {
4034 Parser.Lex(); // Eat the '-' token.
4039 SMLoc E = Parser.getTok().getEndLoc();
4040 int Reg = tryParseRegister();
4043 return MatchOperand_NoMatch;
4044 Error(Parser.getTok().getLoc(), "register expected");
4045 return MatchOperand_ParseFail;
4048 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4049 unsigned ShiftImm = 0;
4050 if (Parser.getTok().is(AsmToken::Comma)) {
4051 Parser.Lex(); // Eat the ','.
4052 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4053 return MatchOperand_ParseFail;
4055 // FIXME: Only approximates end...may include intervening whitespace.
4056 E = Parser.getTok().getLoc();
4059 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4062 return MatchOperand_Success;
4065 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4066 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4067 // Check for a post-index addressing register operand. Specifically:
4068 // am3offset := '+' register
4075 // This method must return MatchOperand_NoMatch without consuming any tokens
4076 // in the case where there is no match, as other alternatives take other
4078 AsmToken Tok = Parser.getTok();
4079 SMLoc S = Tok.getLoc();
4081 // Do immediates first, as we always parse those if we have a '#'.
4082 if (Parser.getTok().is(AsmToken::Hash) ||
4083 Parser.getTok().is(AsmToken::Dollar)) {
4084 Parser.Lex(); // Eat '#' or '$'.
4085 // Explicitly look for a '-', as we need to encode negative zero
4087 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4088 const MCExpr *Offset;
4090 if (getParser().parseExpression(Offset, E))
4091 return MatchOperand_ParseFail;
4092 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4094 Error(S, "constant expression expected");
4095 return MatchOperand_ParseFail;
4097 // Negative zero is encoded as the flag value INT32_MIN.
4098 int32_t Val = CE->getValue();
4099 if (isNegative && Val == 0)
4103 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4105 return MatchOperand_Success;
4109 bool haveEaten = false;
4111 if (Tok.is(AsmToken::Plus)) {
4112 Parser.Lex(); // Eat the '+' token.
4114 } else if (Tok.is(AsmToken::Minus)) {
4115 Parser.Lex(); // Eat the '-' token.
4120 Tok = Parser.getTok();
4121 int Reg = tryParseRegister();
4124 return MatchOperand_NoMatch;
4125 Error(Tok.getLoc(), "register expected");
4126 return MatchOperand_ParseFail;
4129 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4130 0, S, Tok.getEndLoc()));
4132 return MatchOperand_Success;
4135 /// Convert parsed operands to MCInst. Needed here because this instruction
4136 /// only has two register operands, but multiplication is commutative so
4137 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4139 cvtThumbMultiply(MCInst &Inst,
4140 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4141 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4142 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4143 // If we have a three-operand form, make sure to set Rn to be the operand
4144 // that isn't the same as Rd.
4146 if (Operands.size() == 6 &&
4147 ((ARMOperand*)Operands[4])->getReg() ==
4148 ((ARMOperand*)Operands[3])->getReg())
4150 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4151 Inst.addOperand(Inst.getOperand(0));
4152 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4156 cvtThumbBranches(MCInst &Inst,
4157 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4158 int CondOp = -1, ImmOp = -1;
4159 switch(Inst.getOpcode()) {
4161 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4164 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4166 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4168 // first decide whether or not the branch should be conditional
4169 // by looking at it's location relative to an IT block
4171 // inside an IT block we cannot have any conditional branches. any
4172 // such instructions needs to be converted to unconditional form
4173 switch(Inst.getOpcode()) {
4174 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4175 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4178 // outside IT blocks we can only have unconditional branches with AL
4179 // condition code or conditional branches with non-AL condition code
4180 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4181 switch(Inst.getOpcode()) {
4184 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4188 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4193 // now decide on encoding size based on branch target range
4194 switch(Inst.getOpcode()) {
4195 // classify tB as either t2B or t1B based on range of immediate operand
4197 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4198 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4199 Inst.setOpcode(ARM::t2B);
4202 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4204 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4205 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4206 Inst.setOpcode(ARM::t2Bcc);
4210 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4211 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4214 /// Parse an ARM memory expression, return false if successful else return true
4215 /// or an error. The first token must be a '[' when called.
4217 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4219 assert(Parser.getTok().is(AsmToken::LBrac) &&
4220 "Token is not a Left Bracket");
4221 S = Parser.getTok().getLoc();
4222 Parser.Lex(); // Eat left bracket token.
4224 const AsmToken &BaseRegTok = Parser.getTok();
4225 int BaseRegNum = tryParseRegister();
4226 if (BaseRegNum == -1)
4227 return Error(BaseRegTok.getLoc(), "register expected");
4229 // The next token must either be a comma, a colon or a closing bracket.
4230 const AsmToken &Tok = Parser.getTok();
4231 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4232 !Tok.is(AsmToken::RBrac))
4233 return Error(Tok.getLoc(), "malformed memory operand");
4235 if (Tok.is(AsmToken::RBrac)) {
4236 E = Tok.getEndLoc();
4237 Parser.Lex(); // Eat right bracket token.
4239 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4240 0, 0, false, S, E));
4242 // If there's a pre-indexing writeback marker, '!', just add it as a token
4243 // operand. It's rather odd, but syntactically valid.
4244 if (Parser.getTok().is(AsmToken::Exclaim)) {
4245 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4246 Parser.Lex(); // Eat the '!'.
4252 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4253 "Lost colon or comma in memory operand?!");
4254 if (Tok.is(AsmToken::Comma)) {
4255 Parser.Lex(); // Eat the comma.
4258 // If we have a ':', it's an alignment specifier.
4259 if (Parser.getTok().is(AsmToken::Colon)) {
4260 Parser.Lex(); // Eat the ':'.
4261 E = Parser.getTok().getLoc();
4264 if (getParser().parseExpression(Expr))
4267 // The expression has to be a constant. Memory references with relocations
4268 // don't come through here, as they use the <label> forms of the relevant
4270 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4272 return Error (E, "constant expression expected");
4275 switch (CE->getValue()) {
4278 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4279 case 16: Align = 2; break;
4280 case 32: Align = 4; break;
4281 case 64: Align = 8; break;
4282 case 128: Align = 16; break;
4283 case 256: Align = 32; break;
4286 // Now we should have the closing ']'
4287 if (Parser.getTok().isNot(AsmToken::RBrac))
4288 return Error(Parser.getTok().getLoc(), "']' expected");
4289 E = Parser.getTok().getEndLoc();
4290 Parser.Lex(); // Eat right bracket token.
4292 // Don't worry about range checking the value here. That's handled by
4293 // the is*() predicates.
4294 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4295 ARM_AM::no_shift, 0, Align,
4298 // If there's a pre-indexing writeback marker, '!', just add it as a token
4300 if (Parser.getTok().is(AsmToken::Exclaim)) {
4301 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4302 Parser.Lex(); // Eat the '!'.
4308 // If we have a '#', it's an immediate offset, else assume it's a register
4309 // offset. Be friendly and also accept a plain integer (without a leading
4310 // hash) for gas compatibility.
4311 if (Parser.getTok().is(AsmToken::Hash) ||
4312 Parser.getTok().is(AsmToken::Dollar) ||
4313 Parser.getTok().is(AsmToken::Integer)) {
4314 if (Parser.getTok().isNot(AsmToken::Integer))
4315 Parser.Lex(); // Eat '#' or '$'.
4316 E = Parser.getTok().getLoc();
4318 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4319 const MCExpr *Offset;
4320 if (getParser().parseExpression(Offset))
4323 // The expression has to be a constant. Memory references with relocations
4324 // don't come through here, as they use the <label> forms of the relevant
4326 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4328 return Error (E, "constant expression expected");
4330 // If the constant was #-0, represent it as INT32_MIN.
4331 int32_t Val = CE->getValue();
4332 if (isNegative && Val == 0)
4333 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4335 // Now we should have the closing ']'
4336 if (Parser.getTok().isNot(AsmToken::RBrac))
4337 return Error(Parser.getTok().getLoc(), "']' expected");
4338 E = Parser.getTok().getEndLoc();
4339 Parser.Lex(); // Eat right bracket token.
4341 // Don't worry about range checking the value here. That's handled by
4342 // the is*() predicates.
4343 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4344 ARM_AM::no_shift, 0, 0,
4347 // If there's a pre-indexing writeback marker, '!', just add it as a token
4349 if (Parser.getTok().is(AsmToken::Exclaim)) {
4350 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4351 Parser.Lex(); // Eat the '!'.
4357 // The register offset is optionally preceded by a '+' or '-'
4358 bool isNegative = false;
4359 if (Parser.getTok().is(AsmToken::Minus)) {
4361 Parser.Lex(); // Eat the '-'.
4362 } else if (Parser.getTok().is(AsmToken::Plus)) {
4364 Parser.Lex(); // Eat the '+'.
4367 E = Parser.getTok().getLoc();
4368 int OffsetRegNum = tryParseRegister();
4369 if (OffsetRegNum == -1)
4370 return Error(E, "register expected");
4372 // If there's a shift operator, handle it.
4373 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4374 unsigned ShiftImm = 0;
4375 if (Parser.getTok().is(AsmToken::Comma)) {
4376 Parser.Lex(); // Eat the ','.
4377 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4381 // Now we should have the closing ']'
4382 if (Parser.getTok().isNot(AsmToken::RBrac))
4383 return Error(Parser.getTok().getLoc(), "']' expected");
4384 E = Parser.getTok().getEndLoc();
4385 Parser.Lex(); // Eat right bracket token.
4387 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4388 ShiftType, ShiftImm, 0, isNegative,
4391 // If there's a pre-indexing writeback marker, '!', just add it as a token
4393 if (Parser.getTok().is(AsmToken::Exclaim)) {
4394 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4395 Parser.Lex(); // Eat the '!'.
4401 /// parseMemRegOffsetShift - one of these two:
4402 /// ( lsl | lsr | asr | ror ) , # shift_amount
4404 /// return true if it parses a shift otherwise it returns false.
4405 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4407 SMLoc Loc = Parser.getTok().getLoc();
4408 const AsmToken &Tok = Parser.getTok();
4409 if (Tok.isNot(AsmToken::Identifier))
4411 StringRef ShiftName = Tok.getString();
4412 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4413 ShiftName == "asl" || ShiftName == "ASL")
4415 else if (ShiftName == "lsr" || ShiftName == "LSR")
4417 else if (ShiftName == "asr" || ShiftName == "ASR")
4419 else if (ShiftName == "ror" || ShiftName == "ROR")
4421 else if (ShiftName == "rrx" || ShiftName == "RRX")
4424 return Error(Loc, "illegal shift operator");
4425 Parser.Lex(); // Eat shift type token.
4427 // rrx stands alone.
4429 if (St != ARM_AM::rrx) {
4430 Loc = Parser.getTok().getLoc();
4431 // A '#' and a shift amount.
4432 const AsmToken &HashTok = Parser.getTok();
4433 if (HashTok.isNot(AsmToken::Hash) &&
4434 HashTok.isNot(AsmToken::Dollar))
4435 return Error(HashTok.getLoc(), "'#' expected");
4436 Parser.Lex(); // Eat hash token.
4439 if (getParser().parseExpression(Expr))
4441 // Range check the immediate.
4442 // lsl, ror: 0 <= imm <= 31
4443 // lsr, asr: 0 <= imm <= 32
4444 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4446 return Error(Loc, "shift amount must be an immediate");
4447 int64_t Imm = CE->getValue();
4449 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4450 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4451 return Error(Loc, "immediate shift value out of range");
4452 // If <ShiftTy> #0, turn it into a no_shift.
4455 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4464 /// parseFPImm - A floating point immediate expression operand.
4465 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4466 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4467 // Anything that can accept a floating point constant as an operand
4468 // needs to go through here, as the regular parseExpression is
4471 // This routine still creates a generic Immediate operand, containing
4472 // a bitcast of the 64-bit floating point value. The various operands
4473 // that accept floats can check whether the value is valid for them
4474 // via the standard is*() predicates.
4476 SMLoc S = Parser.getTok().getLoc();
4478 if (Parser.getTok().isNot(AsmToken::Hash) &&
4479 Parser.getTok().isNot(AsmToken::Dollar))
4480 return MatchOperand_NoMatch;
4482 // Disambiguate the VMOV forms that can accept an FP immediate.
4483 // vmov.f32 <sreg>, #imm
4484 // vmov.f64 <dreg>, #imm
4485 // vmov.f32 <dreg>, #imm @ vector f32x2
4486 // vmov.f32 <qreg>, #imm @ vector f32x4
4488 // There are also the NEON VMOV instructions which expect an
4489 // integer constant. Make sure we don't try to parse an FPImm
4491 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4492 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4493 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4494 TyOp->getToken() != ".f64"))
4495 return MatchOperand_NoMatch;
4497 Parser.Lex(); // Eat '#' or '$'.
4499 // Handle negation, as that still comes through as a separate token.
4500 bool isNegative = false;
4501 if (Parser.getTok().is(AsmToken::Minus)) {
4505 const AsmToken &Tok = Parser.getTok();
4506 SMLoc Loc = Tok.getLoc();
4507 if (Tok.is(AsmToken::Real)) {
4508 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4509 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4510 // If we had a '-' in front, toggle the sign bit.
4511 IntVal ^= (uint64_t)isNegative << 31;
4512 Parser.Lex(); // Eat the token.
4513 Operands.push_back(ARMOperand::CreateImm(
4514 MCConstantExpr::Create(IntVal, getContext()),
4515 S, Parser.getTok().getLoc()));
4516 return MatchOperand_Success;
4518 // Also handle plain integers. Instructions which allow floating point
4519 // immediates also allow a raw encoded 8-bit value.
4520 if (Tok.is(AsmToken::Integer)) {
4521 int64_t Val = Tok.getIntVal();
4522 Parser.Lex(); // Eat the token.
4523 if (Val > 255 || Val < 0) {
4524 Error(Loc, "encoded floating point value out of range");
4525 return MatchOperand_ParseFail;
4527 double RealVal = ARM_AM::getFPImmFloat(Val);
4528 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4529 Operands.push_back(ARMOperand::CreateImm(
4530 MCConstantExpr::Create(Val, getContext()), S,
4531 Parser.getTok().getLoc()));
4532 return MatchOperand_Success;
4535 Error(Loc, "invalid floating point immediate");
4536 return MatchOperand_ParseFail;
4539 /// Parse a arm instruction operand. For now this parses the operand regardless
4540 /// of the mnemonic.
4541 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4542 StringRef Mnemonic) {
4545 // Check if the current operand has a custom associated parser, if so, try to
4546 // custom parse the operand, or fallback to the general approach.
4547 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4548 if (ResTy == MatchOperand_Success)
4550 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4551 // there was a match, but an error occurred, in which case, just return that
4552 // the operand parsing failed.
4553 if (ResTy == MatchOperand_ParseFail)
4556 switch (getLexer().getKind()) {
4558 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4560 case AsmToken::Identifier: {
4561 // If we've seen a branch mnemonic, the next operand must be a label. This
4562 // is true even if the label is a register name. So "br r1" means branch to
4564 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4566 if (!tryParseRegisterWithWriteBack(Operands))
4568 int Res = tryParseShiftRegister(Operands);
4569 if (Res == 0) // success
4571 else if (Res == -1) // irrecoverable error
4573 // If this is VMRS, check for the apsr_nzcv operand.
4574 if (Mnemonic == "vmrs" &&
4575 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4576 S = Parser.getTok().getLoc();
4578 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4583 // Fall though for the Identifier case that is not a register or a
4586 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4587 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4588 case AsmToken::String: // quoted label names.
4589 case AsmToken::Dot: { // . as a branch target
4590 // This was not a register so parse other operands that start with an
4591 // identifier (like labels) as expressions and create them as immediates.
4592 const MCExpr *IdVal;
4593 S = Parser.getTok().getLoc();
4594 if (getParser().parseExpression(IdVal))
4596 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4597 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4600 case AsmToken::LBrac:
4601 return parseMemory(Operands);
4602 case AsmToken::LCurly:
4603 return parseRegisterList(Operands);
4604 case AsmToken::Dollar:
4605 case AsmToken::Hash: {
4606 // #42 -> immediate.
4607 S = Parser.getTok().getLoc();
4610 if (Parser.getTok().isNot(AsmToken::Colon)) {
4611 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4612 const MCExpr *ImmVal;
4613 if (getParser().parseExpression(ImmVal))
4615 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4617 int32_t Val = CE->getValue();
4618 if (isNegative && Val == 0)
4619 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4621 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4622 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4624 // There can be a trailing '!' on operands that we want as a separate
4625 // '!' Token operand. Handle that here. For example, the compatibilty
4626 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4627 if (Parser.getTok().is(AsmToken::Exclaim)) {
4628 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4629 Parser.getTok().getLoc()));
4630 Parser.Lex(); // Eat exclaim token
4634 // w/ a ':' after the '#', it's just like a plain ':'.
4637 case AsmToken::Colon: {
4638 // ":lower16:" and ":upper16:" expression prefixes
4639 // FIXME: Check it's an expression prefix,
4640 // e.g. (FOO - :lower16:BAR) isn't legal.
4641 ARMMCExpr::VariantKind RefKind;
4642 if (parsePrefix(RefKind))
4645 const MCExpr *SubExprVal;
4646 if (getParser().parseExpression(SubExprVal))
4649 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4651 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4652 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4658 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4659 // :lower16: and :upper16:.
4660 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4661 RefKind = ARMMCExpr::VK_ARM_None;
4663 // :lower16: and :upper16: modifiers
4664 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4665 Parser.Lex(); // Eat ':'
4667 if (getLexer().isNot(AsmToken::Identifier)) {
4668 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4672 StringRef IDVal = Parser.getTok().getIdentifier();
4673 if (IDVal == "lower16") {
4674 RefKind = ARMMCExpr::VK_ARM_LO16;
4675 } else if (IDVal == "upper16") {
4676 RefKind = ARMMCExpr::VK_ARM_HI16;
4678 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4683 if (getLexer().isNot(AsmToken::Colon)) {
4684 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4687 Parser.Lex(); // Eat the last ':'
4691 /// \brief Given a mnemonic, split out possible predication code and carry
4692 /// setting letters to form a canonical mnemonic and flags.
4694 // FIXME: Would be nice to autogen this.
4695 // FIXME: This is a bit of a maze of special cases.
4696 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4697 unsigned &PredicationCode,
4699 unsigned &ProcessorIMod,
4700 StringRef &ITMask) {
4701 PredicationCode = ARMCC::AL;
4702 CarrySetting = false;
4705 // Ignore some mnemonics we know aren't predicated forms.
4707 // FIXME: Would be nice to autogen this.
4708 if ((Mnemonic == "movs" && isThumb()) ||
4709 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4710 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4711 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4712 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4713 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
4714 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4715 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4716 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4717 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
4718 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4719 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4720 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
4723 // First, split out any predication code. Ignore mnemonics we know aren't
4724 // predicated but do have a carry-set and so weren't caught above.
4725 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4726 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4727 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4728 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4729 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4730 .Case("eq", ARMCC::EQ)
4731 .Case("ne", ARMCC::NE)
4732 .Case("hs", ARMCC::HS)
4733 .Case("cs", ARMCC::HS)
4734 .Case("lo", ARMCC::LO)
4735 .Case("cc", ARMCC::LO)
4736 .Case("mi", ARMCC::MI)
4737 .Case("pl", ARMCC::PL)
4738 .Case("vs", ARMCC::VS)
4739 .Case("vc", ARMCC::VC)
4740 .Case("hi", ARMCC::HI)
4741 .Case("ls", ARMCC::LS)
4742 .Case("ge", ARMCC::GE)
4743 .Case("lt", ARMCC::LT)
4744 .Case("gt", ARMCC::GT)
4745 .Case("le", ARMCC::LE)
4746 .Case("al", ARMCC::AL)
4749 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4750 PredicationCode = CC;
4754 // Next, determine if we have a carry setting bit. We explicitly ignore all
4755 // the instructions we know end in 's'.
4756 if (Mnemonic.endswith("s") &&
4757 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4758 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4759 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4760 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4761 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4762 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4763 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4764 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4765 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4766 (Mnemonic == "movs" && isThumb()))) {
4767 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4768 CarrySetting = true;
4771 // The "cps" instruction can have a interrupt mode operand which is glued into
4772 // the mnemonic. Check if this is the case, split it and parse the imod op
4773 if (Mnemonic.startswith("cps")) {
4774 // Split out any imod code.
4776 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4777 .Case("ie", ARM_PROC::IE)
4778 .Case("id", ARM_PROC::ID)
4781 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4782 ProcessorIMod = IMod;
4786 // The "it" instruction has the condition mask on the end of the mnemonic.
4787 if (Mnemonic.startswith("it")) {
4788 ITMask = Mnemonic.slice(2, Mnemonic.size());
4789 Mnemonic = Mnemonic.slice(0, 2);
4795 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4796 /// inclusion of carry set or predication code operands.
4798 // FIXME: It would be nice to autogen this.
4800 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4801 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
4802 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4803 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4804 Mnemonic == "add" || Mnemonic == "adc" ||
4805 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4806 Mnemonic == "orr" || Mnemonic == "mvn" ||
4807 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4808 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4809 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4810 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4811 Mnemonic == "mla" || Mnemonic == "smlal" ||
4812 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4813 CanAcceptCarrySet = true;
4815 CanAcceptCarrySet = false;
4817 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4818 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4819 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
4820 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4821 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
4822 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4823 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4824 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4825 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4826 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
4827 // These mnemonics are never predicable
4828 CanAcceptPredicationCode = false;
4829 } else if (!isThumb()) {
4830 // Some instructions are only predicable in Thumb mode
4831 CanAcceptPredicationCode
4832 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4833 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4834 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4835 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4836 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4837 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4838 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4839 } else if (isThumbOne()) {
4841 CanAcceptPredicationCode = Mnemonic != "movs";
4843 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4845 CanAcceptPredicationCode = true;
4848 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4849 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4850 // FIXME: This is all horribly hacky. We really need a better way to deal
4851 // with optional operands like this in the matcher table.
4853 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4854 // another does not. Specifically, the MOVW instruction does not. So we
4855 // special case it here and remove the defaulted (non-setting) cc_out
4856 // operand if that's the instruction we're trying to match.
4858 // We do this as post-processing of the explicit operands rather than just
4859 // conditionally adding the cc_out in the first place because we need
4860 // to check the type of the parsed immediate operand.
4861 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4862 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4863 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4864 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4867 // Register-register 'add' for thumb does not have a cc_out operand
4868 // when there are only two register operands.
4869 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4870 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4871 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4872 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4874 // Register-register 'add' for thumb does not have a cc_out operand
4875 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4876 // have to check the immediate range here since Thumb2 has a variant
4877 // that can handle a different range and has a cc_out operand.
4878 if (((isThumb() && Mnemonic == "add") ||
4879 (isThumbTwo() && Mnemonic == "sub")) &&
4880 Operands.size() == 6 &&
4881 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4882 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4883 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4884 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4885 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4886 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4888 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4889 // imm0_4095 variant. That's the least-preferred variant when
4890 // selecting via the generic "add" mnemonic, so to know that we
4891 // should remove the cc_out operand, we have to explicitly check that
4892 // it's not one of the other variants. Ugh.
4893 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4894 Operands.size() == 6 &&
4895 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4896 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4897 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4898 // Nest conditions rather than one big 'if' statement for readability.
4900 // If both registers are low, we're in an IT block, and the immediate is
4901 // in range, we should use encoding T1 instead, which has a cc_out.
4903 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4904 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4905 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4907 // Check against T3. If the second register is the PC, this is an
4908 // alternate form of ADR, which uses encoding T4, so check for that too.
4909 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4910 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4913 // Otherwise, we use encoding T4, which does not have a cc_out
4918 // The thumb2 multiply instruction doesn't have a CCOut register, so
4919 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4920 // use the 16-bit encoding or not.
4921 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4922 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4923 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4924 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4925 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4926 // If the registers aren't low regs, the destination reg isn't the
4927 // same as one of the source regs, or the cc_out operand is zero
4928 // outside of an IT block, we have to use the 32-bit encoding, so
4929 // remove the cc_out operand.
4930 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4931 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4932 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4934 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4935 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4936 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4937 static_cast<ARMOperand*>(Operands[4])->getReg())))
4940 // Also check the 'mul' syntax variant that doesn't specify an explicit
4941 // destination register.
4942 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4943 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4944 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4945 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4946 // If the registers aren't low regs or the cc_out operand is zero
4947 // outside of an IT block, we have to use the 32-bit encoding, so
4948 // remove the cc_out operand.
4949 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4950 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4956 // Register-register 'add/sub' for thumb does not have a cc_out operand
4957 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4958 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4959 // right, this will result in better diagnostics (which operand is off)
4961 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4962 (Operands.size() == 5 || Operands.size() == 6) &&
4963 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4964 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4965 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4966 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4967 (Operands.size() == 6 &&
4968 static_cast<ARMOperand*>(Operands[5])->isImm())))
4974 bool ARMAsmParser::shouldOmitPredicateOperand(
4975 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
4976 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
4977 unsigned RegIdx = 3;
4978 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
4979 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
4980 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
4981 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
4984 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
4985 (ARMMCRegisterClasses[ARM::DPRRegClassID]
4986 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
4987 ARMMCRegisterClasses[ARM::QPRRegClassID]
4988 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
4994 static bool isDataTypeToken(StringRef Tok) {
4995 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4996 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4997 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4998 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4999 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5000 Tok == ".f" || Tok == ".d";
5003 // FIXME: This bit should probably be handled via an explicit match class
5004 // in the .td files that matches the suffix instead of having it be
5005 // a literal string token the way it is now.
5006 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5007 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5009 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5010 unsigned VariantID);
5011 /// Parse an arm instruction mnemonic followed by its operands.
5012 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5014 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5015 // Apply mnemonic aliases before doing anything else, as the destination
5016 // mnemnonic may include suffices and we want to handle them normally.
5017 // The generic tblgen'erated code does this later, at the start of
5018 // MatchInstructionImpl(), but that's too late for aliases that include
5019 // any sort of suffix.
5020 unsigned AvailableFeatures = getAvailableFeatures();
5021 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5022 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5024 // First check for the ARM-specific .req directive.
5025 if (Parser.getTok().is(AsmToken::Identifier) &&
5026 Parser.getTok().getIdentifier() == ".req") {
5027 parseDirectiveReq(Name, NameLoc);
5028 // We always return 'error' for this, as we're done with this
5029 // statement and don't need to match the 'instruction."
5033 // Create the leading tokens for the mnemonic, split by '.' characters.
5034 size_t Start = 0, Next = Name.find('.');
5035 StringRef Mnemonic = Name.slice(Start, Next);
5037 // Split out the predication code and carry setting flag from the mnemonic.
5038 unsigned PredicationCode;
5039 unsigned ProcessorIMod;
5042 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5043 ProcessorIMod, ITMask);
5045 // In Thumb1, only the branch (B) instruction can be predicated.
5046 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5047 Parser.eatToEndOfStatement();
5048 return Error(NameLoc, "conditional execution not supported in Thumb1");
5051 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5053 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5054 // is the mask as it will be for the IT encoding if the conditional
5055 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5056 // where the conditional bit0 is zero, the instruction post-processing
5057 // will adjust the mask accordingly.
5058 if (Mnemonic == "it") {
5059 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5060 if (ITMask.size() > 3) {
5061 Parser.eatToEndOfStatement();
5062 return Error(Loc, "too many conditions on IT instruction");
5065 for (unsigned i = ITMask.size(); i != 0; --i) {
5066 char pos = ITMask[i - 1];
5067 if (pos != 't' && pos != 'e') {
5068 Parser.eatToEndOfStatement();
5069 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5072 if (ITMask[i - 1] == 't')
5075 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5078 // FIXME: This is all a pretty gross hack. We should automatically handle
5079 // optional operands like this via tblgen.
5081 // Next, add the CCOut and ConditionCode operands, if needed.
5083 // For mnemonics which can ever incorporate a carry setting bit or predication
5084 // code, our matching model involves us always generating CCOut and
5085 // ConditionCode operands to match the mnemonic "as written" and then we let
5086 // the matcher deal with finding the right instruction or generating an
5087 // appropriate error.
5088 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5089 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5091 // If we had a carry-set on an instruction that can't do that, issue an
5093 if (!CanAcceptCarrySet && CarrySetting) {
5094 Parser.eatToEndOfStatement();
5095 return Error(NameLoc, "instruction '" + Mnemonic +
5096 "' can not set flags, but 's' suffix specified");
5098 // If we had a predication code on an instruction that can't do that, issue an
5100 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5101 Parser.eatToEndOfStatement();
5102 return Error(NameLoc, "instruction '" + Mnemonic +
5103 "' is not predicable, but condition code specified");
5106 // Add the carry setting operand, if necessary.
5107 if (CanAcceptCarrySet) {
5108 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5109 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5113 // Add the predication code operand, if necessary.
5114 if (CanAcceptPredicationCode) {
5115 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5117 Operands.push_back(ARMOperand::CreateCondCode(
5118 ARMCC::CondCodes(PredicationCode), Loc));
5121 // Add the processor imod operand, if necessary.
5122 if (ProcessorIMod) {
5123 Operands.push_back(ARMOperand::CreateImm(
5124 MCConstantExpr::Create(ProcessorIMod, getContext()),
5128 // Add the remaining tokens in the mnemonic.
5129 while (Next != StringRef::npos) {
5131 Next = Name.find('.', Start + 1);
5132 StringRef ExtraToken = Name.slice(Start, Next);
5134 // Some NEON instructions have an optional datatype suffix that is
5135 // completely ignored. Check for that.
5136 if (isDataTypeToken(ExtraToken) &&
5137 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5140 // For for ARM mode generate an error if the .n qualifier is used.
5141 if (ExtraToken == ".n" && !isThumb()) {
5142 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5143 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5147 // The .n qualifier is always discarded as that is what the tables
5148 // and matcher expect. In ARM mode the .w qualifier has no effect,
5149 // so discard it to avoid errors that can be caused by the matcher.
5150 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5151 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5152 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5156 // Read the remaining operands.
5157 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5158 // Read the first operand.
5159 if (parseOperand(Operands, Mnemonic)) {
5160 Parser.eatToEndOfStatement();
5164 while (getLexer().is(AsmToken::Comma)) {
5165 Parser.Lex(); // Eat the comma.
5167 // Parse and remember the operand.
5168 if (parseOperand(Operands, Mnemonic)) {
5169 Parser.eatToEndOfStatement();
5175 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5176 SMLoc Loc = getLexer().getLoc();
5177 Parser.eatToEndOfStatement();
5178 return Error(Loc, "unexpected token in argument list");
5181 Parser.Lex(); // Consume the EndOfStatement
5183 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5184 // do and don't have a cc_out optional-def operand. With some spot-checks
5185 // of the operand list, we can figure out which variant we're trying to
5186 // parse and adjust accordingly before actually matching. We shouldn't ever
5187 // try to remove a cc_out operand that was explicitly set on the the
5188 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5189 // table driven matcher doesn't fit well with the ARM instruction set.
5190 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5191 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5192 Operands.erase(Operands.begin() + 1);
5196 // Some instructions have the same mnemonic, but don't always
5197 // have a predicate. Distinguish them here and delete the
5198 // predicate if needed.
5199 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5200 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5201 Operands.erase(Operands.begin() + 1);
5205 // ARM mode 'blx' need special handling, as the register operand version
5206 // is predicable, but the label operand version is not. So, we can't rely
5207 // on the Mnemonic based checking to correctly figure out when to put
5208 // a k_CondCode operand in the list. If we're trying to match the label
5209 // version, remove the k_CondCode operand here.
5210 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5211 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5212 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5213 Operands.erase(Operands.begin() + 1);
5217 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5218 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5219 // a single GPRPair reg operand is used in the .td file to replace the two
5220 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5221 // expressed as a GPRPair, so we have to manually merge them.
5222 // FIXME: We would really like to be able to tablegen'erate this.
5223 if (!isThumb() && Operands.size() > 4 &&
5224 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5225 Mnemonic == "stlexd")) {
5226 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5227 unsigned Idx = isLoad ? 2 : 3;
5228 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5229 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5231 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5232 // Adjust only if Op1 and Op2 are GPRs.
5233 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5234 MRC.contains(Op2->getReg())) {
5235 unsigned Reg1 = Op1->getReg();
5236 unsigned Reg2 = Op2->getReg();
5237 unsigned Rt = MRI->getEncodingValue(Reg1);
5238 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5240 // Rt2 must be Rt + 1 and Rt must be even.
5241 if (Rt + 1 != Rt2 || (Rt & 1)) {
5242 Error(Op2->getStartLoc(), isLoad ?
5243 "destination operands must be sequential" :
5244 "source operands must be sequential");
5247 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5248 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5249 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5250 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5251 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5257 // FIXME: As said above, this is all a pretty gross hack. This instruction
5258 // does not fit with other "subs" and tblgen.
5259 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5260 // so the Mnemonic is the original name "subs" and delete the predicate
5261 // operand so it will match the table entry.
5262 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5263 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5264 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5265 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5266 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5267 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5268 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5269 Operands.erase(Operands.begin());
5271 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5273 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5274 Operands.erase(Operands.begin() + 1);
5280 // Validate context-sensitive operand constraints.
5282 // return 'true' if register list contains non-low GPR registers,
5283 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5284 // 'containsReg' to true.
5285 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5286 unsigned HiReg, bool &containsReg) {
5287 containsReg = false;
5288 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5289 unsigned OpReg = Inst.getOperand(i).getReg();
5292 // Anything other than a low register isn't legal here.
5293 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5299 // Check if the specified regisgter is in the register list of the inst,
5300 // starting at the indicated operand number.
5301 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5302 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5303 unsigned OpReg = Inst.getOperand(i).getReg();
5310 // Return true if instruction has the interesting property of being
5311 // allowed in IT blocks, but not being predicable.
5312 static bool instIsBreakpoint(const MCInst &Inst) {
5313 return Inst.getOpcode() == ARM::tBKPT ||
5314 Inst.getOpcode() == ARM::BKPT ||
5315 Inst.getOpcode() == ARM::tHLT ||
5316 Inst.getOpcode() == ARM::HLT;
5320 // FIXME: We would really like to be able to tablegen'erate this.
5322 validateInstruction(MCInst &Inst,
5323 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5324 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
5325 SMLoc Loc = Operands[0]->getStartLoc();
5327 // Check the IT block state first.
5328 // NOTE: BKPT and HLT instructions have the interesting property of being
5329 // allowed in IT blocks, but not being predicable. They just always execute.
5330 if (inITBlock() && !instIsBreakpoint(Inst)) {
5332 if (ITState.FirstCond)
5333 ITState.FirstCond = false;
5335 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5336 // The instruction must be predicable.
5337 if (!MCID.isPredicable())
5338 return Error(Loc, "instructions in IT block must be predicable");
5339 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5340 unsigned ITCond = Bit ? ITState.Cond :
5341 ARMCC::getOppositeCondition(ITState.Cond);
5342 if (Cond != ITCond) {
5343 // Find the condition code Operand to get its SMLoc information.
5345 for (unsigned I = 1; I < Operands.size(); ++I)
5346 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5347 CondLoc = Operands[I]->getStartLoc();
5348 return Error(CondLoc, "incorrect condition in IT block; got '" +
5349 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5350 "', but expected '" +
5351 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5353 // Check for non-'al' condition codes outside of the IT block.
5354 } else if (isThumbTwo() && MCID.isPredicable() &&
5355 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5356 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5357 Inst.getOpcode() != ARM::t2Bcc)
5358 return Error(Loc, "predicated instructions must be in IT block");
5360 const unsigned Opcode = Inst.getOpcode();
5364 case ARM::LDRD_POST: {
5365 const unsigned RtReg = Inst.getOperand(0).getReg();
5368 if (RtReg == ARM::LR)
5369 return Error(Operands[3]->getStartLoc(),
5372 const unsigned Rt = MRI->getEncodingValue(RtReg);
5373 // Rt must be even-numbered.
5375 return Error(Operands[3]->getStartLoc(),
5376 "Rt must be even-numbered");
5378 // Rt2 must be Rt + 1.
5379 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5381 return Error(Operands[3]->getStartLoc(),
5382 "destination operands must be sequential");
5384 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5385 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5386 // For addressing modes with writeback, the base register needs to be
5387 // different from the destination registers.
5388 if (Rn == Rt || Rn == Rt2)
5389 return Error(Operands[3]->getStartLoc(),
5390 "base register needs to be different from destination "
5397 case ARM::t2LDRD_PRE:
5398 case ARM::t2LDRD_POST: {
5399 // Rt2 must be different from Rt.
5400 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5401 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5403 return Error(Operands[3]->getStartLoc(),
5404 "destination operands can't be identical");
5408 // Rt2 must be Rt + 1.
5409 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5410 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5412 return Error(Operands[3]->getStartLoc(),
5413 "source operands must be sequential");
5417 case ARM::STRD_POST: {
5418 // Rt2 must be Rt + 1.
5419 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5420 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5422 return Error(Operands[3]->getStartLoc(),
5423 "source operands must be sequential");
5428 // Width must be in range [1, 32-lsb].
5429 unsigned LSB = Inst.getOperand(2).getImm();
5430 unsigned Widthm1 = Inst.getOperand(3).getImm();
5431 if (Widthm1 >= 32 - LSB)
5432 return Error(Operands[5]->getStartLoc(),
5433 "bitfield width must be in range [1,32-lsb]");
5436 // Notionally handles ARM::tLDMIA_UPD too.
5438 // If we're parsing Thumb2, the .w variant is available and handles
5439 // most cases that are normally illegal for a Thumb1 LDM instruction.
5440 // We'll make the transformation in processInstruction() if necessary.
5442 // Thumb LDM instructions are writeback iff the base register is not
5443 // in the register list.
5444 unsigned Rn = Inst.getOperand(0).getReg();
5445 bool HasWritebackToken =
5446 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5447 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5448 bool ListContainsBase;
5449 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5450 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
5451 "registers must be in range r0-r7");
5452 // If we should have writeback, then there should be a '!' token.
5453 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
5454 return Error(Operands[2]->getStartLoc(),
5455 "writeback operator '!' expected");
5456 // If we should not have writeback, there must not be a '!'. This is
5457 // true even for the 32-bit wide encodings.
5458 if (ListContainsBase && HasWritebackToken)
5459 return Error(Operands[3]->getStartLoc(),
5460 "writeback operator '!' not allowed when base register "
5461 "in register list");
5465 case ARM::LDMIA_UPD:
5466 case ARM::LDMDB_UPD:
5467 case ARM::LDMIB_UPD:
5468 case ARM::LDMDA_UPD:
5469 // ARM variants loading and updating the same register are only officially
5470 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5474 case ARM::t2LDMIA_UPD:
5475 case ARM::t2LDMDB_UPD:
5476 case ARM::t2STMIA_UPD:
5477 case ARM::t2STMDB_UPD: {
5478 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5479 return Error(Operands.back()->getStartLoc(),
5480 "writeback register not allowed in register list");
5484 // The second source operand must be the same register as the destination
5487 // In this case, we must directly check the parsed operands because the
5488 // cvtThumbMultiply() function is written in such a way that it guarantees
5489 // this first statement is always true for the new Inst. Essentially, the
5490 // destination is unconditionally copied into the second source operand
5491 // without checking to see if it matches what we actually parsed.
5492 if (Operands.size() == 6 &&
5493 (((ARMOperand*)Operands[3])->getReg() !=
5494 ((ARMOperand*)Operands[5])->getReg()) &&
5495 (((ARMOperand*)Operands[3])->getReg() !=
5496 ((ARMOperand*)Operands[4])->getReg())) {
5497 return Error(Operands[3]->getStartLoc(),
5498 "destination register must match source register");
5502 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5503 // so only issue a diagnostic for thumb1. The instructions will be
5504 // switched to the t2 encodings in processInstruction() if necessary.
5506 bool ListContainsBase;
5507 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
5509 return Error(Operands[2]->getStartLoc(),
5510 "registers must be in range r0-r7 or pc");
5514 bool ListContainsBase;
5515 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
5517 return Error(Operands[2]->getStartLoc(),
5518 "registers must be in range r0-r7 or lr");
5521 case ARM::tSTMIA_UPD: {
5522 bool ListContainsBase, InvalidLowList;
5523 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5524 0, ListContainsBase);
5525 if (InvalidLowList && !isThumbTwo())
5526 return Error(Operands[4]->getStartLoc(),
5527 "registers must be in range r0-r7");
5529 // This would be converted to a 32-bit stm, but that's not valid if the
5530 // writeback register is in the list.
5531 if (InvalidLowList && ListContainsBase)
5532 return Error(Operands[4]->getStartLoc(),
5533 "writeback operator '!' not allowed when base register "
5534 "in register list");
5537 case ARM::tADDrSP: {
5538 // If the non-SP source operand and the destination operand are not the
5539 // same, we need thumb2 (for the wide encoding), or we have an error.
5540 if (!isThumbTwo() &&
5541 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5542 return Error(Operands[4]->getStartLoc(),
5543 "source register must be the same as destination");
5547 // Final range checking for Thumb unconditional branch instructions.
5549 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5550 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5553 int op = (Operands[2]->isImm()) ? 2 : 3;
5554 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5555 return Error(Operands[op]->getStartLoc(), "branch target out of range");
5558 // Final range checking for Thumb conditional branch instructions.
5560 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5561 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5564 int Op = (Operands[2]->isImm()) ? 2 : 3;
5565 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5566 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
5574 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5576 default: llvm_unreachable("unexpected opcode!");
5578 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5579 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5580 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5581 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5582 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5583 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5584 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5585 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5586 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5589 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5590 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5591 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5592 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5593 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5595 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5596 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5597 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5598 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5599 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5601 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5602 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5603 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5604 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5605 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5608 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5609 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5610 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5611 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5612 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5613 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5614 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5615 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5616 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5617 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5618 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5619 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5620 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5621 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5622 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5625 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5626 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5627 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5628 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5629 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5630 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5631 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5632 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5633 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5634 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5635 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5636 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5637 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5638 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5639 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5640 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5641 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5642 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5645 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5646 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5647 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5648 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5649 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5650 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5651 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5652 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5653 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5654 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5655 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5656 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5657 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5658 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5659 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5662 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5663 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5664 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5665 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5666 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5667 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5668 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5669 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5670 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5671 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5672 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5673 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5674 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5675 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5676 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5677 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5678 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5679 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5683 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5685 default: llvm_unreachable("unexpected opcode!");
5687 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5688 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5689 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5690 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5691 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5692 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5693 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5694 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5695 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5698 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5699 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5700 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5701 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5702 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5703 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5704 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5705 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5706 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5707 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5708 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5709 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5710 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5711 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5712 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5715 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5716 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5717 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5718 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5719 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5720 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5721 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5722 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5723 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5724 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5725 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5726 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5727 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5728 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5729 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5730 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5731 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5732 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5735 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5736 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5737 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5738 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5739 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5740 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5741 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5742 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5743 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5744 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5745 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5746 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5747 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5748 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5749 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5752 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5753 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5754 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5755 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5756 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5757 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5758 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5759 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5760 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5761 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5762 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5763 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5764 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5765 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5766 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5767 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5768 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5769 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5772 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5773 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5774 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5775 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5776 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5777 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5778 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5779 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5780 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5781 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5782 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5783 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5784 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5785 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5786 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5789 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5790 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5791 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5792 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5793 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5794 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5795 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5796 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5797 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5798 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5799 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5800 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5801 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5802 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5803 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5804 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5805 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5806 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5809 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5810 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5811 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5812 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5813 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5814 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5815 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5816 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5817 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5818 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5819 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5820 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5821 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5822 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5823 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5824 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5825 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5826 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5831 processInstruction(MCInst &Inst,
5832 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5833 switch (Inst.getOpcode()) {
5834 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5836 if (Inst.getOperand(1).getReg() != ARM::PC ||
5837 Inst.getOperand(5).getReg() != 0)
5840 TmpInst.setOpcode(ARM::ADR);
5841 TmpInst.addOperand(Inst.getOperand(0));
5842 TmpInst.addOperand(Inst.getOperand(2));
5843 TmpInst.addOperand(Inst.getOperand(3));
5844 TmpInst.addOperand(Inst.getOperand(4));
5848 // Aliases for alternate PC+imm syntax of LDR instructions.
5849 case ARM::t2LDRpcrel:
5850 // Select the narrow version if the immediate will fit.
5851 if (Inst.getOperand(1).getImm() > 0 &&
5852 Inst.getOperand(1).getImm() <= 0xff &&
5853 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5854 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
5855 Inst.setOpcode(ARM::tLDRpci);
5857 Inst.setOpcode(ARM::t2LDRpci);
5859 case ARM::t2LDRBpcrel:
5860 Inst.setOpcode(ARM::t2LDRBpci);
5862 case ARM::t2LDRHpcrel:
5863 Inst.setOpcode(ARM::t2LDRHpci);
5865 case ARM::t2LDRSBpcrel:
5866 Inst.setOpcode(ARM::t2LDRSBpci);
5868 case ARM::t2LDRSHpcrel:
5869 Inst.setOpcode(ARM::t2LDRSHpci);
5871 // Handle NEON VST complex aliases.
5872 case ARM::VST1LNdWB_register_Asm_8:
5873 case ARM::VST1LNdWB_register_Asm_16:
5874 case ARM::VST1LNdWB_register_Asm_32: {
5876 // Shuffle the operands around so the lane index operand is in the
5879 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5880 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5881 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5882 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5883 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5884 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5885 TmpInst.addOperand(Inst.getOperand(1)); // lane
5886 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5887 TmpInst.addOperand(Inst.getOperand(6));
5892 case ARM::VST2LNdWB_register_Asm_8:
5893 case ARM::VST2LNdWB_register_Asm_16:
5894 case ARM::VST2LNdWB_register_Asm_32:
5895 case ARM::VST2LNqWB_register_Asm_16:
5896 case ARM::VST2LNqWB_register_Asm_32: {
5898 // Shuffle the operands around so the lane index operand is in the
5901 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5902 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5903 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5904 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5905 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5906 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5907 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5909 TmpInst.addOperand(Inst.getOperand(1)); // lane
5910 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5911 TmpInst.addOperand(Inst.getOperand(6));
5916 case ARM::VST3LNdWB_register_Asm_8:
5917 case ARM::VST3LNdWB_register_Asm_16:
5918 case ARM::VST3LNdWB_register_Asm_32:
5919 case ARM::VST3LNqWB_register_Asm_16:
5920 case ARM::VST3LNqWB_register_Asm_32: {
5922 // Shuffle the operands around so the lane index operand is in the
5925 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5926 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5927 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5928 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5929 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5930 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5931 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5933 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5935 TmpInst.addOperand(Inst.getOperand(1)); // lane
5936 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5937 TmpInst.addOperand(Inst.getOperand(6));
5942 case ARM::VST4LNdWB_register_Asm_8:
5943 case ARM::VST4LNdWB_register_Asm_16:
5944 case ARM::VST4LNdWB_register_Asm_32:
5945 case ARM::VST4LNqWB_register_Asm_16:
5946 case ARM::VST4LNqWB_register_Asm_32: {
5948 // Shuffle the operands around so the lane index operand is in the
5951 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5952 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5953 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5954 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5955 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5956 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5957 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5959 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5961 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5963 TmpInst.addOperand(Inst.getOperand(1)); // lane
5964 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5965 TmpInst.addOperand(Inst.getOperand(6));
5970 case ARM::VST1LNdWB_fixed_Asm_8:
5971 case ARM::VST1LNdWB_fixed_Asm_16:
5972 case ARM::VST1LNdWB_fixed_Asm_32: {
5974 // Shuffle the operands around so the lane index operand is in the
5977 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5978 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5979 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5980 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5981 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5982 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5983 TmpInst.addOperand(Inst.getOperand(1)); // lane
5984 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5985 TmpInst.addOperand(Inst.getOperand(5));
5990 case ARM::VST2LNdWB_fixed_Asm_8:
5991 case ARM::VST2LNdWB_fixed_Asm_16:
5992 case ARM::VST2LNdWB_fixed_Asm_32:
5993 case ARM::VST2LNqWB_fixed_Asm_16:
5994 case ARM::VST2LNqWB_fixed_Asm_32: {
5996 // Shuffle the operands around so the lane index operand is in the
5999 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6000 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6001 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6002 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6003 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6004 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6005 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6007 TmpInst.addOperand(Inst.getOperand(1)); // lane
6008 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6009 TmpInst.addOperand(Inst.getOperand(5));
6014 case ARM::VST3LNdWB_fixed_Asm_8:
6015 case ARM::VST3LNdWB_fixed_Asm_16:
6016 case ARM::VST3LNdWB_fixed_Asm_32:
6017 case ARM::VST3LNqWB_fixed_Asm_16:
6018 case ARM::VST3LNqWB_fixed_Asm_32: {
6020 // Shuffle the operands around so the lane index operand is in the
6023 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6024 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6025 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6026 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6027 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6028 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6029 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6031 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6033 TmpInst.addOperand(Inst.getOperand(1)); // lane
6034 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6035 TmpInst.addOperand(Inst.getOperand(5));
6040 case ARM::VST4LNdWB_fixed_Asm_8:
6041 case ARM::VST4LNdWB_fixed_Asm_16:
6042 case ARM::VST4LNdWB_fixed_Asm_32:
6043 case ARM::VST4LNqWB_fixed_Asm_16:
6044 case ARM::VST4LNqWB_fixed_Asm_32: {
6046 // Shuffle the operands around so the lane index operand is in the
6049 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6050 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6051 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6052 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6053 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6054 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6055 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6057 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6059 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6061 TmpInst.addOperand(Inst.getOperand(1)); // lane
6062 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6063 TmpInst.addOperand(Inst.getOperand(5));
6068 case ARM::VST1LNdAsm_8:
6069 case ARM::VST1LNdAsm_16:
6070 case ARM::VST1LNdAsm_32: {
6072 // Shuffle the operands around so the lane index operand is in the
6075 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6076 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6077 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6078 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6079 TmpInst.addOperand(Inst.getOperand(1)); // lane
6080 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6081 TmpInst.addOperand(Inst.getOperand(5));
6086 case ARM::VST2LNdAsm_8:
6087 case ARM::VST2LNdAsm_16:
6088 case ARM::VST2LNdAsm_32:
6089 case ARM::VST2LNqAsm_16:
6090 case ARM::VST2LNqAsm_32: {
6092 // Shuffle the operands around so the lane index operand is in the
6095 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6096 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6097 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6098 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6099 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6101 TmpInst.addOperand(Inst.getOperand(1)); // lane
6102 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6103 TmpInst.addOperand(Inst.getOperand(5));
6108 case ARM::VST3LNdAsm_8:
6109 case ARM::VST3LNdAsm_16:
6110 case ARM::VST3LNdAsm_32:
6111 case ARM::VST3LNqAsm_16:
6112 case ARM::VST3LNqAsm_32: {
6114 // Shuffle the operands around so the lane index operand is in the
6117 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6118 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6119 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6120 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6121 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6123 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6125 TmpInst.addOperand(Inst.getOperand(1)); // lane
6126 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6127 TmpInst.addOperand(Inst.getOperand(5));
6132 case ARM::VST4LNdAsm_8:
6133 case ARM::VST4LNdAsm_16:
6134 case ARM::VST4LNdAsm_32:
6135 case ARM::VST4LNqAsm_16:
6136 case ARM::VST4LNqAsm_32: {
6138 // Shuffle the operands around so the lane index operand is in the
6141 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6142 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6143 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6144 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6145 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6147 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6149 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6151 TmpInst.addOperand(Inst.getOperand(1)); // lane
6152 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6153 TmpInst.addOperand(Inst.getOperand(5));
6158 // Handle NEON VLD complex aliases.
6159 case ARM::VLD1LNdWB_register_Asm_8:
6160 case ARM::VLD1LNdWB_register_Asm_16:
6161 case ARM::VLD1LNdWB_register_Asm_32: {
6163 // Shuffle the operands around so the lane index operand is in the
6166 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6167 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6168 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6169 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6170 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6171 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6172 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6173 TmpInst.addOperand(Inst.getOperand(1)); // lane
6174 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6175 TmpInst.addOperand(Inst.getOperand(6));
6180 case ARM::VLD2LNdWB_register_Asm_8:
6181 case ARM::VLD2LNdWB_register_Asm_16:
6182 case ARM::VLD2LNdWB_register_Asm_32:
6183 case ARM::VLD2LNqWB_register_Asm_16:
6184 case ARM::VLD2LNqWB_register_Asm_32: {
6186 // Shuffle the operands around so the lane index operand is in the
6189 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6190 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6191 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6193 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6194 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6195 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6196 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6197 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6198 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6200 TmpInst.addOperand(Inst.getOperand(1)); // lane
6201 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6202 TmpInst.addOperand(Inst.getOperand(6));
6207 case ARM::VLD3LNdWB_register_Asm_8:
6208 case ARM::VLD3LNdWB_register_Asm_16:
6209 case ARM::VLD3LNdWB_register_Asm_32:
6210 case ARM::VLD3LNqWB_register_Asm_16:
6211 case ARM::VLD3LNqWB_register_Asm_32: {
6213 // Shuffle the operands around so the lane index operand is in the
6216 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6217 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6218 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6220 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6222 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6223 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6224 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6225 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6226 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6227 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6229 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6231 TmpInst.addOperand(Inst.getOperand(1)); // lane
6232 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6233 TmpInst.addOperand(Inst.getOperand(6));
6238 case ARM::VLD4LNdWB_register_Asm_8:
6239 case ARM::VLD4LNdWB_register_Asm_16:
6240 case ARM::VLD4LNdWB_register_Asm_32:
6241 case ARM::VLD4LNqWB_register_Asm_16:
6242 case ARM::VLD4LNqWB_register_Asm_32: {
6244 // Shuffle the operands around so the lane index operand is in the
6247 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6248 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6249 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6251 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6253 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6255 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6256 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6257 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6258 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6259 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6260 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6262 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6264 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6266 TmpInst.addOperand(Inst.getOperand(1)); // lane
6267 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6268 TmpInst.addOperand(Inst.getOperand(6));
6273 case ARM::VLD1LNdWB_fixed_Asm_8:
6274 case ARM::VLD1LNdWB_fixed_Asm_16:
6275 case ARM::VLD1LNdWB_fixed_Asm_32: {
6277 // Shuffle the operands around so the lane index operand is in the
6280 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6281 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6282 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6283 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6284 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6285 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6286 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6287 TmpInst.addOperand(Inst.getOperand(1)); // lane
6288 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6289 TmpInst.addOperand(Inst.getOperand(5));
6294 case ARM::VLD2LNdWB_fixed_Asm_8:
6295 case ARM::VLD2LNdWB_fixed_Asm_16:
6296 case ARM::VLD2LNdWB_fixed_Asm_32:
6297 case ARM::VLD2LNqWB_fixed_Asm_16:
6298 case ARM::VLD2LNqWB_fixed_Asm_32: {
6300 // Shuffle the operands around so the lane index operand is in the
6303 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6304 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6305 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6307 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6308 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6309 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6310 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6311 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6312 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6314 TmpInst.addOperand(Inst.getOperand(1)); // lane
6315 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6316 TmpInst.addOperand(Inst.getOperand(5));
6321 case ARM::VLD3LNdWB_fixed_Asm_8:
6322 case ARM::VLD3LNdWB_fixed_Asm_16:
6323 case ARM::VLD3LNdWB_fixed_Asm_32:
6324 case ARM::VLD3LNqWB_fixed_Asm_16:
6325 case ARM::VLD3LNqWB_fixed_Asm_32: {
6327 // Shuffle the operands around so the lane index operand is in the
6330 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6331 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6332 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6334 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6336 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6337 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6338 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6339 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6340 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6341 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6343 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6345 TmpInst.addOperand(Inst.getOperand(1)); // lane
6346 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6347 TmpInst.addOperand(Inst.getOperand(5));
6352 case ARM::VLD4LNdWB_fixed_Asm_8:
6353 case ARM::VLD4LNdWB_fixed_Asm_16:
6354 case ARM::VLD4LNdWB_fixed_Asm_32:
6355 case ARM::VLD4LNqWB_fixed_Asm_16:
6356 case ARM::VLD4LNqWB_fixed_Asm_32: {
6358 // Shuffle the operands around so the lane index operand is in the
6361 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6362 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6363 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6365 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6367 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6369 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6370 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6371 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6372 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6373 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6374 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6376 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6378 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6380 TmpInst.addOperand(Inst.getOperand(1)); // lane
6381 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6382 TmpInst.addOperand(Inst.getOperand(5));
6387 case ARM::VLD1LNdAsm_8:
6388 case ARM::VLD1LNdAsm_16:
6389 case ARM::VLD1LNdAsm_32: {
6391 // Shuffle the operands around so the lane index operand is in the
6394 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6395 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6396 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6397 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6398 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6399 TmpInst.addOperand(Inst.getOperand(1)); // lane
6400 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6401 TmpInst.addOperand(Inst.getOperand(5));
6406 case ARM::VLD2LNdAsm_8:
6407 case ARM::VLD2LNdAsm_16:
6408 case ARM::VLD2LNdAsm_32:
6409 case ARM::VLD2LNqAsm_16:
6410 case ARM::VLD2LNqAsm_32: {
6412 // Shuffle the operands around so the lane index operand is in the
6415 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6416 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6417 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6419 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6420 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6421 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6422 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6424 TmpInst.addOperand(Inst.getOperand(1)); // lane
6425 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6426 TmpInst.addOperand(Inst.getOperand(5));
6431 case ARM::VLD3LNdAsm_8:
6432 case ARM::VLD3LNdAsm_16:
6433 case ARM::VLD3LNdAsm_32:
6434 case ARM::VLD3LNqAsm_16:
6435 case ARM::VLD3LNqAsm_32: {
6437 // Shuffle the operands around so the lane index operand is in the
6440 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6441 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6442 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6444 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6446 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6447 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6448 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6449 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6451 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6453 TmpInst.addOperand(Inst.getOperand(1)); // lane
6454 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6455 TmpInst.addOperand(Inst.getOperand(5));
6460 case ARM::VLD4LNdAsm_8:
6461 case ARM::VLD4LNdAsm_16:
6462 case ARM::VLD4LNdAsm_32:
6463 case ARM::VLD4LNqAsm_16:
6464 case ARM::VLD4LNqAsm_32: {
6466 // Shuffle the operands around so the lane index operand is in the
6469 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6470 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6471 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6477 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6478 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6479 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6480 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6482 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6484 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6486 TmpInst.addOperand(Inst.getOperand(1)); // lane
6487 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6488 TmpInst.addOperand(Inst.getOperand(5));
6493 // VLD3DUP single 3-element structure to all lanes instructions.
6494 case ARM::VLD3DUPdAsm_8:
6495 case ARM::VLD3DUPdAsm_16:
6496 case ARM::VLD3DUPdAsm_32:
6497 case ARM::VLD3DUPqAsm_8:
6498 case ARM::VLD3DUPqAsm_16:
6499 case ARM::VLD3DUPqAsm_32: {
6502 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6503 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6504 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6506 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6508 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6509 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6510 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6511 TmpInst.addOperand(Inst.getOperand(4));
6516 case ARM::VLD3DUPdWB_fixed_Asm_8:
6517 case ARM::VLD3DUPdWB_fixed_Asm_16:
6518 case ARM::VLD3DUPdWB_fixed_Asm_32:
6519 case ARM::VLD3DUPqWB_fixed_Asm_8:
6520 case ARM::VLD3DUPqWB_fixed_Asm_16:
6521 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6524 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6525 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6526 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6530 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6531 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6532 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6533 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6534 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6535 TmpInst.addOperand(Inst.getOperand(4));
6540 case ARM::VLD3DUPdWB_register_Asm_8:
6541 case ARM::VLD3DUPdWB_register_Asm_16:
6542 case ARM::VLD3DUPdWB_register_Asm_32:
6543 case ARM::VLD3DUPqWB_register_Asm_8:
6544 case ARM::VLD3DUPqWB_register_Asm_16:
6545 case ARM::VLD3DUPqWB_register_Asm_32: {
6548 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6549 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6550 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6552 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6554 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6555 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6556 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6557 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6558 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6559 TmpInst.addOperand(Inst.getOperand(5));
6564 // VLD3 multiple 3-element structure instructions.
6565 case ARM::VLD3dAsm_8:
6566 case ARM::VLD3dAsm_16:
6567 case ARM::VLD3dAsm_32:
6568 case ARM::VLD3qAsm_8:
6569 case ARM::VLD3qAsm_16:
6570 case ARM::VLD3qAsm_32: {
6573 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6574 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6575 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6577 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6579 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6580 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6581 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6582 TmpInst.addOperand(Inst.getOperand(4));
6587 case ARM::VLD3dWB_fixed_Asm_8:
6588 case ARM::VLD3dWB_fixed_Asm_16:
6589 case ARM::VLD3dWB_fixed_Asm_32:
6590 case ARM::VLD3qWB_fixed_Asm_8:
6591 case ARM::VLD3qWB_fixed_Asm_16:
6592 case ARM::VLD3qWB_fixed_Asm_32: {
6595 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6596 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6599 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6601 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6602 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6603 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6604 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6605 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6606 TmpInst.addOperand(Inst.getOperand(4));
6611 case ARM::VLD3dWB_register_Asm_8:
6612 case ARM::VLD3dWB_register_Asm_16:
6613 case ARM::VLD3dWB_register_Asm_32:
6614 case ARM::VLD3qWB_register_Asm_8:
6615 case ARM::VLD3qWB_register_Asm_16:
6616 case ARM::VLD3qWB_register_Asm_32: {
6619 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6620 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6625 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6626 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6627 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6628 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6629 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6630 TmpInst.addOperand(Inst.getOperand(5));
6635 // VLD4DUP single 3-element structure to all lanes instructions.
6636 case ARM::VLD4DUPdAsm_8:
6637 case ARM::VLD4DUPdAsm_16:
6638 case ARM::VLD4DUPdAsm_32:
6639 case ARM::VLD4DUPqAsm_8:
6640 case ARM::VLD4DUPqAsm_16:
6641 case ARM::VLD4DUPqAsm_32: {
6644 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6645 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6646 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6648 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6650 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6652 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6653 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6654 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6655 TmpInst.addOperand(Inst.getOperand(4));
6660 case ARM::VLD4DUPdWB_fixed_Asm_8:
6661 case ARM::VLD4DUPdWB_fixed_Asm_16:
6662 case ARM::VLD4DUPdWB_fixed_Asm_32:
6663 case ARM::VLD4DUPqWB_fixed_Asm_8:
6664 case ARM::VLD4DUPqWB_fixed_Asm_16:
6665 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6668 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6669 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6670 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6672 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6676 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6677 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6678 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6679 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6680 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6681 TmpInst.addOperand(Inst.getOperand(4));
6686 case ARM::VLD4DUPdWB_register_Asm_8:
6687 case ARM::VLD4DUPdWB_register_Asm_16:
6688 case ARM::VLD4DUPdWB_register_Asm_32:
6689 case ARM::VLD4DUPqWB_register_Asm_8:
6690 case ARM::VLD4DUPqWB_register_Asm_16:
6691 case ARM::VLD4DUPqWB_register_Asm_32: {
6694 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6695 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6696 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6700 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6702 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6703 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6704 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6705 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6706 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6707 TmpInst.addOperand(Inst.getOperand(5));
6712 // VLD4 multiple 4-element structure instructions.
6713 case ARM::VLD4dAsm_8:
6714 case ARM::VLD4dAsm_16:
6715 case ARM::VLD4dAsm_32:
6716 case ARM::VLD4qAsm_8:
6717 case ARM::VLD4qAsm_16:
6718 case ARM::VLD4qAsm_32: {
6721 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6722 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6723 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6725 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6727 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6729 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6730 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6731 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6732 TmpInst.addOperand(Inst.getOperand(4));
6737 case ARM::VLD4dWB_fixed_Asm_8:
6738 case ARM::VLD4dWB_fixed_Asm_16:
6739 case ARM::VLD4dWB_fixed_Asm_32:
6740 case ARM::VLD4qWB_fixed_Asm_8:
6741 case ARM::VLD4qWB_fixed_Asm_16:
6742 case ARM::VLD4qWB_fixed_Asm_32: {
6745 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6746 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6749 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6751 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6753 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6754 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6755 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6756 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6757 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6758 TmpInst.addOperand(Inst.getOperand(4));
6763 case ARM::VLD4dWB_register_Asm_8:
6764 case ARM::VLD4dWB_register_Asm_16:
6765 case ARM::VLD4dWB_register_Asm_32:
6766 case ARM::VLD4qWB_register_Asm_8:
6767 case ARM::VLD4qWB_register_Asm_16:
6768 case ARM::VLD4qWB_register_Asm_32: {
6771 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6772 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6773 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6775 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6779 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6780 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6781 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6782 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6783 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6784 TmpInst.addOperand(Inst.getOperand(5));
6789 // VST3 multiple 3-element structure instructions.
6790 case ARM::VST3dAsm_8:
6791 case ARM::VST3dAsm_16:
6792 case ARM::VST3dAsm_32:
6793 case ARM::VST3qAsm_8:
6794 case ARM::VST3qAsm_16:
6795 case ARM::VST3qAsm_32: {
6798 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6799 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6800 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6801 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6802 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6804 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6806 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6807 TmpInst.addOperand(Inst.getOperand(4));
6812 case ARM::VST3dWB_fixed_Asm_8:
6813 case ARM::VST3dWB_fixed_Asm_16:
6814 case ARM::VST3dWB_fixed_Asm_32:
6815 case ARM::VST3qWB_fixed_Asm_8:
6816 case ARM::VST3qWB_fixed_Asm_16:
6817 case ARM::VST3qWB_fixed_Asm_32: {
6820 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6821 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6822 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6823 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6824 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6825 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6826 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6828 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6830 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6831 TmpInst.addOperand(Inst.getOperand(4));
6836 case ARM::VST3dWB_register_Asm_8:
6837 case ARM::VST3dWB_register_Asm_16:
6838 case ARM::VST3dWB_register_Asm_32:
6839 case ARM::VST3qWB_register_Asm_8:
6840 case ARM::VST3qWB_register_Asm_16:
6841 case ARM::VST3qWB_register_Asm_32: {
6844 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6845 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6846 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6847 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6848 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6849 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6850 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6852 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6854 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6855 TmpInst.addOperand(Inst.getOperand(5));
6860 // VST4 multiple 3-element structure instructions.
6861 case ARM::VST4dAsm_8:
6862 case ARM::VST4dAsm_16:
6863 case ARM::VST4dAsm_32:
6864 case ARM::VST4qAsm_8:
6865 case ARM::VST4qAsm_16:
6866 case ARM::VST4qAsm_32: {
6869 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6870 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6871 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6872 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6873 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6875 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6877 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6879 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6880 TmpInst.addOperand(Inst.getOperand(4));
6885 case ARM::VST4dWB_fixed_Asm_8:
6886 case ARM::VST4dWB_fixed_Asm_16:
6887 case ARM::VST4dWB_fixed_Asm_32:
6888 case ARM::VST4qWB_fixed_Asm_8:
6889 case ARM::VST4qWB_fixed_Asm_16:
6890 case ARM::VST4qWB_fixed_Asm_32: {
6893 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6894 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6895 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6896 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6897 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6898 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6899 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6901 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6903 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6905 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6906 TmpInst.addOperand(Inst.getOperand(4));
6911 case ARM::VST4dWB_register_Asm_8:
6912 case ARM::VST4dWB_register_Asm_16:
6913 case ARM::VST4dWB_register_Asm_32:
6914 case ARM::VST4qWB_register_Asm_8:
6915 case ARM::VST4qWB_register_Asm_16:
6916 case ARM::VST4qWB_register_Asm_32: {
6919 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6920 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6921 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6922 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6923 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6924 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6925 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6927 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6929 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6931 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6932 TmpInst.addOperand(Inst.getOperand(5));
6937 // Handle encoding choice for the shift-immediate instructions.
6940 case ARM::t2ASRri: {
6941 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6942 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6943 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6944 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6945 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6947 switch (Inst.getOpcode()) {
6948 default: llvm_unreachable("unexpected opcode");
6949 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6950 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6951 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6953 // The Thumb1 operands aren't in the same order. Awesome, eh?
6955 TmpInst.setOpcode(NewOpc);
6956 TmpInst.addOperand(Inst.getOperand(0));
6957 TmpInst.addOperand(Inst.getOperand(5));
6958 TmpInst.addOperand(Inst.getOperand(1));
6959 TmpInst.addOperand(Inst.getOperand(2));
6960 TmpInst.addOperand(Inst.getOperand(3));
6961 TmpInst.addOperand(Inst.getOperand(4));
6968 // Handle the Thumb2 mode MOV complex aliases.
6970 case ARM::t2MOVSsr: {
6971 // Which instruction to expand to depends on the CCOut operand and
6972 // whether we're in an IT block if the register operands are low
6974 bool isNarrow = false;
6975 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6976 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6977 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6978 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6979 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6983 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6984 default: llvm_unreachable("unexpected opcode!");
6985 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6986 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6987 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6988 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6990 TmpInst.setOpcode(newOpc);
6991 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6993 TmpInst.addOperand(MCOperand::CreateReg(
6994 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6995 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6996 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6997 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6998 TmpInst.addOperand(Inst.getOperand(5));
7000 TmpInst.addOperand(MCOperand::CreateReg(
7001 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7006 case ARM::t2MOVSsi: {
7007 // Which instruction to expand to depends on the CCOut operand and
7008 // whether we're in an IT block if the register operands are low
7010 bool isNarrow = false;
7011 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7012 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7013 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7017 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7018 default: llvm_unreachable("unexpected opcode!");
7019 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7020 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7021 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7022 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7023 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7025 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7026 if (Amount == 32) Amount = 0;
7027 TmpInst.setOpcode(newOpc);
7028 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7030 TmpInst.addOperand(MCOperand::CreateReg(
7031 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7032 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7033 if (newOpc != ARM::t2RRX)
7034 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7035 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7036 TmpInst.addOperand(Inst.getOperand(4));
7038 TmpInst.addOperand(MCOperand::CreateReg(
7039 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7043 // Handle the ARM mode MOV complex aliases.
7048 ARM_AM::ShiftOpc ShiftTy;
7049 switch(Inst.getOpcode()) {
7050 default: llvm_unreachable("unexpected opcode!");
7051 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7052 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7053 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7054 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7056 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7058 TmpInst.setOpcode(ARM::MOVsr);
7059 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7060 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7061 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7062 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7063 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7064 TmpInst.addOperand(Inst.getOperand(4));
7065 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7073 ARM_AM::ShiftOpc ShiftTy;
7074 switch(Inst.getOpcode()) {
7075 default: llvm_unreachable("unexpected opcode!");
7076 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7077 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7078 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7079 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7081 // A shift by zero is a plain MOVr, not a MOVsi.
7082 unsigned Amt = Inst.getOperand(2).getImm();
7083 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7084 // A shift by 32 should be encoded as 0 when permitted
7085 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7087 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7089 TmpInst.setOpcode(Opc);
7090 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7091 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7092 if (Opc == ARM::MOVsi)
7093 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7094 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7095 TmpInst.addOperand(Inst.getOperand(4));
7096 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7101 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7103 TmpInst.setOpcode(ARM::MOVsi);
7104 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7105 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7106 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7107 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7108 TmpInst.addOperand(Inst.getOperand(3));
7109 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7113 case ARM::t2LDMIA_UPD: {
7114 // If this is a load of a single register, then we should use
7115 // a post-indexed LDR instruction instead, per the ARM ARM.
7116 if (Inst.getNumOperands() != 5)
7119 TmpInst.setOpcode(ARM::t2LDR_POST);
7120 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7121 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7122 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7123 TmpInst.addOperand(MCOperand::CreateImm(4));
7124 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7125 TmpInst.addOperand(Inst.getOperand(3));
7129 case ARM::t2STMDB_UPD: {
7130 // If this is a store of a single register, then we should use
7131 // a pre-indexed STR instruction instead, per the ARM ARM.
7132 if (Inst.getNumOperands() != 5)
7135 TmpInst.setOpcode(ARM::t2STR_PRE);
7136 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7137 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7138 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7139 TmpInst.addOperand(MCOperand::CreateImm(-4));
7140 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7141 TmpInst.addOperand(Inst.getOperand(3));
7145 case ARM::LDMIA_UPD:
7146 // If this is a load of a single register via a 'pop', then we should use
7147 // a post-indexed LDR instruction instead, per the ARM ARM.
7148 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7149 Inst.getNumOperands() == 5) {
7151 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7152 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7153 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7154 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7155 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7156 TmpInst.addOperand(MCOperand::CreateImm(4));
7157 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7158 TmpInst.addOperand(Inst.getOperand(3));
7163 case ARM::STMDB_UPD:
7164 // If this is a store of a single register via a 'push', then we should use
7165 // a pre-indexed STR instruction instead, per the ARM ARM.
7166 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7167 Inst.getNumOperands() == 5) {
7169 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7170 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7171 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7172 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7173 TmpInst.addOperand(MCOperand::CreateImm(-4));
7174 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7175 TmpInst.addOperand(Inst.getOperand(3));
7179 case ARM::t2ADDri12:
7180 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7181 // mnemonic was used (not "addw"), encoding T3 is preferred.
7182 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7183 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7185 Inst.setOpcode(ARM::t2ADDri);
7186 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7188 case ARM::t2SUBri12:
7189 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7190 // mnemonic was used (not "subw"), encoding T3 is preferred.
7191 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7192 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7194 Inst.setOpcode(ARM::t2SUBri);
7195 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7198 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7199 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7200 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7201 // to encoding T1 if <Rd> is omitted."
7202 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7203 Inst.setOpcode(ARM::tADDi3);
7208 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7209 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7210 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7211 // to encoding T1 if <Rd> is omitted."
7212 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7213 Inst.setOpcode(ARM::tSUBi3);
7218 case ARM::t2SUBri: {
7219 // If the destination and first source operand are the same, and
7220 // the flags are compatible with the current IT status, use encoding T2
7221 // instead of T3. For compatibility with the system 'as'. Make sure the
7222 // wide encoding wasn't explicit.
7223 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7224 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7225 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7226 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7227 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7228 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7229 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7232 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7233 ARM::tADDi8 : ARM::tSUBi8);
7234 TmpInst.addOperand(Inst.getOperand(0));
7235 TmpInst.addOperand(Inst.getOperand(5));
7236 TmpInst.addOperand(Inst.getOperand(0));
7237 TmpInst.addOperand(Inst.getOperand(2));
7238 TmpInst.addOperand(Inst.getOperand(3));
7239 TmpInst.addOperand(Inst.getOperand(4));
7243 case ARM::t2ADDrr: {
7244 // If the destination and first source operand are the same, and
7245 // there's no setting of the flags, use encoding T2 instead of T3.
7246 // Note that this is only for ADD, not SUB. This mirrors the system
7247 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7248 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7249 Inst.getOperand(5).getReg() != 0 ||
7250 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7251 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7254 TmpInst.setOpcode(ARM::tADDhirr);
7255 TmpInst.addOperand(Inst.getOperand(0));
7256 TmpInst.addOperand(Inst.getOperand(0));
7257 TmpInst.addOperand(Inst.getOperand(2));
7258 TmpInst.addOperand(Inst.getOperand(3));
7259 TmpInst.addOperand(Inst.getOperand(4));
7263 case ARM::tADDrSP: {
7264 // If the non-SP source operand and the destination operand are not the
7265 // same, we need to use the 32-bit encoding if it's available.
7266 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7267 Inst.setOpcode(ARM::t2ADDrr);
7268 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7274 // A Thumb conditional branch outside of an IT block is a tBcc.
7275 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7276 Inst.setOpcode(ARM::tBcc);
7281 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7282 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7283 Inst.setOpcode(ARM::t2Bcc);
7288 // If the conditional is AL or we're in an IT block, we really want t2B.
7289 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7290 Inst.setOpcode(ARM::t2B);
7295 // If the conditional is AL, we really want tB.
7296 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7297 Inst.setOpcode(ARM::tB);
7302 // If the register list contains any high registers, or if the writeback
7303 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7304 // instead if we're in Thumb2. Otherwise, this should have generated
7305 // an error in validateInstruction().
7306 unsigned Rn = Inst.getOperand(0).getReg();
7307 bool hasWritebackToken =
7308 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7309 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7310 bool listContainsBase;
7311 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7312 (!listContainsBase && !hasWritebackToken) ||
7313 (listContainsBase && hasWritebackToken)) {
7314 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7315 assert (isThumbTwo());
7316 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7317 // If we're switching to the updating version, we need to insert
7318 // the writeback tied operand.
7319 if (hasWritebackToken)
7320 Inst.insert(Inst.begin(),
7321 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7326 case ARM::tSTMIA_UPD: {
7327 // If the register list contains any high registers, we need to use
7328 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7329 // should have generated an error in validateInstruction().
7330 unsigned Rn = Inst.getOperand(0).getReg();
7331 bool listContainsBase;
7332 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7333 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7334 assert (isThumbTwo());
7335 Inst.setOpcode(ARM::t2STMIA_UPD);
7341 bool listContainsBase;
7342 // If the register list contains any high registers, we need to use
7343 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7344 // should have generated an error in validateInstruction().
7345 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7347 assert (isThumbTwo());
7348 Inst.setOpcode(ARM::t2LDMIA_UPD);
7349 // Add the base register and writeback operands.
7350 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7351 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7355 bool listContainsBase;
7356 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7358 assert (isThumbTwo());
7359 Inst.setOpcode(ARM::t2STMDB_UPD);
7360 // Add the base register and writeback operands.
7361 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7362 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7366 // If we can use the 16-bit encoding and the user didn't explicitly
7367 // request the 32-bit variant, transform it here.
7368 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7369 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7370 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7371 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7372 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7373 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7374 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7375 // The operands aren't in the same order for tMOVi8...
7377 TmpInst.setOpcode(ARM::tMOVi8);
7378 TmpInst.addOperand(Inst.getOperand(0));
7379 TmpInst.addOperand(Inst.getOperand(4));
7380 TmpInst.addOperand(Inst.getOperand(1));
7381 TmpInst.addOperand(Inst.getOperand(2));
7382 TmpInst.addOperand(Inst.getOperand(3));
7389 // If we can use the 16-bit encoding and the user didn't explicitly
7390 // request the 32-bit variant, transform it here.
7391 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7392 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7393 Inst.getOperand(2).getImm() == ARMCC::AL &&
7394 Inst.getOperand(4).getReg() == ARM::CPSR &&
7395 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7396 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7397 // The operands aren't the same for tMOV[S]r... (no cc_out)
7399 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7400 TmpInst.addOperand(Inst.getOperand(0));
7401 TmpInst.addOperand(Inst.getOperand(1));
7402 TmpInst.addOperand(Inst.getOperand(2));
7403 TmpInst.addOperand(Inst.getOperand(3));
7413 // If we can use the 16-bit encoding and the user didn't explicitly
7414 // request the 32-bit variant, transform it here.
7415 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7416 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7417 Inst.getOperand(2).getImm() == 0 &&
7418 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7419 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7421 switch (Inst.getOpcode()) {
7422 default: llvm_unreachable("Illegal opcode!");
7423 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7424 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7425 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7426 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7428 // The operands aren't the same for thumb1 (no rotate operand).
7430 TmpInst.setOpcode(NewOpc);
7431 TmpInst.addOperand(Inst.getOperand(0));
7432 TmpInst.addOperand(Inst.getOperand(1));
7433 TmpInst.addOperand(Inst.getOperand(3));
7434 TmpInst.addOperand(Inst.getOperand(4));
7441 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7442 // rrx shifts and asr/lsr of #32 is encoded as 0
7443 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7445 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7446 // Shifting by zero is accepted as a vanilla 'MOVr'
7448 TmpInst.setOpcode(ARM::MOVr);
7449 TmpInst.addOperand(Inst.getOperand(0));
7450 TmpInst.addOperand(Inst.getOperand(1));
7451 TmpInst.addOperand(Inst.getOperand(3));
7452 TmpInst.addOperand(Inst.getOperand(4));
7453 TmpInst.addOperand(Inst.getOperand(5));
7466 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7467 if (SOpc == ARM_AM::rrx) return false;
7468 switch (Inst.getOpcode()) {
7469 default: llvm_unreachable("unexpected opcode!");
7470 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7471 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7472 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7473 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7474 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7475 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7477 // If the shift is by zero, use the non-shifted instruction definition.
7478 // The exception is for right shifts, where 0 == 32
7479 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7480 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7482 TmpInst.setOpcode(newOpc);
7483 TmpInst.addOperand(Inst.getOperand(0));
7484 TmpInst.addOperand(Inst.getOperand(1));
7485 TmpInst.addOperand(Inst.getOperand(2));
7486 TmpInst.addOperand(Inst.getOperand(4));
7487 TmpInst.addOperand(Inst.getOperand(5));
7488 TmpInst.addOperand(Inst.getOperand(6));
7496 // The mask bits for all but the first condition are represented as
7497 // the low bit of the condition code value implies 't'. We currently
7498 // always have 1 implies 't', so XOR toggle the bits if the low bit
7499 // of the condition code is zero.
7500 MCOperand &MO = Inst.getOperand(1);
7501 unsigned Mask = MO.getImm();
7502 unsigned OrigMask = Mask;
7503 unsigned TZ = countTrailingZeros(Mask);
7504 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7505 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7506 Mask ^= (0xE << TZ) & 0xF;
7510 // Set up the IT block state according to the IT instruction we just
7512 assert(!inITBlock() && "nested IT blocks?!");
7513 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7514 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7515 ITState.CurPosition = 0;
7516 ITState.FirstCond = true;
7526 // Assemblers should use the narrow encodings of these instructions when permissible.
7527 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7528 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7529 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7530 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7531 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7532 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7533 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7535 switch (Inst.getOpcode()) {
7536 default: llvm_unreachable("unexpected opcode");
7537 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7538 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7539 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7540 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7541 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7542 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7545 TmpInst.setOpcode(NewOpc);
7546 TmpInst.addOperand(Inst.getOperand(0));
7547 TmpInst.addOperand(Inst.getOperand(5));
7548 TmpInst.addOperand(Inst.getOperand(1));
7549 TmpInst.addOperand(Inst.getOperand(2));
7550 TmpInst.addOperand(Inst.getOperand(3));
7551 TmpInst.addOperand(Inst.getOperand(4));
7562 // Assemblers should use the narrow encodings of these instructions when permissible.
7563 // These instructions are special in that they are commutable, so shorter encodings
7564 // are available more often.
7565 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7566 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7567 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7568 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7569 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7570 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7571 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7572 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7574 switch (Inst.getOpcode()) {
7575 default: llvm_unreachable("unexpected opcode");
7576 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7577 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7578 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7579 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7582 TmpInst.setOpcode(NewOpc);
7583 TmpInst.addOperand(Inst.getOperand(0));
7584 TmpInst.addOperand(Inst.getOperand(5));
7585 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7586 TmpInst.addOperand(Inst.getOperand(1));
7587 TmpInst.addOperand(Inst.getOperand(2));
7589 TmpInst.addOperand(Inst.getOperand(2));
7590 TmpInst.addOperand(Inst.getOperand(1));
7592 TmpInst.addOperand(Inst.getOperand(3));
7593 TmpInst.addOperand(Inst.getOperand(4));
7603 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7604 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7605 // suffix depending on whether they're in an IT block or not.
7606 unsigned Opc = Inst.getOpcode();
7607 const MCInstrDesc &MCID = MII.get(Opc);
7608 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7609 assert(MCID.hasOptionalDef() &&
7610 "optionally flag setting instruction missing optional def operand");
7611 assert(MCID.NumOperands == Inst.getNumOperands() &&
7612 "operand count mismatch!");
7613 // Find the optional-def operand (cc_out).
7616 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7619 // If we're parsing Thumb1, reject it completely.
7620 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7621 return Match_MnemonicFail;
7622 // If we're parsing Thumb2, which form is legal depends on whether we're
7624 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7626 return Match_RequiresITBlock;
7627 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7629 return Match_RequiresNotITBlock;
7631 // Some high-register supporting Thumb1 encodings only allow both registers
7632 // to be from r0-r7 when in Thumb2.
7633 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7634 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7635 isARMLowRegister(Inst.getOperand(2).getReg()))
7636 return Match_RequiresThumb2;
7637 // Others only require ARMv6 or later.
7638 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7639 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7640 isARMLowRegister(Inst.getOperand(1).getReg()))
7641 return Match_RequiresV6;
7642 return Match_Success;
7645 static const char *getSubtargetFeatureName(unsigned Val);
7647 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7648 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7649 MCStreamer &Out, unsigned &ErrorInfo,
7650 bool MatchingInlineAsm) {
7652 unsigned MatchResult;
7654 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7656 switch (MatchResult) {
7659 // Context sensitive operand constraints aren't handled by the matcher,
7660 // so check them here.
7661 if (validateInstruction(Inst, Operands)) {
7662 // Still progress the IT block, otherwise one wrong condition causes
7663 // nasty cascading errors.
7664 forwardITPosition();
7668 { // processInstruction() updates inITBlock state, we need to save it away
7669 bool wasInITBlock = inITBlock();
7671 // Some instructions need post-processing to, for example, tweak which
7672 // encoding is selected. Loop on it while changes happen so the
7673 // individual transformations can chain off each other. E.g.,
7674 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7675 while (processInstruction(Inst, Operands))
7678 // Only after the instruction is fully processed, we can validate it
7679 if (wasInITBlock && hasV8Ops() && isThumb() &&
7680 !isV8EligibleForIT(&Inst, 2)) {
7681 Warning(IDLoc, "deprecated instruction in IT block");
7685 // Only move forward at the very end so that everything in validate
7686 // and process gets a consistent answer about whether we're in an IT
7688 forwardITPosition();
7690 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7691 // doesn't actually encode.
7692 if (Inst.getOpcode() == ARM::ITasm)
7696 Out.EmitInstruction(Inst);
7698 case Match_MissingFeature: {
7699 assert(ErrorInfo && "Unknown missing feature!");
7700 // Special case the error message for the very common case where only
7701 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7702 std::string Msg = "instruction requires:";
7704 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7705 if (ErrorInfo & Mask) {
7707 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7711 return Error(IDLoc, Msg);
7713 case Match_InvalidOperand: {
7714 SMLoc ErrorLoc = IDLoc;
7715 if (ErrorInfo != ~0U) {
7716 if (ErrorInfo >= Operands.size())
7717 return Error(IDLoc, "too few operands for instruction");
7719 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7720 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7723 return Error(ErrorLoc, "invalid operand for instruction");
7725 case Match_MnemonicFail:
7726 return Error(IDLoc, "invalid instruction",
7727 ((ARMOperand*)Operands[0])->getLocRange());
7728 case Match_RequiresNotITBlock:
7729 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7730 case Match_RequiresITBlock:
7731 return Error(IDLoc, "instruction only valid inside IT block");
7732 case Match_RequiresV6:
7733 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7734 case Match_RequiresThumb2:
7735 return Error(IDLoc, "instruction variant requires Thumb2");
7736 case Match_ImmRange0_15: {
7737 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7738 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7739 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7741 case Match_ImmRange0_239: {
7742 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7743 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7744 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7748 llvm_unreachable("Implement any new match types added!");
7751 /// parseDirective parses the arm specific directives
7752 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7753 StringRef IDVal = DirectiveID.getIdentifier();
7754 if (IDVal == ".word")
7755 return parseDirectiveWord(4, DirectiveID.getLoc());
7756 else if (IDVal == ".thumb")
7757 return parseDirectiveThumb(DirectiveID.getLoc());
7758 else if (IDVal == ".arm")
7759 return parseDirectiveARM(DirectiveID.getLoc());
7760 else if (IDVal == ".thumb_func")
7761 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7762 else if (IDVal == ".code")
7763 return parseDirectiveCode(DirectiveID.getLoc());
7764 else if (IDVal == ".syntax")
7765 return parseDirectiveSyntax(DirectiveID.getLoc());
7766 else if (IDVal == ".unreq")
7767 return parseDirectiveUnreq(DirectiveID.getLoc());
7768 else if (IDVal == ".arch")
7769 return parseDirectiveArch(DirectiveID.getLoc());
7770 else if (IDVal == ".eabi_attribute")
7771 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7772 else if (IDVal == ".cpu")
7773 return parseDirectiveCPU(DirectiveID.getLoc());
7774 else if (IDVal == ".fpu")
7775 return parseDirectiveFPU(DirectiveID.getLoc());
7776 else if (IDVal == ".fnstart")
7777 return parseDirectiveFnStart(DirectiveID.getLoc());
7778 else if (IDVal == ".fnend")
7779 return parseDirectiveFnEnd(DirectiveID.getLoc());
7780 else if (IDVal == ".cantunwind")
7781 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7782 else if (IDVal == ".personality")
7783 return parseDirectivePersonality(DirectiveID.getLoc());
7784 else if (IDVal == ".handlerdata")
7785 return parseDirectiveHandlerData(DirectiveID.getLoc());
7786 else if (IDVal == ".setfp")
7787 return parseDirectiveSetFP(DirectiveID.getLoc());
7788 else if (IDVal == ".pad")
7789 return parseDirectivePad(DirectiveID.getLoc());
7790 else if (IDVal == ".save")
7791 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7792 else if (IDVal == ".vsave")
7793 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7797 /// parseDirectiveWord
7798 /// ::= .word [ expression (, expression)* ]
7799 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7800 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7802 const MCExpr *Value;
7803 if (getParser().parseExpression(Value))
7806 getParser().getStreamer().EmitValue(Value, Size);
7808 if (getLexer().is(AsmToken::EndOfStatement))
7811 // FIXME: Improve diagnostic.
7812 if (getLexer().isNot(AsmToken::Comma))
7813 return Error(L, "unexpected token in directive");
7822 /// parseDirectiveThumb
7824 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7825 if (getLexer().isNot(AsmToken::EndOfStatement))
7826 return Error(L, "unexpected token in directive");
7830 return Error(L, "target does not support Thumb mode");
7834 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7838 /// parseDirectiveARM
7840 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7841 if (getLexer().isNot(AsmToken::EndOfStatement))
7842 return Error(L, "unexpected token in directive");
7846 return Error(L, "target does not support ARM mode");
7850 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7854 void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
7855 if (NextSymbolIsThumb) {
7856 getParser().getStreamer().EmitThumbFunc(Symbol);
7857 NextSymbolIsThumb = false;
7861 /// parseDirectiveThumbFunc
7862 /// ::= .thumbfunc symbol_name
7863 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7864 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7865 bool isMachO = MAI->hasSubsectionsViaSymbols();
7867 // Darwin asm has (optionally) function name after .thumb_func direction
7870 const AsmToken &Tok = Parser.getTok();
7871 if (Tok.isNot(AsmToken::EndOfStatement)) {
7872 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7873 return Error(L, "unexpected token in .thumb_func directive");
7875 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
7876 getParser().getStreamer().EmitThumbFunc(Func);
7877 Parser.Lex(); // Consume the identifier token.
7882 if (getLexer().isNot(AsmToken::EndOfStatement))
7883 return Error(L, "unexpected token in directive");
7885 NextSymbolIsThumb = true;
7890 /// parseDirectiveSyntax
7891 /// ::= .syntax unified | divided
7892 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7893 const AsmToken &Tok = Parser.getTok();
7894 if (Tok.isNot(AsmToken::Identifier))
7895 return Error(L, "unexpected token in .syntax directive");
7896 StringRef Mode = Tok.getString();
7897 if (Mode == "unified" || Mode == "UNIFIED")
7899 else if (Mode == "divided" || Mode == "DIVIDED")
7900 return Error(L, "'.syntax divided' arm asssembly not supported");
7902 return Error(L, "unrecognized syntax mode in .syntax directive");
7904 if (getLexer().isNot(AsmToken::EndOfStatement))
7905 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7908 // TODO tell the MC streamer the mode
7909 // getParser().getStreamer().Emit???();
7913 /// parseDirectiveCode
7914 /// ::= .code 16 | 32
7915 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7916 const AsmToken &Tok = Parser.getTok();
7917 if (Tok.isNot(AsmToken::Integer))
7918 return Error(L, "unexpected token in .code directive");
7919 int64_t Val = Parser.getTok().getIntVal();
7925 return Error(L, "invalid operand to .code directive");
7927 if (getLexer().isNot(AsmToken::EndOfStatement))
7928 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7933 return Error(L, "target does not support Thumb mode");
7937 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7940 return Error(L, "target does not support ARM mode");
7944 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7950 /// parseDirectiveReq
7951 /// ::= name .req registername
7952 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7953 Parser.Lex(); // Eat the '.req' token.
7955 SMLoc SRegLoc, ERegLoc;
7956 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7957 Parser.eatToEndOfStatement();
7958 return Error(SRegLoc, "register name expected");
7961 // Shouldn't be anything else.
7962 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7963 Parser.eatToEndOfStatement();
7964 return Error(Parser.getTok().getLoc(),
7965 "unexpected input in .req directive.");
7968 Parser.Lex(); // Consume the EndOfStatement
7970 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7971 return Error(SRegLoc, "redefinition of '" + Name +
7972 "' does not match original.");
7977 /// parseDirectiveUneq
7978 /// ::= .unreq registername
7979 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7980 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7981 Parser.eatToEndOfStatement();
7982 return Error(L, "unexpected input in .unreq directive.");
7984 RegisterReqs.erase(Parser.getTok().getIdentifier());
7985 Parser.Lex(); // Eat the identifier.
7989 /// parseDirectiveArch
7991 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7995 /// parseDirectiveEabiAttr
7996 /// ::= .eabi_attribute int, int
7997 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7998 if (Parser.getTok().isNot(AsmToken::Integer))
7999 return Error(L, "integer expected");
8000 int64_t Tag = Parser.getTok().getIntVal();
8001 Parser.Lex(); // eat tag integer
8003 if (Parser.getTok().isNot(AsmToken::Comma))
8004 return Error(L, "comma expected");
8005 Parser.Lex(); // skip comma
8007 L = Parser.getTok().getLoc();
8008 if (Parser.getTok().isNot(AsmToken::Integer))
8009 return Error(L, "integer expected");
8010 int64_t Value = Parser.getTok().getIntVal();
8011 Parser.Lex(); // eat value integer
8013 getTargetStreamer().emitAttribute(Tag, Value);
8017 /// parseDirectiveCPU
8019 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8020 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8021 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8025 /// parseDirectiveFPU
8027 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8028 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8030 unsigned ID = StringSwitch<unsigned>(FPU)
8031 #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8032 #include "ARMFPUName.def"
8033 .Default(ARM::INVALID_FPU);
8035 if (ID == ARM::INVALID_FPU)
8036 return Error(L, "Unknown FPU name");
8038 getTargetStreamer().emitFPU(ID);
8042 /// parseDirectiveFnStart
8044 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8045 if (FnStartLoc.isValid()) {
8046 Error(L, ".fnstart starts before the end of previous one");
8047 Error(FnStartLoc, "previous .fnstart starts here");
8052 getTargetStreamer().emitFnStart();
8056 /// parseDirectiveFnEnd
8058 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8059 // Check the ordering of unwind directives
8060 if (!FnStartLoc.isValid())
8061 return Error(L, ".fnstart must precede .fnend directive");
8063 // Reset the unwind directives parser state
8064 resetUnwindDirectiveParserState();
8065 getTargetStreamer().emitFnEnd();
8069 /// parseDirectiveCantUnwind
8071 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8072 // Check the ordering of unwind directives
8074 if (!FnStartLoc.isValid())
8075 return Error(L, ".fnstart must precede .cantunwind directive");
8076 if (HandlerDataLoc.isValid()) {
8077 Error(L, ".cantunwind can't be used with .handlerdata directive");
8078 Error(HandlerDataLoc, ".handlerdata was specified here");
8081 if (PersonalityLoc.isValid()) {
8082 Error(L, ".cantunwind can't be used with .personality directive");
8083 Error(PersonalityLoc, ".personality was specified here");
8087 getTargetStreamer().emitCantUnwind();
8091 /// parseDirectivePersonality
8092 /// ::= .personality name
8093 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8094 // Check the ordering of unwind directives
8096 if (!FnStartLoc.isValid())
8097 return Error(L, ".fnstart must precede .personality directive");
8098 if (CantUnwindLoc.isValid()) {
8099 Error(L, ".personality can't be used with .cantunwind directive");
8100 Error(CantUnwindLoc, ".cantunwind was specified here");
8103 if (HandlerDataLoc.isValid()) {
8104 Error(L, ".personality must precede .handlerdata directive");
8105 Error(HandlerDataLoc, ".handlerdata was specified here");
8109 // Parse the name of the personality routine
8110 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8111 Parser.eatToEndOfStatement();
8112 return Error(L, "unexpected input in .personality directive.");
8114 StringRef Name(Parser.getTok().getIdentifier());
8117 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8118 getTargetStreamer().emitPersonality(PR);
8122 /// parseDirectiveHandlerData
8123 /// ::= .handlerdata
8124 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8125 // Check the ordering of unwind directives
8127 if (!FnStartLoc.isValid())
8128 return Error(L, ".fnstart must precede .personality directive");
8129 if (CantUnwindLoc.isValid()) {
8130 Error(L, ".handlerdata can't be used with .cantunwind directive");
8131 Error(CantUnwindLoc, ".cantunwind was specified here");
8135 getTargetStreamer().emitHandlerData();
8139 /// parseDirectiveSetFP
8140 /// ::= .setfp fpreg, spreg [, offset]
8141 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8142 // Check the ordering of unwind directives
8143 if (!FnStartLoc.isValid())
8144 return Error(L, ".fnstart must precede .setfp directive");
8145 if (HandlerDataLoc.isValid())
8146 return Error(L, ".setfp must precede .handlerdata directive");
8149 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8150 int NewFPReg = tryParseRegister();
8152 return Error(NewFPRegLoc, "frame pointer register expected");
8155 if (!Parser.getTok().is(AsmToken::Comma))
8156 return Error(Parser.getTok().getLoc(), "comma expected");
8157 Parser.Lex(); // skip comma
8160 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8161 int NewSPReg = tryParseRegister();
8163 return Error(NewSPRegLoc, "stack pointer register expected");
8165 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8166 return Error(NewSPRegLoc,
8167 "register should be either $sp or the latest fp register");
8169 // Update the frame pointer register
8174 if (Parser.getTok().is(AsmToken::Comma)) {
8175 Parser.Lex(); // skip comma
8177 if (Parser.getTok().isNot(AsmToken::Hash) &&
8178 Parser.getTok().isNot(AsmToken::Dollar)) {
8179 return Error(Parser.getTok().getLoc(), "'#' expected");
8181 Parser.Lex(); // skip hash token.
8183 const MCExpr *OffsetExpr;
8184 SMLoc ExLoc = Parser.getTok().getLoc();
8186 if (getParser().parseExpression(OffsetExpr, EndLoc))
8187 return Error(ExLoc, "malformed setfp offset");
8188 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8190 return Error(ExLoc, "setfp offset must be an immediate");
8192 Offset = CE->getValue();
8195 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8196 static_cast<unsigned>(NewSPReg), Offset);
8202 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8203 // Check the ordering of unwind directives
8204 if (!FnStartLoc.isValid())
8205 return Error(L, ".fnstart must precede .pad directive");
8206 if (HandlerDataLoc.isValid())
8207 return Error(L, ".pad must precede .handlerdata directive");
8210 if (Parser.getTok().isNot(AsmToken::Hash) &&
8211 Parser.getTok().isNot(AsmToken::Dollar)) {
8212 return Error(Parser.getTok().getLoc(), "'#' expected");
8214 Parser.Lex(); // skip hash token.
8216 const MCExpr *OffsetExpr;
8217 SMLoc ExLoc = Parser.getTok().getLoc();
8219 if (getParser().parseExpression(OffsetExpr, EndLoc))
8220 return Error(ExLoc, "malformed pad offset");
8221 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8223 return Error(ExLoc, "pad offset must be an immediate");
8225 getTargetStreamer().emitPad(CE->getValue());
8229 /// parseDirectiveRegSave
8230 /// ::= .save { registers }
8231 /// ::= .vsave { registers }
8232 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8233 // Check the ordering of unwind directives
8234 if (!FnStartLoc.isValid())
8235 return Error(L, ".fnstart must precede .save or .vsave directives");
8236 if (HandlerDataLoc.isValid())
8237 return Error(L, ".save or .vsave must precede .handlerdata directive");
8239 // RAII object to make sure parsed operands are deleted.
8240 struct CleanupObject {
8241 SmallVector<MCParsedAsmOperand *, 1> Operands;
8243 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8248 // Parse the register list
8249 if (parseRegisterList(CO.Operands))
8251 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
8252 if (!IsVector && !Op->isRegList())
8253 return Error(L, ".save expects GPR registers");
8254 if (IsVector && !Op->isDPRRegList())
8255 return Error(L, ".vsave expects DPR registers");
8257 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
8261 /// Force static initialization.
8262 extern "C" void LLVMInitializeARMAsmParser() {
8263 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8264 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8267 #define GET_REGISTER_MATCHER
8268 #define GET_SUBTARGET_FEATURE_NAME
8269 #define GET_MATCHER_IMPLEMENTATION
8270 #include "ARMGenAsmMatcher.inc"
8272 // Define this matcher function after the auto-generated include so we
8273 // have the match class enum definitions.
8274 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8276 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8277 // If the kind is a token for a literal immediate, check if our asm
8278 // operand matches. This is for InstAliases which have a fixed-value
8279 // immediate in the syntax.
8280 if (Kind == MCK__35_0 && Op->isImm()) {
8281 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8283 return Match_InvalidOperand;
8284 if (CE->getValue() == 0)
8285 return Match_Success;
8287 return Match_InvalidOperand;