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 "MCTargetDesc/ARMBaseInfo.h"
11 #include "MCTargetDesc/ARMAddressingModes.h"
12 #include "MCTargetDesc/ARMMCExpr.h"
13 #include "llvm/MC/MCParser/MCAsmLexer.h"
14 #include "llvm/MC/MCParser/MCAsmParser.h"
15 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCInstrDesc.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/MC/MCTargetAsmParser.h"
25 #include "llvm/Support/MathExtras.h"
26 #include "llvm/Support/SourceMgr.h"
27 #include "llvm/Support/TargetRegistry.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include "llvm/ADT/BitVector.h"
30 #include "llvm/ADT/OwningPtr.h"
31 #include "llvm/ADT/STLExtras.h"
32 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/ADT/StringSwitch.h"
34 #include "llvm/ADT/Twine.h"
42 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
44 class ARMAsmParser : public MCTargetAsmParser {
47 const MCRegisterInfo *MRI;
49 // Map of register aliases registers via the .req directive.
50 StringMap<unsigned> RegisterReqs;
53 ARMCC::CondCodes Cond; // Condition for IT block.
54 unsigned Mask:4; // Condition mask for instructions.
55 // Starting at first 1 (from lsb).
56 // '1' condition as indicated in IT.
57 // '0' inverse of condition (else).
58 // Count of instructions in IT block is
59 // 4 - trailingzeroes(mask)
61 bool FirstCond; // Explicit flag for when we're parsing the
62 // First instruction in the IT block. It's
63 // implied in the mask, so needs special
66 unsigned CurPosition; // Current position in parsing of IT
67 // block. In range [0,3]. Initialized
68 // according to count of instructions in block.
69 // ~0U if no active IT block.
71 bool inITBlock() { return ITState.CurPosition != ~0U;}
72 void forwardITPosition() {
73 if (!inITBlock()) return;
74 // Move to the next instruction in the IT block, if there is one. If not,
75 // mark the block as done.
76 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
77 if (++ITState.CurPosition == 5 - TZ)
78 ITState.CurPosition = ~0U; // Done with the IT block after this.
82 MCAsmParser &getParser() const { return Parser; }
83 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
85 bool Warning(SMLoc L, const Twine &Msg,
86 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
87 return Parser.Warning(L, Msg, Ranges);
89 bool Error(SMLoc L, const Twine &Msg,
90 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
91 return Parser.Error(L, Msg, Ranges);
94 int tryParseRegister();
95 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
96 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
97 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
98 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
99 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
100 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
101 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
102 unsigned &ShiftAmount);
103 bool parseDirectiveWord(unsigned Size, SMLoc L);
104 bool parseDirectiveThumb(SMLoc L);
105 bool parseDirectiveARM(SMLoc L);
106 bool parseDirectiveThumbFunc(SMLoc L);
107 bool parseDirectiveCode(SMLoc L);
108 bool parseDirectiveSyntax(SMLoc L);
109 bool parseDirectiveReq(StringRef Name, SMLoc L);
110 bool parseDirectiveUnreq(SMLoc L);
111 bool parseDirectiveArch(SMLoc L);
112 bool parseDirectiveEabiAttr(SMLoc L);
114 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
115 bool &CarrySetting, unsigned &ProcessorIMod,
117 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
118 bool &CanAcceptPredicationCode);
120 bool isThumb() const {
121 // FIXME: Can tablegen auto-generate this?
122 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
124 bool isThumbOne() const {
125 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
127 bool isThumbTwo() const {
128 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
130 bool hasV6Ops() const {
131 return STI.getFeatureBits() & ARM::HasV6Ops;
133 bool hasV7Ops() const {
134 return STI.getFeatureBits() & ARM::HasV7Ops;
137 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
138 setAvailableFeatures(FB);
140 bool isMClass() const {
141 return STI.getFeatureBits() & ARM::FeatureMClass;
144 /// @name Auto-generated Match Functions
147 #define GET_ASSEMBLER_HEADER
148 #include "ARMGenAsmMatcher.inc"
152 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
153 OperandMatchResultTy parseCoprocNumOperand(
154 SmallVectorImpl<MCParsedAsmOperand*>&);
155 OperandMatchResultTy parseCoprocRegOperand(
156 SmallVectorImpl<MCParsedAsmOperand*>&);
157 OperandMatchResultTy parseCoprocOptionOperand(
158 SmallVectorImpl<MCParsedAsmOperand*>&);
159 OperandMatchResultTy parseMemBarrierOptOperand(
160 SmallVectorImpl<MCParsedAsmOperand*>&);
161 OperandMatchResultTy parseProcIFlagsOperand(
162 SmallVectorImpl<MCParsedAsmOperand*>&);
163 OperandMatchResultTy parseMSRMaskOperand(
164 SmallVectorImpl<MCParsedAsmOperand*>&);
165 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
166 StringRef Op, int Low, int High);
167 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
168 return parsePKHImm(O, "lsl", 0, 31);
170 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
171 return parsePKHImm(O, "asr", 1, 32);
173 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
174 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
175 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
176 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
177 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
178 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
179 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
180 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
181 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
183 // Asm Match Converter Methods
184 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
185 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
186 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
187 const SmallVectorImpl<MCParsedAsmOperand*> &);
188 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
189 const SmallVectorImpl<MCParsedAsmOperand*> &);
190 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
191 const SmallVectorImpl<MCParsedAsmOperand*> &);
192 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
193 const SmallVectorImpl<MCParsedAsmOperand*> &);
194 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
195 const SmallVectorImpl<MCParsedAsmOperand*> &);
196 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
197 const SmallVectorImpl<MCParsedAsmOperand*> &);
198 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
199 const SmallVectorImpl<MCParsedAsmOperand*> &);
200 void cvtLdExtTWriteBackImm(MCInst &Inst,
201 const SmallVectorImpl<MCParsedAsmOperand*> &);
202 void cvtLdExtTWriteBackReg(MCInst &Inst,
203 const SmallVectorImpl<MCParsedAsmOperand*> &);
204 void cvtStExtTWriteBackImm(MCInst &Inst,
205 const SmallVectorImpl<MCParsedAsmOperand*> &);
206 void cvtStExtTWriteBackReg(MCInst &Inst,
207 const SmallVectorImpl<MCParsedAsmOperand*> &);
208 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
209 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
210 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
211 const SmallVectorImpl<MCParsedAsmOperand*> &);
212 void cvtThumbMultiply(MCInst &Inst,
213 const SmallVectorImpl<MCParsedAsmOperand*> &);
214 void cvtVLDwbFixed(MCInst &Inst,
215 const SmallVectorImpl<MCParsedAsmOperand*> &);
216 void cvtVLDwbRegister(MCInst &Inst,
217 const SmallVectorImpl<MCParsedAsmOperand*> &);
218 void cvtVSTwbFixed(MCInst &Inst,
219 const SmallVectorImpl<MCParsedAsmOperand*> &);
220 void cvtVSTwbRegister(MCInst &Inst,
221 const SmallVectorImpl<MCParsedAsmOperand*> &);
222 bool validateInstruction(MCInst &Inst,
223 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
224 bool processInstruction(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
226 bool shouldOmitCCOutOperand(StringRef Mnemonic,
227 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
230 enum ARMMatchResultTy {
231 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
232 Match_RequiresNotITBlock,
234 Match_RequiresThumb2,
235 #define GET_OPERAND_DIAGNOSTIC_TYPES
236 #include "ARMGenAsmMatcher.inc"
240 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
241 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
242 MCAsmParserExtension::Initialize(_Parser);
244 // Cache the MCRegisterInfo.
245 MRI = &getContext().getRegisterInfo();
247 // Initialize the set of available features.
248 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
250 // Not in an ITBlock to start with.
251 ITState.CurPosition = ~0U;
254 // Implementation of the MCTargetAsmParser interface:
255 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
256 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
257 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
258 bool ParseDirective(AsmToken DirectiveID);
260 unsigned checkTargetMatchPredicate(MCInst &Inst);
262 bool MatchAndEmitInstruction(SMLoc IDLoc,
263 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
266 } // end anonymous namespace
270 /// ARMOperand - Instances of this class represent a parsed ARM machine
272 class ARMOperand : public MCParsedAsmOperand {
292 k_VectorListAllLanes,
298 k_BitfieldDescriptor,
302 SMLoc StartLoc, EndLoc;
303 SmallVector<unsigned, 8> Registers;
307 ARMCC::CondCodes Val;
327 ARM_PROC::IFlags Val;
343 // A vector register list is a sequential list of 1 to 4 registers.
359 /// Combined record for all forms of ARM address expressions.
362 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
364 const MCConstantExpr *OffsetImm; // Offset immediate value
365 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
366 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
367 unsigned ShiftImm; // shift for OffsetReg.
368 unsigned Alignment; // 0 = no alignment specified
369 // n = alignment in bytes (2, 4, 8, 16, or 32)
370 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
376 ARM_AM::ShiftOpc ShiftTy;
385 ARM_AM::ShiftOpc ShiftTy;
391 ARM_AM::ShiftOpc ShiftTy;
404 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
406 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
408 StartLoc = o.StartLoc;
425 case k_DPRRegisterList:
426 case k_SPRRegisterList:
427 Registers = o.Registers;
430 case k_VectorListAllLanes:
431 case k_VectorListIndexed:
432 VectorList = o.VectorList;
439 CoprocOption = o.CoprocOption;
444 case k_MemBarrierOpt:
450 case k_PostIndexRegister:
451 PostIdxReg = o.PostIdxReg;
459 case k_ShifterImmediate:
460 ShifterImm = o.ShifterImm;
462 case k_ShiftedRegister:
463 RegShiftedReg = o.RegShiftedReg;
465 case k_ShiftedImmediate:
466 RegShiftedImm = o.RegShiftedImm;
468 case k_RotateImmediate:
471 case k_BitfieldDescriptor:
472 Bitfield = o.Bitfield;
475 VectorIndex = o.VectorIndex;
480 /// getStartLoc - Get the location of the first token of this operand.
481 SMLoc getStartLoc() const { return StartLoc; }
482 /// getEndLoc - Get the location of the last token of this operand.
483 SMLoc getEndLoc() const { return EndLoc; }
485 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
487 ARMCC::CondCodes getCondCode() const {
488 assert(Kind == k_CondCode && "Invalid access!");
492 unsigned getCoproc() const {
493 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
497 StringRef getToken() const {
498 assert(Kind == k_Token && "Invalid access!");
499 return StringRef(Tok.Data, Tok.Length);
502 unsigned getReg() const {
503 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
507 const SmallVectorImpl<unsigned> &getRegList() const {
508 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
509 Kind == k_SPRRegisterList) && "Invalid access!");
513 const MCExpr *getImm() const {
514 assert(isImm() && "Invalid access!");
518 unsigned getVectorIndex() const {
519 assert(Kind == k_VectorIndex && "Invalid access!");
520 return VectorIndex.Val;
523 ARM_MB::MemBOpt getMemBarrierOpt() const {
524 assert(Kind == k_MemBarrierOpt && "Invalid access!");
528 ARM_PROC::IFlags getProcIFlags() const {
529 assert(Kind == k_ProcIFlags && "Invalid access!");
533 unsigned getMSRMask() const {
534 assert(Kind == k_MSRMask && "Invalid access!");
538 bool isCoprocNum() const { return Kind == k_CoprocNum; }
539 bool isCoprocReg() const { return Kind == k_CoprocReg; }
540 bool isCoprocOption() const { return Kind == k_CoprocOption; }
541 bool isCondCode() const { return Kind == k_CondCode; }
542 bool isCCOut() const { return Kind == k_CCOut; }
543 bool isITMask() const { return Kind == k_ITCondMask; }
544 bool isITCondCode() const { return Kind == k_CondCode; }
545 bool isImm() const { return Kind == k_Immediate; }
546 bool isFPImm() const {
547 if (!isImm()) return false;
548 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
549 if (!CE) return false;
550 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
553 bool isFBits16() const {
554 if (!isImm()) return false;
555 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
556 if (!CE) return false;
557 int64_t Value = CE->getValue();
558 return Value >= 0 && Value <= 16;
560 bool isFBits32() const {
561 if (!isImm()) return false;
562 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
563 if (!CE) return false;
564 int64_t Value = CE->getValue();
565 return Value >= 1 && Value <= 32;
567 bool isImm8s4() const {
568 if (!isImm()) return false;
569 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
570 if (!CE) return false;
571 int64_t Value = CE->getValue();
572 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
574 bool isImm0_1020s4() const {
575 if (!isImm()) return false;
576 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
577 if (!CE) return false;
578 int64_t Value = CE->getValue();
579 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
581 bool isImm0_508s4() const {
582 if (!isImm()) return false;
583 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
584 if (!CE) return false;
585 int64_t Value = CE->getValue();
586 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
588 bool isImm0_508s4Neg() const {
589 if (!isImm()) return false;
590 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
591 if (!CE) return false;
592 int64_t Value = -CE->getValue();
593 // explicitly exclude zero. we want that to use the normal 0_508 version.
594 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
596 bool isImm0_255() const {
597 if (!isImm()) return false;
598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
599 if (!CE) return false;
600 int64_t Value = CE->getValue();
601 return Value >= 0 && Value < 256;
603 bool isImm0_4095() const {
604 if (!isImm()) return false;
605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
606 if (!CE) return false;
607 int64_t Value = CE->getValue();
608 return Value >= 0 && Value < 4096;
610 bool isImm0_4095Neg() const {
611 if (!isImm()) return false;
612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
613 if (!CE) return false;
614 int64_t Value = -CE->getValue();
615 return Value > 0 && Value < 4096;
617 bool isImm0_1() const {
618 if (!isImm()) return false;
619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
620 if (!CE) return false;
621 int64_t Value = CE->getValue();
622 return Value >= 0 && Value < 2;
624 bool isImm0_3() const {
625 if (!isImm()) return false;
626 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
627 if (!CE) return false;
628 int64_t Value = CE->getValue();
629 return Value >= 0 && Value < 4;
631 bool isImm0_7() const {
632 if (!isImm()) return false;
633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
634 if (!CE) return false;
635 int64_t Value = CE->getValue();
636 return Value >= 0 && Value < 8;
638 bool isImm0_15() const {
639 if (!isImm()) return false;
640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
641 if (!CE) return false;
642 int64_t Value = CE->getValue();
643 return Value >= 0 && Value < 16;
645 bool isImm0_31() const {
646 if (!isImm()) return false;
647 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
648 if (!CE) return false;
649 int64_t Value = CE->getValue();
650 return Value >= 0 && Value < 32;
652 bool isImm0_63() const {
653 if (!isImm()) return false;
654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
655 if (!CE) return false;
656 int64_t Value = CE->getValue();
657 return Value >= 0 && Value < 64;
659 bool isImm8() const {
660 if (!isImm()) return false;
661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
662 if (!CE) return false;
663 int64_t Value = CE->getValue();
666 bool isImm16() const {
667 if (!isImm()) return false;
668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
669 if (!CE) return false;
670 int64_t Value = CE->getValue();
673 bool isImm32() 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();
680 bool isShrImm8() 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 > 0 && Value <= 8;
687 bool isShrImm16() 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 > 0 && Value <= 16;
694 bool isShrImm32() 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 > 0 && Value <= 32;
701 bool isShrImm64() 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 > 0 && Value <= 64;
708 bool isImm1_7() 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 return Value > 0 && Value < 8;
715 bool isImm1_15() const {
716 if (!isImm()) return false;
717 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
718 if (!CE) return false;
719 int64_t Value = CE->getValue();
720 return Value > 0 && Value < 16;
722 bool isImm1_31() const {
723 if (!isImm()) return false;
724 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
725 if (!CE) return false;
726 int64_t Value = CE->getValue();
727 return Value > 0 && Value < 32;
729 bool isImm1_16() const {
730 if (!isImm()) return false;
731 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
732 if (!CE) return false;
733 int64_t Value = CE->getValue();
734 return Value > 0 && Value < 17;
736 bool isImm1_32() const {
737 if (!isImm()) return false;
738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
739 if (!CE) return false;
740 int64_t Value = CE->getValue();
741 return Value > 0 && Value < 33;
743 bool isImm0_32() const {
744 if (!isImm()) return false;
745 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
746 if (!CE) return false;
747 int64_t Value = CE->getValue();
748 return Value >= 0 && Value < 33;
750 bool isImm0_65535() const {
751 if (!isImm()) return false;
752 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
753 if (!CE) return false;
754 int64_t Value = CE->getValue();
755 return Value >= 0 && Value < 65536;
757 bool isImm0_65535Expr() const {
758 if (!isImm()) return false;
759 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
760 // If it's not a constant expression, it'll generate a fixup and be
762 if (!CE) return true;
763 int64_t Value = CE->getValue();
764 return Value >= 0 && Value < 65536;
766 bool isImm24bit() const {
767 if (!isImm()) return false;
768 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
769 if (!CE) return false;
770 int64_t Value = CE->getValue();
771 return Value >= 0 && Value <= 0xffffff;
773 bool isImmThumbSR() const {
774 if (!isImm()) return false;
775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
776 if (!CE) return false;
777 int64_t Value = CE->getValue();
778 return Value > 0 && Value < 33;
780 bool isPKHLSLImm() const {
781 if (!isImm()) return false;
782 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
783 if (!CE) return false;
784 int64_t Value = CE->getValue();
785 return Value >= 0 && Value < 32;
787 bool isPKHASRImm() const {
788 if (!isImm()) return false;
789 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
790 if (!CE) return false;
791 int64_t Value = CE->getValue();
792 return Value > 0 && Value <= 32;
794 bool isAdrLabel() const {
795 // If we have an immediate that's not a constant, treat it as a label
796 // reference needing a fixup. If it is a constant, but it can't fit
797 // into shift immediate encoding, we reject it.
798 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
799 else return (isARMSOImm() || isARMSOImmNeg());
801 bool isARMSOImm() const {
802 if (!isImm()) return false;
803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
804 if (!CE) return false;
805 int64_t Value = CE->getValue();
806 return ARM_AM::getSOImmVal(Value) != -1;
808 bool isARMSOImmNot() const {
809 if (!isImm()) return false;
810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return ARM_AM::getSOImmVal(~Value) != -1;
815 bool isARMSOImmNeg() const {
816 if (!isImm()) return false;
817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
818 if (!CE) return false;
819 int64_t Value = CE->getValue();
820 // Only use this when not representable as a plain so_imm.
821 return ARM_AM::getSOImmVal(Value) == -1 &&
822 ARM_AM::getSOImmVal(-Value) != -1;
824 bool isT2SOImm() const {
825 if (!isImm()) return false;
826 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
827 if (!CE) return false;
828 int64_t Value = CE->getValue();
829 return ARM_AM::getT2SOImmVal(Value) != -1;
831 bool isT2SOImmNot() const {
832 if (!isImm()) return false;
833 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
834 if (!CE) return false;
835 int64_t Value = CE->getValue();
836 return ARM_AM::getT2SOImmVal(~Value) != -1;
838 bool isT2SOImmNeg() const {
839 if (!isImm()) return false;
840 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
841 if (!CE) return false;
842 int64_t Value = CE->getValue();
843 // Only use this when not representable as a plain so_imm.
844 return ARM_AM::getT2SOImmVal(Value) == -1 &&
845 ARM_AM::getT2SOImmVal(-Value) != -1;
847 bool isSetEndImm() const {
848 if (!isImm()) return false;
849 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
850 if (!CE) return false;
851 int64_t Value = CE->getValue();
852 return Value == 1 || Value == 0;
854 bool isReg() const { return Kind == k_Register; }
855 bool isRegList() const { return Kind == k_RegisterList; }
856 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
857 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
858 bool isToken() const { return Kind == k_Token; }
859 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
860 bool isMemory() const { return Kind == k_Memory; }
861 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
862 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
863 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
864 bool isRotImm() const { return Kind == k_RotateImmediate; }
865 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
866 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
867 bool isPostIdxReg() const {
868 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
870 bool isMemNoOffset(bool alignOK = false) const {
873 // No offset of any kind.
874 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
875 (alignOK || Memory.Alignment == 0);
877 bool isMemPCRelImm12() const {
878 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
880 // Base register must be PC.
881 if (Memory.BaseRegNum != ARM::PC)
883 // Immediate offset in range [-4095, 4095].
884 if (!Memory.OffsetImm) return true;
885 int64_t Val = Memory.OffsetImm->getValue();
886 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
888 bool isAlignedMemory() const {
889 return isMemNoOffset(true);
891 bool isAddrMode2() const {
892 if (!isMemory() || Memory.Alignment != 0) return false;
893 // Check for register offset.
894 if (Memory.OffsetRegNum) return true;
895 // Immediate offset in range [-4095, 4095].
896 if (!Memory.OffsetImm) return true;
897 int64_t Val = Memory.OffsetImm->getValue();
898 return Val > -4096 && Val < 4096;
900 bool isAM2OffsetImm() const {
901 if (!isImm()) return false;
902 // Immediate offset in range [-4095, 4095].
903 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
904 if (!CE) return false;
905 int64_t Val = CE->getValue();
906 return Val > -4096 && Val < 4096;
908 bool isAddrMode3() const {
909 // If we have an immediate that's not a constant, treat it as a label
910 // reference needing a fixup. If it is a constant, it's something else
912 if (isImm() && !isa<MCConstantExpr>(getImm()))
914 if (!isMemory() || Memory.Alignment != 0) return false;
915 // No shifts are legal for AM3.
916 if (Memory.ShiftType != ARM_AM::no_shift) return false;
917 // Check for register offset.
918 if (Memory.OffsetRegNum) return true;
919 // Immediate offset in range [-255, 255].
920 if (!Memory.OffsetImm) return true;
921 int64_t Val = Memory.OffsetImm->getValue();
922 // The #-0 offset is encoded as INT32_MIN, and we have to check
924 return (Val > -256 && Val < 256) || Val == INT32_MIN;
926 bool isAM3Offset() const {
927 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
929 if (Kind == k_PostIndexRegister)
930 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
931 // Immediate offset in range [-255, 255].
932 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
933 if (!CE) return false;
934 int64_t Val = CE->getValue();
935 // Special case, #-0 is INT32_MIN.
936 return (Val > -256 && Val < 256) || Val == INT32_MIN;
938 bool isAddrMode5() const {
939 // If we have an immediate that's not a constant, treat it as a label
940 // reference needing a fixup. If it is a constant, it's something else
942 if (isImm() && !isa<MCConstantExpr>(getImm()))
944 if (!isMemory() || Memory.Alignment != 0) return false;
945 // Check for register offset.
946 if (Memory.OffsetRegNum) return false;
947 // Immediate offset in range [-1020, 1020] and a multiple of 4.
948 if (!Memory.OffsetImm) return true;
949 int64_t Val = Memory.OffsetImm->getValue();
950 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
953 bool isMemTBB() const {
954 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
955 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
959 bool isMemTBH() const {
960 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
961 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
962 Memory.Alignment != 0 )
966 bool isMemRegOffset() const {
967 if (!isMemory() || !Memory.OffsetRegNum || Memory.Alignment != 0)
971 bool isT2MemRegOffset() const {
972 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
973 Memory.Alignment != 0)
975 // Only lsl #{0, 1, 2, 3} allowed.
976 if (Memory.ShiftType == ARM_AM::no_shift)
978 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
982 bool isMemThumbRR() const {
983 // Thumb reg+reg addressing is simple. Just two registers, a base and
984 // an offset. No shifts, negations or any other complicating factors.
985 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
986 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
988 return isARMLowRegister(Memory.BaseRegNum) &&
989 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
991 bool isMemThumbRIs4() const {
992 if (!isMemory() || Memory.OffsetRegNum != 0 ||
993 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
995 // Immediate offset, multiple of 4 in range [0, 124].
996 if (!Memory.OffsetImm) return true;
997 int64_t Val = Memory.OffsetImm->getValue();
998 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1000 bool isMemThumbRIs2() const {
1001 if (!isMemory() || Memory.OffsetRegNum != 0 ||
1002 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1004 // Immediate offset, multiple of 4 in range [0, 62].
1005 if (!Memory.OffsetImm) return true;
1006 int64_t Val = Memory.OffsetImm->getValue();
1007 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1009 bool isMemThumbRIs1() const {
1010 if (!isMemory() || Memory.OffsetRegNum != 0 ||
1011 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1013 // Immediate offset in range [0, 31].
1014 if (!Memory.OffsetImm) return true;
1015 int64_t Val = Memory.OffsetImm->getValue();
1016 return Val >= 0 && Val <= 31;
1018 bool isMemThumbSPI() const {
1019 if (!isMemory() || Memory.OffsetRegNum != 0 ||
1020 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1022 // Immediate offset, multiple of 4 in range [0, 1020].
1023 if (!Memory.OffsetImm) return true;
1024 int64_t Val = Memory.OffsetImm->getValue();
1025 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1027 bool isMemImm8s4Offset() const {
1028 // If we have an immediate that's not a constant, treat it as a label
1029 // reference needing a fixup. If it is a constant, it's something else
1030 // and we reject it.
1031 if (isImm() && !isa<MCConstantExpr>(getImm()))
1033 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1035 // Immediate offset a multiple of 4 in range [-1020, 1020].
1036 if (!Memory.OffsetImm) return true;
1037 int64_t Val = Memory.OffsetImm->getValue();
1038 // Special case, #-0 is INT32_MIN.
1039 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1041 bool isMemImm0_1020s4Offset() const {
1042 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1044 // Immediate offset a multiple of 4 in range [0, 1020].
1045 if (!Memory.OffsetImm) return true;
1046 int64_t Val = Memory.OffsetImm->getValue();
1047 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1049 bool isMemImm8Offset() const {
1050 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1052 // Base reg of PC isn't allowed for these encodings.
1053 if (Memory.BaseRegNum == ARM::PC) return false;
1054 // Immediate offset in range [-255, 255].
1055 if (!Memory.OffsetImm) return true;
1056 int64_t Val = Memory.OffsetImm->getValue();
1057 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1059 bool isMemPosImm8Offset() const {
1060 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1062 // Immediate offset in range [0, 255].
1063 if (!Memory.OffsetImm) return true;
1064 int64_t Val = Memory.OffsetImm->getValue();
1065 return Val >= 0 && Val < 256;
1067 bool isMemNegImm8Offset() const {
1068 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1070 // Base reg of PC isn't allowed for these encodings.
1071 if (Memory.BaseRegNum == ARM::PC) return false;
1072 // Immediate offset in range [-255, -1].
1073 if (!Memory.OffsetImm) return false;
1074 int64_t Val = Memory.OffsetImm->getValue();
1075 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1077 bool isMemUImm12Offset() const {
1078 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1080 // Immediate offset in range [0, 4095].
1081 if (!Memory.OffsetImm) return true;
1082 int64_t Val = Memory.OffsetImm->getValue();
1083 return (Val >= 0 && Val < 4096);
1085 bool isMemImm12Offset() const {
1086 // If we have an immediate that's not a constant, treat it as a label
1087 // reference needing a fixup. If it is a constant, it's something else
1088 // and we reject it.
1089 if (isImm() && !isa<MCConstantExpr>(getImm()))
1092 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1094 // Immediate offset in range [-4095, 4095].
1095 if (!Memory.OffsetImm) return true;
1096 int64_t Val = Memory.OffsetImm->getValue();
1097 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1099 bool isPostIdxImm8() const {
1100 if (!isImm()) return false;
1101 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1102 if (!CE) return false;
1103 int64_t Val = CE->getValue();
1104 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1106 bool isPostIdxImm8s4() const {
1107 if (!isImm()) return false;
1108 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1109 if (!CE) return false;
1110 int64_t Val = CE->getValue();
1111 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1115 bool isMSRMask() const { return Kind == k_MSRMask; }
1116 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1119 bool isSingleSpacedVectorList() const {
1120 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1122 bool isDoubleSpacedVectorList() const {
1123 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1125 bool isVecListOneD() const {
1126 if (!isSingleSpacedVectorList()) return false;
1127 return VectorList.Count == 1;
1130 bool isVecListDPair() const {
1131 if (!isSingleSpacedVectorList()) return false;
1132 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1133 .contains(VectorList.RegNum));
1136 bool isVecListThreeD() const {
1137 if (!isSingleSpacedVectorList()) return false;
1138 return VectorList.Count == 3;
1141 bool isVecListFourD() const {
1142 if (!isSingleSpacedVectorList()) return false;
1143 return VectorList.Count == 4;
1146 bool isVecListDPairSpaced() const {
1147 if (isSingleSpacedVectorList()) return false;
1148 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1149 .contains(VectorList.RegNum));
1152 bool isVecListThreeQ() const {
1153 if (!isDoubleSpacedVectorList()) return false;
1154 return VectorList.Count == 3;
1157 bool isVecListFourQ() const {
1158 if (!isDoubleSpacedVectorList()) return false;
1159 return VectorList.Count == 4;
1162 bool isSingleSpacedVectorAllLanes() const {
1163 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1165 bool isDoubleSpacedVectorAllLanes() const {
1166 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1168 bool isVecListOneDAllLanes() const {
1169 if (!isSingleSpacedVectorAllLanes()) return false;
1170 return VectorList.Count == 1;
1173 bool isVecListDPairAllLanes() const {
1174 if (!isSingleSpacedVectorAllLanes()) return false;
1175 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1176 .contains(VectorList.RegNum));
1179 bool isVecListDPairSpacedAllLanes() const {
1180 if (!isDoubleSpacedVectorAllLanes()) return false;
1181 return VectorList.Count == 2;
1184 bool isVecListThreeDAllLanes() const {
1185 if (!isSingleSpacedVectorAllLanes()) return false;
1186 return VectorList.Count == 3;
1189 bool isVecListThreeQAllLanes() const {
1190 if (!isDoubleSpacedVectorAllLanes()) return false;
1191 return VectorList.Count == 3;
1194 bool isVecListFourDAllLanes() const {
1195 if (!isSingleSpacedVectorAllLanes()) return false;
1196 return VectorList.Count == 4;
1199 bool isVecListFourQAllLanes() const {
1200 if (!isDoubleSpacedVectorAllLanes()) return false;
1201 return VectorList.Count == 4;
1204 bool isSingleSpacedVectorIndexed() const {
1205 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1207 bool isDoubleSpacedVectorIndexed() const {
1208 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1210 bool isVecListOneDByteIndexed() const {
1211 if (!isSingleSpacedVectorIndexed()) return false;
1212 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1215 bool isVecListOneDHWordIndexed() const {
1216 if (!isSingleSpacedVectorIndexed()) return false;
1217 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1220 bool isVecListOneDWordIndexed() const {
1221 if (!isSingleSpacedVectorIndexed()) return false;
1222 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1225 bool isVecListTwoDByteIndexed() const {
1226 if (!isSingleSpacedVectorIndexed()) return false;
1227 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1230 bool isVecListTwoDHWordIndexed() const {
1231 if (!isSingleSpacedVectorIndexed()) return false;
1232 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1235 bool isVecListTwoQWordIndexed() const {
1236 if (!isDoubleSpacedVectorIndexed()) return false;
1237 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1240 bool isVecListTwoQHWordIndexed() const {
1241 if (!isDoubleSpacedVectorIndexed()) return false;
1242 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1245 bool isVecListTwoDWordIndexed() const {
1246 if (!isSingleSpacedVectorIndexed()) return false;
1247 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1250 bool isVecListThreeDByteIndexed() const {
1251 if (!isSingleSpacedVectorIndexed()) return false;
1252 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1255 bool isVecListThreeDHWordIndexed() const {
1256 if (!isSingleSpacedVectorIndexed()) return false;
1257 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1260 bool isVecListThreeQWordIndexed() const {
1261 if (!isDoubleSpacedVectorIndexed()) return false;
1262 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1265 bool isVecListThreeQHWordIndexed() const {
1266 if (!isDoubleSpacedVectorIndexed()) return false;
1267 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1270 bool isVecListThreeDWordIndexed() const {
1271 if (!isSingleSpacedVectorIndexed()) return false;
1272 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1275 bool isVecListFourDByteIndexed() const {
1276 if (!isSingleSpacedVectorIndexed()) return false;
1277 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1280 bool isVecListFourDHWordIndexed() const {
1281 if (!isSingleSpacedVectorIndexed()) return false;
1282 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1285 bool isVecListFourQWordIndexed() const {
1286 if (!isDoubleSpacedVectorIndexed()) return false;
1287 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1290 bool isVecListFourQHWordIndexed() const {
1291 if (!isDoubleSpacedVectorIndexed()) return false;
1292 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1295 bool isVecListFourDWordIndexed() const {
1296 if (!isSingleSpacedVectorIndexed()) return false;
1297 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1300 bool isVectorIndex8() const {
1301 if (Kind != k_VectorIndex) return false;
1302 return VectorIndex.Val < 8;
1304 bool isVectorIndex16() const {
1305 if (Kind != k_VectorIndex) return false;
1306 return VectorIndex.Val < 4;
1308 bool isVectorIndex32() const {
1309 if (Kind != k_VectorIndex) return false;
1310 return VectorIndex.Val < 2;
1313 bool isNEONi8splat() const {
1314 if (!isImm()) return false;
1315 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1316 // Must be a constant.
1317 if (!CE) return false;
1318 int64_t Value = CE->getValue();
1319 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1321 return Value >= 0 && Value < 256;
1324 bool isNEONi16splat() const {
1325 if (!isImm()) return false;
1326 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1327 // Must be a constant.
1328 if (!CE) return false;
1329 int64_t Value = CE->getValue();
1330 // i16 value in the range [0,255] or [0x0100, 0xff00]
1331 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1334 bool isNEONi32splat() const {
1335 if (!isImm()) return false;
1336 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1337 // Must be a constant.
1338 if (!CE) return false;
1339 int64_t Value = CE->getValue();
1340 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1341 return (Value >= 0 && Value < 256) ||
1342 (Value >= 0x0100 && Value <= 0xff00) ||
1343 (Value >= 0x010000 && Value <= 0xff0000) ||
1344 (Value >= 0x01000000 && Value <= 0xff000000);
1347 bool isNEONi32vmov() const {
1348 if (!isImm()) return false;
1349 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1350 // Must be a constant.
1351 if (!CE) return false;
1352 int64_t Value = CE->getValue();
1353 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1354 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1355 return (Value >= 0 && Value < 256) ||
1356 (Value >= 0x0100 && Value <= 0xff00) ||
1357 (Value >= 0x010000 && Value <= 0xff0000) ||
1358 (Value >= 0x01000000 && Value <= 0xff000000) ||
1359 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1360 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1362 bool isNEONi32vmovNeg() const {
1363 if (!isImm()) return false;
1364 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1365 // Must be a constant.
1366 if (!CE) return false;
1367 int64_t Value = ~CE->getValue();
1368 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1369 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1370 return (Value >= 0 && Value < 256) ||
1371 (Value >= 0x0100 && Value <= 0xff00) ||
1372 (Value >= 0x010000 && Value <= 0xff0000) ||
1373 (Value >= 0x01000000 && Value <= 0xff000000) ||
1374 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1375 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1378 bool isNEONi64splat() const {
1379 if (!isImm()) return false;
1380 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1381 // Must be a constant.
1382 if (!CE) return false;
1383 uint64_t Value = CE->getValue();
1384 // i64 value with each byte being either 0 or 0xff.
1385 for (unsigned i = 0; i < 8; ++i)
1386 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1390 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1391 // Add as immediates when possible. Null MCExpr = 0.
1393 Inst.addOperand(MCOperand::CreateImm(0));
1394 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1395 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1397 Inst.addOperand(MCOperand::CreateExpr(Expr));
1400 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1401 assert(N == 2 && "Invalid number of operands!");
1402 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1403 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1404 Inst.addOperand(MCOperand::CreateReg(RegNum));
1407 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1408 assert(N == 1 && "Invalid number of operands!");
1409 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1412 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1413 assert(N == 1 && "Invalid number of operands!");
1414 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1417 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1418 assert(N == 1 && "Invalid number of operands!");
1419 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1422 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1423 assert(N == 1 && "Invalid number of operands!");
1424 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1427 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1428 assert(N == 1 && "Invalid number of operands!");
1429 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1432 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1433 assert(N == 1 && "Invalid number of operands!");
1434 Inst.addOperand(MCOperand::CreateReg(getReg()));
1437 void addRegOperands(MCInst &Inst, unsigned N) const {
1438 assert(N == 1 && "Invalid number of operands!");
1439 Inst.addOperand(MCOperand::CreateReg(getReg()));
1442 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1443 assert(N == 3 && "Invalid number of operands!");
1444 assert(isRegShiftedReg() &&
1445 "addRegShiftedRegOperands() on non RegShiftedReg!");
1446 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1447 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1448 Inst.addOperand(MCOperand::CreateImm(
1449 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1452 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1453 assert(N == 2 && "Invalid number of operands!");
1454 assert(isRegShiftedImm() &&
1455 "addRegShiftedImmOperands() on non RegShiftedImm!");
1456 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1457 // Shift of #32 is encoded as 0 where permitted
1458 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1459 Inst.addOperand(MCOperand::CreateImm(
1460 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1463 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1464 assert(N == 1 && "Invalid number of operands!");
1465 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1469 void addRegListOperands(MCInst &Inst, unsigned N) const {
1470 assert(N == 1 && "Invalid number of operands!");
1471 const SmallVectorImpl<unsigned> &RegList = getRegList();
1472 for (SmallVectorImpl<unsigned>::const_iterator
1473 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1474 Inst.addOperand(MCOperand::CreateReg(*I));
1477 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1478 addRegListOperands(Inst, N);
1481 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1482 addRegListOperands(Inst, N);
1485 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1486 assert(N == 1 && "Invalid number of operands!");
1487 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1488 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1491 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1492 assert(N == 1 && "Invalid number of operands!");
1493 // Munge the lsb/width into a bitfield mask.
1494 unsigned lsb = Bitfield.LSB;
1495 unsigned width = Bitfield.Width;
1496 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1497 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1498 (32 - (lsb + width)));
1499 Inst.addOperand(MCOperand::CreateImm(Mask));
1502 void addImmOperands(MCInst &Inst, unsigned N) const {
1503 assert(N == 1 && "Invalid number of operands!");
1504 addExpr(Inst, getImm());
1507 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1508 assert(N == 1 && "Invalid number of operands!");
1509 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1510 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1513 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1514 assert(N == 1 && "Invalid number of operands!");
1515 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1516 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1519 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1520 assert(N == 1 && "Invalid number of operands!");
1521 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1522 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1523 Inst.addOperand(MCOperand::CreateImm(Val));
1526 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1527 assert(N == 1 && "Invalid number of operands!");
1528 // FIXME: We really want to scale the value here, but the LDRD/STRD
1529 // instruction don't encode operands that way yet.
1530 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1531 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1534 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1535 assert(N == 1 && "Invalid number of operands!");
1536 // The immediate is scaled by four in the encoding and is stored
1537 // in the MCInst as such. Lop off the low two bits here.
1538 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1539 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1542 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1543 assert(N == 1 && "Invalid number of operands!");
1544 // The immediate is scaled by four in the encoding and is stored
1545 // in the MCInst as such. Lop off the low two bits here.
1546 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1547 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1550 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1551 assert(N == 1 && "Invalid number of operands!");
1552 // The immediate is scaled by four in the encoding and is stored
1553 // in the MCInst as such. Lop off the low two bits here.
1554 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1555 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1558 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1559 assert(N == 1 && "Invalid number of operands!");
1560 // The constant encodes as the immediate-1, and we store in the instruction
1561 // the bits as encoded, so subtract off one here.
1562 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1563 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1566 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1567 assert(N == 1 && "Invalid number of operands!");
1568 // The constant encodes as the immediate-1, and we store in the instruction
1569 // the bits as encoded, so subtract off one here.
1570 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1571 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1574 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1575 assert(N == 1 && "Invalid number of operands!");
1576 // The constant encodes as the immediate, except for 32, which encodes as
1578 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1579 unsigned Imm = CE->getValue();
1580 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1583 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1584 assert(N == 1 && "Invalid number of operands!");
1585 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1586 // the instruction as well.
1587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1588 int Val = CE->getValue();
1589 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1592 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1593 assert(N == 1 && "Invalid number of operands!");
1594 // The operand is actually a t2_so_imm, but we have its bitwise
1595 // negation in the assembly source, so twiddle it here.
1596 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1597 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1600 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1601 assert(N == 1 && "Invalid number of operands!");
1602 // The operand is actually a t2_so_imm, but we have its
1603 // negation in the assembly source, so twiddle it here.
1604 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1605 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1608 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1609 assert(N == 1 && "Invalid number of operands!");
1610 // The operand is actually an imm0_4095, but we have its
1611 // negation in the assembly source, so twiddle it here.
1612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1613 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1616 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1617 assert(N == 1 && "Invalid number of operands!");
1618 // The operand is actually a so_imm, but we have its bitwise
1619 // negation in the assembly source, so twiddle it here.
1620 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1621 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1624 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1625 assert(N == 1 && "Invalid number of operands!");
1626 // The operand is actually a so_imm, but we have its
1627 // negation in the assembly source, so twiddle it here.
1628 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1629 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1632 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1633 assert(N == 1 && "Invalid number of operands!");
1634 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1637 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1638 assert(N == 1 && "Invalid number of operands!");
1639 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1642 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1643 assert(N == 1 && "Invalid number of operands!");
1644 int32_t Imm = Memory.OffsetImm->getValue();
1645 // FIXME: Handle #-0
1646 if (Imm == INT32_MIN) Imm = 0;
1647 Inst.addOperand(MCOperand::CreateImm(Imm));
1650 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1651 assert(N == 1 && "Invalid number of operands!");
1652 assert(isImm() && "Not an immediate!");
1654 // If we have an immediate that's not a constant, treat it as a label
1655 // reference needing a fixup.
1656 if (!isa<MCConstantExpr>(getImm())) {
1657 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1662 int Val = CE->getValue();
1663 Inst.addOperand(MCOperand::CreateImm(Val));
1666 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1667 assert(N == 2 && "Invalid number of operands!");
1668 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1669 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1672 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1673 assert(N == 3 && "Invalid number of operands!");
1674 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1675 if (!Memory.OffsetRegNum) {
1676 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1677 // Special case for #-0
1678 if (Val == INT32_MIN) Val = 0;
1679 if (Val < 0) Val = -Val;
1680 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1682 // For register offset, we encode the shift type and negation flag
1684 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1685 Memory.ShiftImm, Memory.ShiftType);
1687 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1688 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1689 Inst.addOperand(MCOperand::CreateImm(Val));
1692 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1693 assert(N == 2 && "Invalid number of operands!");
1694 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1695 assert(CE && "non-constant AM2OffsetImm operand!");
1696 int32_t Val = CE->getValue();
1697 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1698 // Special case for #-0
1699 if (Val == INT32_MIN) Val = 0;
1700 if (Val < 0) Val = -Val;
1701 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1702 Inst.addOperand(MCOperand::CreateReg(0));
1703 Inst.addOperand(MCOperand::CreateImm(Val));
1706 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1707 assert(N == 3 && "Invalid number of operands!");
1708 // If we have an immediate that's not a constant, treat it as a label
1709 // reference needing a fixup. If it is a constant, it's something else
1710 // and we reject it.
1712 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1713 Inst.addOperand(MCOperand::CreateReg(0));
1714 Inst.addOperand(MCOperand::CreateImm(0));
1718 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1719 if (!Memory.OffsetRegNum) {
1720 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1721 // Special case for #-0
1722 if (Val == INT32_MIN) Val = 0;
1723 if (Val < 0) Val = -Val;
1724 Val = ARM_AM::getAM3Opc(AddSub, Val);
1726 // For register offset, we encode the shift type and negation flag
1728 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1730 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1731 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1732 Inst.addOperand(MCOperand::CreateImm(Val));
1735 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1736 assert(N == 2 && "Invalid number of operands!");
1737 if (Kind == k_PostIndexRegister) {
1739 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1740 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1741 Inst.addOperand(MCOperand::CreateImm(Val));
1746 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1747 int32_t Val = CE->getValue();
1748 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1749 // Special case for #-0
1750 if (Val == INT32_MIN) Val = 0;
1751 if (Val < 0) Val = -Val;
1752 Val = ARM_AM::getAM3Opc(AddSub, Val);
1753 Inst.addOperand(MCOperand::CreateReg(0));
1754 Inst.addOperand(MCOperand::CreateImm(Val));
1757 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1758 assert(N == 2 && "Invalid number of operands!");
1759 // If we have an immediate that's not a constant, treat it as a label
1760 // reference needing a fixup. If it is a constant, it's something else
1761 // and we reject it.
1763 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1764 Inst.addOperand(MCOperand::CreateImm(0));
1768 // The lower two bits are always zero and as such are not encoded.
1769 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1770 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1771 // Special case for #-0
1772 if (Val == INT32_MIN) Val = 0;
1773 if (Val < 0) Val = -Val;
1774 Val = ARM_AM::getAM5Opc(AddSub, Val);
1775 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1776 Inst.addOperand(MCOperand::CreateImm(Val));
1779 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1780 assert(N == 2 && "Invalid number of operands!");
1781 // If we have an immediate that's not a constant, treat it as a label
1782 // reference needing a fixup. If it is a constant, it's something else
1783 // and we reject it.
1785 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1786 Inst.addOperand(MCOperand::CreateImm(0));
1790 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1791 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1792 Inst.addOperand(MCOperand::CreateImm(Val));
1795 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1796 assert(N == 2 && "Invalid number of operands!");
1797 // The lower two bits are always zero and as such are not encoded.
1798 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1799 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1800 Inst.addOperand(MCOperand::CreateImm(Val));
1803 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1804 assert(N == 2 && "Invalid number of operands!");
1805 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1806 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1807 Inst.addOperand(MCOperand::CreateImm(Val));
1810 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1811 addMemImm8OffsetOperands(Inst, N);
1814 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1815 addMemImm8OffsetOperands(Inst, N);
1818 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1819 assert(N == 2 && "Invalid number of operands!");
1820 // If this is an immediate, it's a label reference.
1822 addExpr(Inst, getImm());
1823 Inst.addOperand(MCOperand::CreateImm(0));
1827 // Otherwise, it's a normal memory reg+offset.
1828 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1829 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1830 Inst.addOperand(MCOperand::CreateImm(Val));
1833 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1834 assert(N == 2 && "Invalid number of operands!");
1835 // If this is an immediate, it's a label reference.
1837 addExpr(Inst, getImm());
1838 Inst.addOperand(MCOperand::CreateImm(0));
1842 // Otherwise, it's a normal memory reg+offset.
1843 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1844 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1845 Inst.addOperand(MCOperand::CreateImm(Val));
1848 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1849 assert(N == 2 && "Invalid number of operands!");
1850 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1851 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1854 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1855 assert(N == 2 && "Invalid number of operands!");
1856 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1857 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1860 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1861 assert(N == 3 && "Invalid number of operands!");
1863 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1864 Memory.ShiftImm, Memory.ShiftType);
1865 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1866 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1867 Inst.addOperand(MCOperand::CreateImm(Val));
1870 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1871 assert(N == 3 && "Invalid number of operands!");
1872 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1873 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1874 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
1877 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1878 assert(N == 2 && "Invalid number of operands!");
1879 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1880 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1883 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1884 assert(N == 2 && "Invalid number of operands!");
1885 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1886 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1887 Inst.addOperand(MCOperand::CreateImm(Val));
1890 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1891 assert(N == 2 && "Invalid number of operands!");
1892 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1893 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1894 Inst.addOperand(MCOperand::CreateImm(Val));
1897 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1898 assert(N == 2 && "Invalid number of operands!");
1899 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1900 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1901 Inst.addOperand(MCOperand::CreateImm(Val));
1904 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1905 assert(N == 2 && "Invalid number of operands!");
1906 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1907 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1908 Inst.addOperand(MCOperand::CreateImm(Val));
1911 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1912 assert(N == 1 && "Invalid number of operands!");
1913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1914 assert(CE && "non-constant post-idx-imm8 operand!");
1915 int Imm = CE->getValue();
1916 bool isAdd = Imm >= 0;
1917 if (Imm == INT32_MIN) Imm = 0;
1918 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1919 Inst.addOperand(MCOperand::CreateImm(Imm));
1922 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1923 assert(N == 1 && "Invalid number of operands!");
1924 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1925 assert(CE && "non-constant post-idx-imm8s4 operand!");
1926 int Imm = CE->getValue();
1927 bool isAdd = Imm >= 0;
1928 if (Imm == INT32_MIN) Imm = 0;
1929 // Immediate is scaled by 4.
1930 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1931 Inst.addOperand(MCOperand::CreateImm(Imm));
1934 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1935 assert(N == 2 && "Invalid number of operands!");
1936 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1937 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1940 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1941 assert(N == 2 && "Invalid number of operands!");
1942 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1943 // The sign, shift type, and shift amount are encoded in a single operand
1944 // using the AM2 encoding helpers.
1945 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1946 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1947 PostIdxReg.ShiftTy);
1948 Inst.addOperand(MCOperand::CreateImm(Imm));
1951 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1952 assert(N == 1 && "Invalid number of operands!");
1953 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1956 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1957 assert(N == 1 && "Invalid number of operands!");
1958 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1961 void addVecListOperands(MCInst &Inst, unsigned N) const {
1962 assert(N == 1 && "Invalid number of operands!");
1963 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1966 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1967 assert(N == 2 && "Invalid number of operands!");
1968 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1969 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1972 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1973 assert(N == 1 && "Invalid number of operands!");
1974 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1977 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1978 assert(N == 1 && "Invalid number of operands!");
1979 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1982 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1983 assert(N == 1 && "Invalid number of operands!");
1984 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1987 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1988 assert(N == 1 && "Invalid number of operands!");
1989 // The immediate encodes the type of constant as well as the value.
1990 // Mask in that this is an i8 splat.
1991 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1992 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1995 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1996 assert(N == 1 && "Invalid number of operands!");
1997 // The immediate encodes the type of constant as well as the value.
1998 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1999 unsigned Value = CE->getValue();
2001 Value = (Value >> 8) | 0xa00;
2004 Inst.addOperand(MCOperand::CreateImm(Value));
2007 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2008 assert(N == 1 && "Invalid number of operands!");
2009 // The immediate encodes the type of constant as well as the value.
2010 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2011 unsigned Value = CE->getValue();
2012 if (Value >= 256 && Value <= 0xff00)
2013 Value = (Value >> 8) | 0x200;
2014 else if (Value > 0xffff && Value <= 0xff0000)
2015 Value = (Value >> 16) | 0x400;
2016 else if (Value > 0xffffff)
2017 Value = (Value >> 24) | 0x600;
2018 Inst.addOperand(MCOperand::CreateImm(Value));
2021 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2022 assert(N == 1 && "Invalid number of operands!");
2023 // The immediate encodes the type of constant as well as the value.
2024 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2025 unsigned Value = CE->getValue();
2026 if (Value >= 256 && Value <= 0xffff)
2027 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2028 else if (Value > 0xffff && Value <= 0xffffff)
2029 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2030 else if (Value > 0xffffff)
2031 Value = (Value >> 24) | 0x600;
2032 Inst.addOperand(MCOperand::CreateImm(Value));
2035 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2036 assert(N == 1 && "Invalid number of operands!");
2037 // The immediate encodes the type of constant as well as the value.
2038 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2039 unsigned Value = ~CE->getValue();
2040 if (Value >= 256 && Value <= 0xffff)
2041 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2042 else if (Value > 0xffff && Value <= 0xffffff)
2043 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2044 else if (Value > 0xffffff)
2045 Value = (Value >> 24) | 0x600;
2046 Inst.addOperand(MCOperand::CreateImm(Value));
2049 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2050 assert(N == 1 && "Invalid number of operands!");
2051 // The immediate encodes the type of constant as well as the value.
2052 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2053 uint64_t Value = CE->getValue();
2055 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2056 Imm |= (Value & 1) << i;
2058 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2061 virtual void print(raw_ostream &OS) const;
2063 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2064 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2065 Op->ITMask.Mask = Mask;
2071 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2072 ARMOperand *Op = new ARMOperand(k_CondCode);
2079 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2080 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2081 Op->Cop.Val = CopVal;
2087 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2088 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2089 Op->Cop.Val = CopVal;
2095 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2096 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2103 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2104 ARMOperand *Op = new ARMOperand(k_CCOut);
2105 Op->Reg.RegNum = RegNum;
2111 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2112 ARMOperand *Op = new ARMOperand(k_Token);
2113 Op->Tok.Data = Str.data();
2114 Op->Tok.Length = Str.size();
2120 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2121 ARMOperand *Op = new ARMOperand(k_Register);
2122 Op->Reg.RegNum = RegNum;
2128 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2133 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2134 Op->RegShiftedReg.ShiftTy = ShTy;
2135 Op->RegShiftedReg.SrcReg = SrcReg;
2136 Op->RegShiftedReg.ShiftReg = ShiftReg;
2137 Op->RegShiftedReg.ShiftImm = ShiftImm;
2143 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2147 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2148 Op->RegShiftedImm.ShiftTy = ShTy;
2149 Op->RegShiftedImm.SrcReg = SrcReg;
2150 Op->RegShiftedImm.ShiftImm = ShiftImm;
2156 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2158 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2159 Op->ShifterImm.isASR = isASR;
2160 Op->ShifterImm.Imm = Imm;
2166 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2167 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2168 Op->RotImm.Imm = Imm;
2174 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2176 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2177 Op->Bitfield.LSB = LSB;
2178 Op->Bitfield.Width = Width;
2185 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
2186 SMLoc StartLoc, SMLoc EndLoc) {
2187 KindTy Kind = k_RegisterList;
2189 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
2190 Kind = k_DPRRegisterList;
2191 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2192 contains(Regs.front().first))
2193 Kind = k_SPRRegisterList;
2195 ARMOperand *Op = new ARMOperand(Kind);
2196 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
2197 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2198 Op->Registers.push_back(I->first);
2199 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
2200 Op->StartLoc = StartLoc;
2201 Op->EndLoc = EndLoc;
2205 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2206 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2207 ARMOperand *Op = new ARMOperand(k_VectorList);
2208 Op->VectorList.RegNum = RegNum;
2209 Op->VectorList.Count = Count;
2210 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2216 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2217 bool isDoubleSpaced,
2219 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2220 Op->VectorList.RegNum = RegNum;
2221 Op->VectorList.Count = Count;
2222 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2228 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2230 bool isDoubleSpaced,
2232 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2233 Op->VectorList.RegNum = RegNum;
2234 Op->VectorList.Count = Count;
2235 Op->VectorList.LaneIndex = Index;
2236 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2242 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2244 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2245 Op->VectorIndex.Val = Idx;
2251 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2252 ARMOperand *Op = new ARMOperand(k_Immediate);
2259 static ARMOperand *CreateMem(unsigned BaseRegNum,
2260 const MCConstantExpr *OffsetImm,
2261 unsigned OffsetRegNum,
2262 ARM_AM::ShiftOpc ShiftType,
2267 ARMOperand *Op = new ARMOperand(k_Memory);
2268 Op->Memory.BaseRegNum = BaseRegNum;
2269 Op->Memory.OffsetImm = OffsetImm;
2270 Op->Memory.OffsetRegNum = OffsetRegNum;
2271 Op->Memory.ShiftType = ShiftType;
2272 Op->Memory.ShiftImm = ShiftImm;
2273 Op->Memory.Alignment = Alignment;
2274 Op->Memory.isNegative = isNegative;
2280 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2281 ARM_AM::ShiftOpc ShiftTy,
2284 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2285 Op->PostIdxReg.RegNum = RegNum;
2286 Op->PostIdxReg.isAdd = isAdd;
2287 Op->PostIdxReg.ShiftTy = ShiftTy;
2288 Op->PostIdxReg.ShiftImm = ShiftImm;
2294 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2295 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2296 Op->MBOpt.Val = Opt;
2302 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2303 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2304 Op->IFlags.Val = IFlags;
2310 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2311 ARMOperand *Op = new ARMOperand(k_MSRMask);
2312 Op->MMask.Val = MMask;
2319 } // end anonymous namespace.
2321 void ARMOperand::print(raw_ostream &OS) const {
2324 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2327 OS << "<ccout " << getReg() << ">";
2329 case k_ITCondMask: {
2330 static const char *const MaskStr[] = {
2331 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2332 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2334 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2335 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2339 OS << "<coprocessor number: " << getCoproc() << ">";
2342 OS << "<coprocessor register: " << getCoproc() << ">";
2344 case k_CoprocOption:
2345 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2348 OS << "<mask: " << getMSRMask() << ">";
2351 getImm()->print(OS);
2353 case k_MemBarrierOpt:
2354 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2358 << " base:" << Memory.BaseRegNum;
2361 case k_PostIndexRegister:
2362 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2363 << PostIdxReg.RegNum;
2364 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2365 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2366 << PostIdxReg.ShiftImm;
2369 case k_ProcIFlags: {
2370 OS << "<ARM_PROC::";
2371 unsigned IFlags = getProcIFlags();
2372 for (int i=2; i >= 0; --i)
2373 if (IFlags & (1 << i))
2374 OS << ARM_PROC::IFlagsToString(1 << i);
2379 OS << "<register " << getReg() << ">";
2381 case k_ShifterImmediate:
2382 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2383 << " #" << ShifterImm.Imm << ">";
2385 case k_ShiftedRegister:
2386 OS << "<so_reg_reg "
2387 << RegShiftedReg.SrcReg << " "
2388 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2389 << " " << RegShiftedReg.ShiftReg << ">";
2391 case k_ShiftedImmediate:
2392 OS << "<so_reg_imm "
2393 << RegShiftedImm.SrcReg << " "
2394 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2395 << " #" << RegShiftedImm.ShiftImm << ">";
2397 case k_RotateImmediate:
2398 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2400 case k_BitfieldDescriptor:
2401 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2402 << ", width: " << Bitfield.Width << ">";
2404 case k_RegisterList:
2405 case k_DPRRegisterList:
2406 case k_SPRRegisterList: {
2407 OS << "<register_list ";
2409 const SmallVectorImpl<unsigned> &RegList = getRegList();
2410 for (SmallVectorImpl<unsigned>::const_iterator
2411 I = RegList.begin(), E = RegList.end(); I != E; ) {
2413 if (++I < E) OS << ", ";
2420 OS << "<vector_list " << VectorList.Count << " * "
2421 << VectorList.RegNum << ">";
2423 case k_VectorListAllLanes:
2424 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2425 << VectorList.RegNum << ">";
2427 case k_VectorListIndexed:
2428 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2429 << VectorList.Count << " * " << VectorList.RegNum << ">";
2432 OS << "'" << getToken() << "'";
2435 OS << "<vectorindex " << getVectorIndex() << ">";
2440 /// @name Auto-generated Match Functions
2443 static unsigned MatchRegisterName(StringRef Name);
2447 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2448 SMLoc &StartLoc, SMLoc &EndLoc) {
2449 StartLoc = Parser.getTok().getLoc();
2450 RegNo = tryParseRegister();
2451 EndLoc = Parser.getTok().getLoc();
2453 return (RegNo == (unsigned)-1);
2456 /// Try to parse a register name. The token must be an Identifier when called,
2457 /// and if it is a register name the token is eaten and the register number is
2458 /// returned. Otherwise return -1.
2460 int ARMAsmParser::tryParseRegister() {
2461 const AsmToken &Tok = Parser.getTok();
2462 if (Tok.isNot(AsmToken::Identifier)) return -1;
2464 std::string lowerCase = Tok.getString().lower();
2465 unsigned RegNum = MatchRegisterName(lowerCase);
2467 RegNum = StringSwitch<unsigned>(lowerCase)
2468 .Case("r13", ARM::SP)
2469 .Case("r14", ARM::LR)
2470 .Case("r15", ARM::PC)
2471 .Case("ip", ARM::R12)
2472 // Additional register name aliases for 'gas' compatibility.
2473 .Case("a1", ARM::R0)
2474 .Case("a2", ARM::R1)
2475 .Case("a3", ARM::R2)
2476 .Case("a4", ARM::R3)
2477 .Case("v1", ARM::R4)
2478 .Case("v2", ARM::R5)
2479 .Case("v3", ARM::R6)
2480 .Case("v4", ARM::R7)
2481 .Case("v5", ARM::R8)
2482 .Case("v6", ARM::R9)
2483 .Case("v7", ARM::R10)
2484 .Case("v8", ARM::R11)
2485 .Case("sb", ARM::R9)
2486 .Case("sl", ARM::R10)
2487 .Case("fp", ARM::R11)
2491 // Check for aliases registered via .req. Canonicalize to lower case.
2492 // That's more consistent since register names are case insensitive, and
2493 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2494 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2495 // If no match, return failure.
2496 if (Entry == RegisterReqs.end())
2498 Parser.Lex(); // Eat identifier token.
2499 return Entry->getValue();
2502 Parser.Lex(); // Eat identifier token.
2507 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2508 // If a recoverable error occurs, return 1. If an irrecoverable error
2509 // occurs, return -1. An irrecoverable error is one where tokens have been
2510 // consumed in the process of trying to parse the shifter (i.e., when it is
2511 // indeed a shifter operand, but malformed).
2512 int ARMAsmParser::tryParseShiftRegister(
2513 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2514 SMLoc S = Parser.getTok().getLoc();
2515 const AsmToken &Tok = Parser.getTok();
2516 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2518 std::string lowerCase = Tok.getString().lower();
2519 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2520 .Case("asl", ARM_AM::lsl)
2521 .Case("lsl", ARM_AM::lsl)
2522 .Case("lsr", ARM_AM::lsr)
2523 .Case("asr", ARM_AM::asr)
2524 .Case("ror", ARM_AM::ror)
2525 .Case("rrx", ARM_AM::rrx)
2526 .Default(ARM_AM::no_shift);
2528 if (ShiftTy == ARM_AM::no_shift)
2531 Parser.Lex(); // Eat the operator.
2533 // The source register for the shift has already been added to the
2534 // operand list, so we need to pop it off and combine it into the shifted
2535 // register operand instead.
2536 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2537 if (!PrevOp->isReg())
2538 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2539 int SrcReg = PrevOp->getReg();
2542 if (ShiftTy == ARM_AM::rrx) {
2543 // RRX Doesn't have an explicit shift amount. The encoder expects
2544 // the shift register to be the same as the source register. Seems odd,
2548 // Figure out if this is shifted by a constant or a register (for non-RRX).
2549 if (Parser.getTok().is(AsmToken::Hash) ||
2550 Parser.getTok().is(AsmToken::Dollar)) {
2551 Parser.Lex(); // Eat hash.
2552 SMLoc ImmLoc = Parser.getTok().getLoc();
2553 const MCExpr *ShiftExpr = 0;
2554 if (getParser().ParseExpression(ShiftExpr)) {
2555 Error(ImmLoc, "invalid immediate shift value");
2558 // The expression must be evaluatable as an immediate.
2559 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2561 Error(ImmLoc, "invalid immediate shift value");
2564 // Range check the immediate.
2565 // lsl, ror: 0 <= imm <= 31
2566 // lsr, asr: 0 <= imm <= 32
2567 Imm = CE->getValue();
2569 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2570 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2571 Error(ImmLoc, "immediate shift value out of range");
2574 // shift by zero is a nop. Always send it through as lsl.
2575 // ('as' compatibility)
2577 ShiftTy = ARM_AM::lsl;
2578 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2579 ShiftReg = tryParseRegister();
2580 SMLoc L = Parser.getTok().getLoc();
2581 if (ShiftReg == -1) {
2582 Error (L, "expected immediate or register in shift operand");
2586 Error (Parser.getTok().getLoc(),
2587 "expected immediate or register in shift operand");
2592 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2593 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2595 S, Parser.getTok().getLoc()));
2597 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2598 S, Parser.getTok().getLoc()));
2604 /// Try to parse a register name. The token must be an Identifier when called.
2605 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2606 /// if there is a "writeback". 'true' if it's not a register.
2608 /// TODO this is likely to change to allow different register types and or to
2609 /// parse for a specific register type.
2611 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2612 SMLoc S = Parser.getTok().getLoc();
2613 int RegNo = tryParseRegister();
2617 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
2619 const AsmToken &ExclaimTok = Parser.getTok();
2620 if (ExclaimTok.is(AsmToken::Exclaim)) {
2621 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2622 ExclaimTok.getLoc()));
2623 Parser.Lex(); // Eat exclaim token
2627 // Also check for an index operand. This is only legal for vector registers,
2628 // but that'll get caught OK in operand matching, so we don't need to
2629 // explicitly filter everything else out here.
2630 if (Parser.getTok().is(AsmToken::LBrac)) {
2631 SMLoc SIdx = Parser.getTok().getLoc();
2632 Parser.Lex(); // Eat left bracket token.
2634 const MCExpr *ImmVal;
2635 if (getParser().ParseExpression(ImmVal))
2637 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2639 return TokError("immediate value expected for vector index");
2641 SMLoc E = Parser.getTok().getLoc();
2642 if (Parser.getTok().isNot(AsmToken::RBrac))
2643 return Error(E, "']' expected");
2645 Parser.Lex(); // Eat right bracket token.
2647 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2655 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2656 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2658 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2659 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2661 switch (Name.size()) {
2664 if (Name[0] != CoprocOp)
2680 if (Name[0] != CoprocOp || Name[1] != '1')
2684 case '0': return 10;
2685 case '1': return 11;
2686 case '2': return 12;
2687 case '3': return 13;
2688 case '4': return 14;
2689 case '5': return 15;
2694 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2695 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2696 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2697 SMLoc S = Parser.getTok().getLoc();
2698 const AsmToken &Tok = Parser.getTok();
2699 if (!Tok.is(AsmToken::Identifier))
2700 return MatchOperand_NoMatch;
2701 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2702 .Case("eq", ARMCC::EQ)
2703 .Case("ne", ARMCC::NE)
2704 .Case("hs", ARMCC::HS)
2705 .Case("cs", ARMCC::HS)
2706 .Case("lo", ARMCC::LO)
2707 .Case("cc", ARMCC::LO)
2708 .Case("mi", ARMCC::MI)
2709 .Case("pl", ARMCC::PL)
2710 .Case("vs", ARMCC::VS)
2711 .Case("vc", ARMCC::VC)
2712 .Case("hi", ARMCC::HI)
2713 .Case("ls", ARMCC::LS)
2714 .Case("ge", ARMCC::GE)
2715 .Case("lt", ARMCC::LT)
2716 .Case("gt", ARMCC::GT)
2717 .Case("le", ARMCC::LE)
2718 .Case("al", ARMCC::AL)
2721 return MatchOperand_NoMatch;
2722 Parser.Lex(); // Eat the token.
2724 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2726 return MatchOperand_Success;
2729 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2730 /// token must be an Identifier when called, and if it is a coprocessor
2731 /// number, the token is eaten and the operand is added to the operand list.
2732 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2733 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2734 SMLoc S = Parser.getTok().getLoc();
2735 const AsmToken &Tok = Parser.getTok();
2736 if (Tok.isNot(AsmToken::Identifier))
2737 return MatchOperand_NoMatch;
2739 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2741 return MatchOperand_NoMatch;
2743 Parser.Lex(); // Eat identifier token.
2744 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2745 return MatchOperand_Success;
2748 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2749 /// token must be an Identifier when called, and if it is a coprocessor
2750 /// number, the token is eaten and the operand is added to the operand list.
2751 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2752 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2753 SMLoc S = Parser.getTok().getLoc();
2754 const AsmToken &Tok = Parser.getTok();
2755 if (Tok.isNot(AsmToken::Identifier))
2756 return MatchOperand_NoMatch;
2758 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2760 return MatchOperand_NoMatch;
2762 Parser.Lex(); // Eat identifier token.
2763 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2764 return MatchOperand_Success;
2767 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2768 /// coproc_option : '{' imm0_255 '}'
2769 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2770 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2771 SMLoc S = Parser.getTok().getLoc();
2773 // If this isn't a '{', this isn't a coprocessor immediate operand.
2774 if (Parser.getTok().isNot(AsmToken::LCurly))
2775 return MatchOperand_NoMatch;
2776 Parser.Lex(); // Eat the '{'
2779 SMLoc Loc = Parser.getTok().getLoc();
2780 if (getParser().ParseExpression(Expr)) {
2781 Error(Loc, "illegal expression");
2782 return MatchOperand_ParseFail;
2784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2785 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2786 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2787 return MatchOperand_ParseFail;
2789 int Val = CE->getValue();
2791 // Check for and consume the closing '}'
2792 if (Parser.getTok().isNot(AsmToken::RCurly))
2793 return MatchOperand_ParseFail;
2794 SMLoc E = Parser.getTok().getLoc();
2795 Parser.Lex(); // Eat the '}'
2797 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2798 return MatchOperand_Success;
2801 // For register list parsing, we need to map from raw GPR register numbering
2802 // to the enumeration values. The enumeration values aren't sorted by
2803 // register number due to our using "sp", "lr" and "pc" as canonical names.
2804 static unsigned getNextRegister(unsigned Reg) {
2805 // If this is a GPR, we need to do it manually, otherwise we can rely
2806 // on the sort ordering of the enumeration since the other reg-classes
2808 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2811 default: llvm_unreachable("Invalid GPR number!");
2812 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2813 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2814 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2815 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2816 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2817 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2818 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2819 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2823 // Return the low-subreg of a given Q register.
2824 static unsigned getDRegFromQReg(unsigned QReg) {
2826 default: llvm_unreachable("expected a Q register!");
2827 case ARM::Q0: return ARM::D0;
2828 case ARM::Q1: return ARM::D2;
2829 case ARM::Q2: return ARM::D4;
2830 case ARM::Q3: return ARM::D6;
2831 case ARM::Q4: return ARM::D8;
2832 case ARM::Q5: return ARM::D10;
2833 case ARM::Q6: return ARM::D12;
2834 case ARM::Q7: return ARM::D14;
2835 case ARM::Q8: return ARM::D16;
2836 case ARM::Q9: return ARM::D18;
2837 case ARM::Q10: return ARM::D20;
2838 case ARM::Q11: return ARM::D22;
2839 case ARM::Q12: return ARM::D24;
2840 case ARM::Q13: return ARM::D26;
2841 case ARM::Q14: return ARM::D28;
2842 case ARM::Q15: return ARM::D30;
2846 /// Parse a register list.
2848 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2849 assert(Parser.getTok().is(AsmToken::LCurly) &&
2850 "Token is not a Left Curly Brace");
2851 SMLoc S = Parser.getTok().getLoc();
2852 Parser.Lex(); // Eat '{' token.
2853 SMLoc RegLoc = Parser.getTok().getLoc();
2855 // Check the first register in the list to see what register class
2856 // this is a list of.
2857 int Reg = tryParseRegister();
2859 return Error(RegLoc, "register expected");
2861 // The reglist instructions have at most 16 registers, so reserve
2862 // space for that many.
2863 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2865 // Allow Q regs and just interpret them as the two D sub-registers.
2866 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2867 Reg = getDRegFromQReg(Reg);
2868 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2871 const MCRegisterClass *RC;
2872 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2873 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2874 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2875 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2876 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2877 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2879 return Error(RegLoc, "invalid register in register list");
2881 // Store the register.
2882 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2884 // This starts immediately after the first register token in the list,
2885 // so we can see either a comma or a minus (range separator) as a legal
2887 while (Parser.getTok().is(AsmToken::Comma) ||
2888 Parser.getTok().is(AsmToken::Minus)) {
2889 if (Parser.getTok().is(AsmToken::Minus)) {
2890 Parser.Lex(); // Eat the minus.
2891 SMLoc EndLoc = Parser.getTok().getLoc();
2892 int EndReg = tryParseRegister();
2894 return Error(EndLoc, "register expected");
2895 // Allow Q regs and just interpret them as the two D sub-registers.
2896 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2897 EndReg = getDRegFromQReg(EndReg) + 1;
2898 // If the register is the same as the start reg, there's nothing
2902 // The register must be in the same register class as the first.
2903 if (!RC->contains(EndReg))
2904 return Error(EndLoc, "invalid register in register list");
2905 // Ranges must go from low to high.
2906 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
2907 return Error(EndLoc, "bad range in register list");
2909 // Add all the registers in the range to the register list.
2910 while (Reg != EndReg) {
2911 Reg = getNextRegister(Reg);
2912 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2916 Parser.Lex(); // Eat the comma.
2917 RegLoc = Parser.getTok().getLoc();
2919 const AsmToken RegTok = Parser.getTok();
2920 Reg = tryParseRegister();
2922 return Error(RegLoc, "register expected");
2923 // Allow Q regs and just interpret them as the two D sub-registers.
2924 bool isQReg = false;
2925 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2926 Reg = getDRegFromQReg(Reg);
2929 // The register must be in the same register class as the first.
2930 if (!RC->contains(Reg))
2931 return Error(RegLoc, "invalid register in register list");
2932 // List must be monotonically increasing.
2933 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
2934 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2935 Warning(RegLoc, "register list not in ascending order");
2937 return Error(RegLoc, "register list not in ascending order");
2939 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
2940 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2941 ") in register list");
2944 // VFP register lists must also be contiguous.
2945 // It's OK to use the enumeration values directly here rather, as the
2946 // VFP register classes have the enum sorted properly.
2947 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2949 return Error(RegLoc, "non-contiguous register range");
2950 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2952 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
2955 SMLoc E = Parser.getTok().getLoc();
2956 if (Parser.getTok().isNot(AsmToken::RCurly))
2957 return Error(E, "'}' expected");
2958 Parser.Lex(); // Eat '}' token.
2960 // Push the register list operand.
2961 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
2963 // The ARM system instruction variants for LDM/STM have a '^' token here.
2964 if (Parser.getTok().is(AsmToken::Caret)) {
2965 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2966 Parser.Lex(); // Eat '^' token.
2972 // Helper function to parse the lane index for vector lists.
2973 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2974 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2975 Index = 0; // Always return a defined index value.
2976 if (Parser.getTok().is(AsmToken::LBrac)) {
2977 Parser.Lex(); // Eat the '['.
2978 if (Parser.getTok().is(AsmToken::RBrac)) {
2979 // "Dn[]" is the 'all lanes' syntax.
2980 LaneKind = AllLanes;
2981 Parser.Lex(); // Eat the ']'.
2982 return MatchOperand_Success;
2985 // There's an optional '#' token here. Normally there wouldn't be, but
2986 // inline assemble puts one in, and it's friendly to accept that.
2987 if (Parser.getTok().is(AsmToken::Hash))
2988 Parser.Lex(); // Eat the '#'
2990 const MCExpr *LaneIndex;
2991 SMLoc Loc = Parser.getTok().getLoc();
2992 if (getParser().ParseExpression(LaneIndex)) {
2993 Error(Loc, "illegal expression");
2994 return MatchOperand_ParseFail;
2996 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
2998 Error(Loc, "lane index must be empty or an integer");
2999 return MatchOperand_ParseFail;
3001 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3002 Error(Parser.getTok().getLoc(), "']' expected");
3003 return MatchOperand_ParseFail;
3005 Parser.Lex(); // Eat the ']'.
3006 int64_t Val = CE->getValue();
3008 // FIXME: Make this range check context sensitive for .8, .16, .32.
3009 if (Val < 0 || Val > 7) {
3010 Error(Parser.getTok().getLoc(), "lane index out of range");
3011 return MatchOperand_ParseFail;
3014 LaneKind = IndexedLane;
3015 return MatchOperand_Success;
3018 return MatchOperand_Success;
3021 // parse a vector register list
3022 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3023 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3024 VectorLaneTy LaneKind;
3026 SMLoc S = Parser.getTok().getLoc();
3027 // As an extension (to match gas), support a plain D register or Q register
3028 // (without encosing curly braces) as a single or double entry list,
3030 if (Parser.getTok().is(AsmToken::Identifier)) {
3031 int Reg = tryParseRegister();
3033 return MatchOperand_NoMatch;
3034 SMLoc E = Parser.getTok().getLoc();
3035 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3036 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
3037 if (Res != MatchOperand_Success)
3041 E = Parser.getTok().getLoc();
3042 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3045 E = Parser.getTok().getLoc();
3046 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3050 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3055 return MatchOperand_Success;
3057 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3058 Reg = getDRegFromQReg(Reg);
3059 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
3060 if (Res != MatchOperand_Success)
3064 E = Parser.getTok().getLoc();
3065 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3066 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3067 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3070 E = Parser.getTok().getLoc();
3071 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3072 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3073 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3077 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3082 return MatchOperand_Success;
3084 Error(S, "vector register expected");
3085 return MatchOperand_ParseFail;
3088 if (Parser.getTok().isNot(AsmToken::LCurly))
3089 return MatchOperand_NoMatch;
3091 Parser.Lex(); // Eat '{' token.
3092 SMLoc RegLoc = Parser.getTok().getLoc();
3094 int Reg = tryParseRegister();
3096 Error(RegLoc, "register expected");
3097 return MatchOperand_ParseFail;
3101 unsigned FirstReg = Reg;
3102 // The list is of D registers, but we also allow Q regs and just interpret
3103 // them as the two D sub-registers.
3104 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3105 FirstReg = Reg = getDRegFromQReg(Reg);
3106 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3107 // it's ambiguous with four-register single spaced.
3111 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
3112 return MatchOperand_ParseFail;
3114 while (Parser.getTok().is(AsmToken::Comma) ||
3115 Parser.getTok().is(AsmToken::Minus)) {
3116 if (Parser.getTok().is(AsmToken::Minus)) {
3118 Spacing = 1; // Register range implies a single spaced list.
3119 else if (Spacing == 2) {
3120 Error(Parser.getTok().getLoc(),
3121 "sequential registers in double spaced list");
3122 return MatchOperand_ParseFail;
3124 Parser.Lex(); // Eat the minus.
3125 SMLoc EndLoc = Parser.getTok().getLoc();
3126 int EndReg = tryParseRegister();
3128 Error(EndLoc, "register expected");
3129 return MatchOperand_ParseFail;
3131 // Allow Q regs and just interpret them as the two D sub-registers.
3132 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3133 EndReg = getDRegFromQReg(EndReg) + 1;
3134 // If the register is the same as the start reg, there's nothing
3138 // The register must be in the same register class as the first.
3139 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3140 Error(EndLoc, "invalid register in register list");
3141 return MatchOperand_ParseFail;
3143 // Ranges must go from low to high.
3145 Error(EndLoc, "bad range in register list");
3146 return MatchOperand_ParseFail;
3148 // Parse the lane specifier if present.
3149 VectorLaneTy NextLaneKind;
3150 unsigned NextLaneIndex;
3151 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3152 return MatchOperand_ParseFail;
3153 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3154 Error(EndLoc, "mismatched lane index in register list");
3155 return MatchOperand_ParseFail;
3157 EndLoc = Parser.getTok().getLoc();
3159 // Add all the registers in the range to the register list.
3160 Count += EndReg - Reg;
3164 Parser.Lex(); // Eat the comma.
3165 RegLoc = Parser.getTok().getLoc();
3167 Reg = tryParseRegister();
3169 Error(RegLoc, "register expected");
3170 return MatchOperand_ParseFail;
3172 // vector register lists must be contiguous.
3173 // It's OK to use the enumeration values directly here rather, as the
3174 // VFP register classes have the enum sorted properly.
3176 // The list is of D registers, but we also allow Q regs and just interpret
3177 // them as the two D sub-registers.
3178 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3180 Spacing = 1; // Register range implies a single spaced list.
3181 else if (Spacing == 2) {
3183 "invalid register in double-spaced list (must be 'D' register')");
3184 return MatchOperand_ParseFail;
3186 Reg = getDRegFromQReg(Reg);
3187 if (Reg != OldReg + 1) {
3188 Error(RegLoc, "non-contiguous register range");
3189 return MatchOperand_ParseFail;
3193 // Parse the lane specifier if present.
3194 VectorLaneTy NextLaneKind;
3195 unsigned NextLaneIndex;
3196 SMLoc EndLoc = Parser.getTok().getLoc();
3197 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3198 return MatchOperand_ParseFail;
3199 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3200 Error(EndLoc, "mismatched lane index in register list");
3201 return MatchOperand_ParseFail;
3205 // Normal D register.
3206 // Figure out the register spacing (single or double) of the list if
3207 // we don't know it already.
3209 Spacing = 1 + (Reg == OldReg + 2);
3211 // Just check that it's contiguous and keep going.
3212 if (Reg != OldReg + Spacing) {
3213 Error(RegLoc, "non-contiguous register range");
3214 return MatchOperand_ParseFail;
3217 // Parse the lane specifier if present.
3218 VectorLaneTy NextLaneKind;
3219 unsigned NextLaneIndex;
3220 SMLoc EndLoc = Parser.getTok().getLoc();
3221 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3222 return MatchOperand_ParseFail;
3223 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3224 Error(EndLoc, "mismatched lane index in register list");
3225 return MatchOperand_ParseFail;
3229 SMLoc E = Parser.getTok().getLoc();
3230 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3231 Error(E, "'}' expected");
3232 return MatchOperand_ParseFail;
3234 Parser.Lex(); // Eat '}' token.
3238 // Two-register operands have been converted to the
3239 // composite register classes.
3241 const MCRegisterClass *RC = (Spacing == 1) ?
3242 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3243 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3244 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3247 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3248 (Spacing == 2), S, E));
3251 // Two-register operands have been converted to the
3252 // composite register classes.
3254 const MCRegisterClass *RC = (Spacing == 1) ?
3255 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3256 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3257 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3259 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3264 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3270 return MatchOperand_Success;
3273 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3274 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3275 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3276 SMLoc S = Parser.getTok().getLoc();
3277 const AsmToken &Tok = Parser.getTok();
3280 if (Tok.is(AsmToken::Identifier)) {
3281 StringRef OptStr = Tok.getString();
3283 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3284 .Case("sy", ARM_MB::SY)
3285 .Case("st", ARM_MB::ST)
3286 .Case("sh", ARM_MB::ISH)
3287 .Case("ish", ARM_MB::ISH)
3288 .Case("shst", ARM_MB::ISHST)
3289 .Case("ishst", ARM_MB::ISHST)
3290 .Case("nsh", ARM_MB::NSH)
3291 .Case("un", ARM_MB::NSH)
3292 .Case("nshst", ARM_MB::NSHST)
3293 .Case("unst", ARM_MB::NSHST)
3294 .Case("osh", ARM_MB::OSH)
3295 .Case("oshst", ARM_MB::OSHST)
3299 return MatchOperand_NoMatch;
3301 Parser.Lex(); // Eat identifier token.
3302 } else if (Tok.is(AsmToken::Hash) ||
3303 Tok.is(AsmToken::Dollar) ||
3304 Tok.is(AsmToken::Integer)) {
3305 if (Parser.getTok().isNot(AsmToken::Integer))
3306 Parser.Lex(); // Eat the '#'.
3307 SMLoc Loc = Parser.getTok().getLoc();
3309 const MCExpr *MemBarrierID;
3310 if (getParser().ParseExpression(MemBarrierID)) {
3311 Error(Loc, "illegal expression");
3312 return MatchOperand_ParseFail;
3315 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3317 Error(Loc, "constant expression expected");
3318 return MatchOperand_ParseFail;
3321 int Val = CE->getValue();
3323 Error(Loc, "immediate value out of range");
3324 return MatchOperand_ParseFail;
3327 Opt = ARM_MB::RESERVED_0 + Val;
3329 return MatchOperand_ParseFail;
3331 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3332 return MatchOperand_Success;
3335 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3336 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3337 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3338 SMLoc S = Parser.getTok().getLoc();
3339 const AsmToken &Tok = Parser.getTok();
3340 if (!Tok.is(AsmToken::Identifier))
3341 return MatchOperand_NoMatch;
3342 StringRef IFlagsStr = Tok.getString();
3344 // An iflags string of "none" is interpreted to mean that none of the AIF
3345 // bits are set. Not a terribly useful instruction, but a valid encoding.
3346 unsigned IFlags = 0;
3347 if (IFlagsStr != "none") {
3348 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3349 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3350 .Case("a", ARM_PROC::A)
3351 .Case("i", ARM_PROC::I)
3352 .Case("f", ARM_PROC::F)
3355 // If some specific iflag is already set, it means that some letter is
3356 // present more than once, this is not acceptable.
3357 if (Flag == ~0U || (IFlags & Flag))
3358 return MatchOperand_NoMatch;
3364 Parser.Lex(); // Eat identifier token.
3365 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3366 return MatchOperand_Success;
3369 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3370 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3371 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3372 SMLoc S = Parser.getTok().getLoc();
3373 const AsmToken &Tok = Parser.getTok();
3374 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3375 StringRef Mask = Tok.getString();
3378 // See ARMv6-M 10.1.1
3379 std::string Name = Mask.lower();
3380 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3381 // Note: in the documentation:
3382 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3383 // for MSR APSR_nzcvq.
3384 // but we do make it an alias here. This is so to get the "mask encoding"
3385 // bits correct on MSR APSR writes.
3387 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3388 // should really only be allowed when writing a special register. Note
3389 // they get dropped in the MRS instruction reading a special register as
3390 // the SYSm field is only 8 bits.
3392 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3393 // includes the DSP extension but that is not checked.
3394 .Case("apsr", 0x800)
3395 .Case("apsr_nzcvq", 0x800)
3396 .Case("apsr_g", 0x400)
3397 .Case("apsr_nzcvqg", 0xc00)
3398 .Case("iapsr", 0x801)
3399 .Case("iapsr_nzcvq", 0x801)
3400 .Case("iapsr_g", 0x401)
3401 .Case("iapsr_nzcvqg", 0xc01)
3402 .Case("eapsr", 0x802)
3403 .Case("eapsr_nzcvq", 0x802)
3404 .Case("eapsr_g", 0x402)
3405 .Case("eapsr_nzcvqg", 0xc02)
3406 .Case("xpsr", 0x803)
3407 .Case("xpsr_nzcvq", 0x803)
3408 .Case("xpsr_g", 0x403)
3409 .Case("xpsr_nzcvqg", 0xc03)
3410 .Case("ipsr", 0x805)
3411 .Case("epsr", 0x806)
3412 .Case("iepsr", 0x807)
3415 .Case("primask", 0x810)
3416 .Case("basepri", 0x811)
3417 .Case("basepri_max", 0x812)
3418 .Case("faultmask", 0x813)
3419 .Case("control", 0x814)
3422 if (FlagsVal == ~0U)
3423 return MatchOperand_NoMatch;
3425 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3426 // basepri, basepri_max and faultmask only valid for V7m.
3427 return MatchOperand_NoMatch;
3429 Parser.Lex(); // Eat identifier token.
3430 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3431 return MatchOperand_Success;
3434 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3435 size_t Start = 0, Next = Mask.find('_');
3436 StringRef Flags = "";
3437 std::string SpecReg = Mask.slice(Start, Next).lower();
3438 if (Next != StringRef::npos)
3439 Flags = Mask.slice(Next+1, Mask.size());
3441 // FlagsVal contains the complete mask:
3443 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3444 unsigned FlagsVal = 0;
3446 if (SpecReg == "apsr") {
3447 FlagsVal = StringSwitch<unsigned>(Flags)
3448 .Case("nzcvq", 0x8) // same as CPSR_f
3449 .Case("g", 0x4) // same as CPSR_s
3450 .Case("nzcvqg", 0xc) // same as CPSR_fs
3453 if (FlagsVal == ~0U) {
3455 return MatchOperand_NoMatch;
3457 FlagsVal = 8; // No flag
3459 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3460 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3461 if (Flags == "all" || Flags == "")
3463 for (int i = 0, e = Flags.size(); i != e; ++i) {
3464 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3471 // If some specific flag is already set, it means that some letter is
3472 // present more than once, this is not acceptable.
3473 if (FlagsVal == ~0U || (FlagsVal & Flag))
3474 return MatchOperand_NoMatch;
3477 } else // No match for special register.
3478 return MatchOperand_NoMatch;
3480 // Special register without flags is NOT equivalent to "fc" flags.
3481 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3482 // two lines would enable gas compatibility at the expense of breaking
3488 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3489 if (SpecReg == "spsr")
3492 Parser.Lex(); // Eat identifier token.
3493 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3494 return MatchOperand_Success;
3497 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3498 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3499 int Low, int High) {
3500 const AsmToken &Tok = Parser.getTok();
3501 if (Tok.isNot(AsmToken::Identifier)) {
3502 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3503 return MatchOperand_ParseFail;
3505 StringRef ShiftName = Tok.getString();
3506 std::string LowerOp = Op.lower();
3507 std::string UpperOp = Op.upper();
3508 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3509 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3510 return MatchOperand_ParseFail;
3512 Parser.Lex(); // Eat shift type token.
3514 // There must be a '#' and a shift amount.
3515 if (Parser.getTok().isNot(AsmToken::Hash) &&
3516 Parser.getTok().isNot(AsmToken::Dollar)) {
3517 Error(Parser.getTok().getLoc(), "'#' expected");
3518 return MatchOperand_ParseFail;
3520 Parser.Lex(); // Eat hash token.
3522 const MCExpr *ShiftAmount;
3523 SMLoc Loc = Parser.getTok().getLoc();
3524 if (getParser().ParseExpression(ShiftAmount)) {
3525 Error(Loc, "illegal expression");
3526 return MatchOperand_ParseFail;
3528 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3530 Error(Loc, "constant expression expected");
3531 return MatchOperand_ParseFail;
3533 int Val = CE->getValue();
3534 if (Val < Low || Val > High) {
3535 Error(Loc, "immediate value out of range");
3536 return MatchOperand_ParseFail;
3539 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3541 return MatchOperand_Success;
3544 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3545 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3546 const AsmToken &Tok = Parser.getTok();
3547 SMLoc S = Tok.getLoc();
3548 if (Tok.isNot(AsmToken::Identifier)) {
3549 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3550 return MatchOperand_ParseFail;
3552 int Val = StringSwitch<int>(Tok.getString())
3556 Parser.Lex(); // Eat the token.
3559 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3560 return MatchOperand_ParseFail;
3562 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3564 S, Parser.getTok().getLoc()));
3565 return MatchOperand_Success;
3568 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3569 /// instructions. Legal values are:
3570 /// lsl #n 'n' in [0,31]
3571 /// asr #n 'n' in [1,32]
3572 /// n == 32 encoded as n == 0.
3573 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3574 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3575 const AsmToken &Tok = Parser.getTok();
3576 SMLoc S = Tok.getLoc();
3577 if (Tok.isNot(AsmToken::Identifier)) {
3578 Error(S, "shift operator 'asr' or 'lsl' expected");
3579 return MatchOperand_ParseFail;
3581 StringRef ShiftName = Tok.getString();
3583 if (ShiftName == "lsl" || ShiftName == "LSL")
3585 else if (ShiftName == "asr" || ShiftName == "ASR")
3588 Error(S, "shift operator 'asr' or 'lsl' expected");
3589 return MatchOperand_ParseFail;
3591 Parser.Lex(); // Eat the operator.
3593 // A '#' and a shift amount.
3594 if (Parser.getTok().isNot(AsmToken::Hash) &&
3595 Parser.getTok().isNot(AsmToken::Dollar)) {
3596 Error(Parser.getTok().getLoc(), "'#' expected");
3597 return MatchOperand_ParseFail;
3599 Parser.Lex(); // Eat hash token.
3601 const MCExpr *ShiftAmount;
3602 SMLoc E = Parser.getTok().getLoc();
3603 if (getParser().ParseExpression(ShiftAmount)) {
3604 Error(E, "malformed shift expression");
3605 return MatchOperand_ParseFail;
3607 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3609 Error(E, "shift amount must be an immediate");
3610 return MatchOperand_ParseFail;
3613 int64_t Val = CE->getValue();
3615 // Shift amount must be in [1,32]
3616 if (Val < 1 || Val > 32) {
3617 Error(E, "'asr' shift amount must be in range [1,32]");
3618 return MatchOperand_ParseFail;
3620 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3621 if (isThumb() && Val == 32) {
3622 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3623 return MatchOperand_ParseFail;
3625 if (Val == 32) Val = 0;
3627 // Shift amount must be in [1,32]
3628 if (Val < 0 || Val > 31) {
3629 Error(E, "'lsr' shift amount must be in range [0,31]");
3630 return MatchOperand_ParseFail;
3634 E = Parser.getTok().getLoc();
3635 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3637 return MatchOperand_Success;
3640 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3641 /// of instructions. Legal values are:
3642 /// ror #n 'n' in {0, 8, 16, 24}
3643 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3644 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3645 const AsmToken &Tok = Parser.getTok();
3646 SMLoc S = Tok.getLoc();
3647 if (Tok.isNot(AsmToken::Identifier))
3648 return MatchOperand_NoMatch;
3649 StringRef ShiftName = Tok.getString();
3650 if (ShiftName != "ror" && ShiftName != "ROR")
3651 return MatchOperand_NoMatch;
3652 Parser.Lex(); // Eat the operator.
3654 // A '#' and a rotate amount.
3655 if (Parser.getTok().isNot(AsmToken::Hash) &&
3656 Parser.getTok().isNot(AsmToken::Dollar)) {
3657 Error(Parser.getTok().getLoc(), "'#' expected");
3658 return MatchOperand_ParseFail;
3660 Parser.Lex(); // Eat hash token.
3662 const MCExpr *ShiftAmount;
3663 SMLoc E = Parser.getTok().getLoc();
3664 if (getParser().ParseExpression(ShiftAmount)) {
3665 Error(E, "malformed rotate expression");
3666 return MatchOperand_ParseFail;
3668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3670 Error(E, "rotate amount must be an immediate");
3671 return MatchOperand_ParseFail;
3674 int64_t Val = CE->getValue();
3675 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3676 // normally, zero is represented in asm by omitting the rotate operand
3678 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3679 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3680 return MatchOperand_ParseFail;
3683 E = Parser.getTok().getLoc();
3684 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3686 return MatchOperand_Success;
3689 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3690 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3691 SMLoc S = Parser.getTok().getLoc();
3692 // The bitfield descriptor is really two operands, the LSB and the width.
3693 if (Parser.getTok().isNot(AsmToken::Hash) &&
3694 Parser.getTok().isNot(AsmToken::Dollar)) {
3695 Error(Parser.getTok().getLoc(), "'#' expected");
3696 return MatchOperand_ParseFail;
3698 Parser.Lex(); // Eat hash token.
3700 const MCExpr *LSBExpr;
3701 SMLoc E = Parser.getTok().getLoc();
3702 if (getParser().ParseExpression(LSBExpr)) {
3703 Error(E, "malformed immediate expression");
3704 return MatchOperand_ParseFail;
3706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3708 Error(E, "'lsb' operand must be an immediate");
3709 return MatchOperand_ParseFail;
3712 int64_t LSB = CE->getValue();
3713 // The LSB must be in the range [0,31]
3714 if (LSB < 0 || LSB > 31) {
3715 Error(E, "'lsb' operand must be in the range [0,31]");
3716 return MatchOperand_ParseFail;
3718 E = Parser.getTok().getLoc();
3720 // Expect another immediate operand.
3721 if (Parser.getTok().isNot(AsmToken::Comma)) {
3722 Error(Parser.getTok().getLoc(), "too few operands");
3723 return MatchOperand_ParseFail;
3725 Parser.Lex(); // Eat hash token.
3726 if (Parser.getTok().isNot(AsmToken::Hash) &&
3727 Parser.getTok().isNot(AsmToken::Dollar)) {
3728 Error(Parser.getTok().getLoc(), "'#' expected");
3729 return MatchOperand_ParseFail;
3731 Parser.Lex(); // Eat hash token.
3733 const MCExpr *WidthExpr;
3734 if (getParser().ParseExpression(WidthExpr)) {
3735 Error(E, "malformed immediate expression");
3736 return MatchOperand_ParseFail;
3738 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3740 Error(E, "'width' operand must be an immediate");
3741 return MatchOperand_ParseFail;
3744 int64_t Width = CE->getValue();
3745 // The LSB must be in the range [1,32-lsb]
3746 if (Width < 1 || Width > 32 - LSB) {
3747 Error(E, "'width' operand must be in the range [1,32-lsb]");
3748 return MatchOperand_ParseFail;
3750 E = Parser.getTok().getLoc();
3752 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3754 return MatchOperand_Success;
3757 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3758 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3759 // Check for a post-index addressing register operand. Specifically:
3760 // postidx_reg := '+' register {, shift}
3761 // | '-' register {, shift}
3762 // | register {, shift}
3764 // This method must return MatchOperand_NoMatch without consuming any tokens
3765 // in the case where there is no match, as other alternatives take other
3767 AsmToken Tok = Parser.getTok();
3768 SMLoc S = Tok.getLoc();
3769 bool haveEaten = false;
3772 if (Tok.is(AsmToken::Plus)) {
3773 Parser.Lex(); // Eat the '+' token.
3775 } else if (Tok.is(AsmToken::Minus)) {
3776 Parser.Lex(); // Eat the '-' token.
3780 if (Parser.getTok().is(AsmToken::Identifier))
3781 Reg = tryParseRegister();
3784 return MatchOperand_NoMatch;
3785 Error(Parser.getTok().getLoc(), "register expected");
3786 return MatchOperand_ParseFail;
3788 SMLoc E = Parser.getTok().getLoc();
3790 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3791 unsigned ShiftImm = 0;
3792 if (Parser.getTok().is(AsmToken::Comma)) {
3793 Parser.Lex(); // Eat the ','.
3794 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3795 return MatchOperand_ParseFail;
3798 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3801 return MatchOperand_Success;
3804 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3805 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3806 // Check for a post-index addressing register operand. Specifically:
3807 // am3offset := '+' register
3814 // This method must return MatchOperand_NoMatch without consuming any tokens
3815 // in the case where there is no match, as other alternatives take other
3817 AsmToken Tok = Parser.getTok();
3818 SMLoc S = Tok.getLoc();
3820 // Do immediates first, as we always parse those if we have a '#'.
3821 if (Parser.getTok().is(AsmToken::Hash) ||
3822 Parser.getTok().is(AsmToken::Dollar)) {
3823 Parser.Lex(); // Eat the '#'.
3824 // Explicitly look for a '-', as we need to encode negative zero
3826 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3827 const MCExpr *Offset;
3828 if (getParser().ParseExpression(Offset))
3829 return MatchOperand_ParseFail;
3830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3832 Error(S, "constant expression expected");
3833 return MatchOperand_ParseFail;
3835 SMLoc E = Tok.getLoc();
3836 // Negative zero is encoded as the flag value INT32_MIN.
3837 int32_t Val = CE->getValue();
3838 if (isNegative && Val == 0)
3842 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3844 return MatchOperand_Success;
3848 bool haveEaten = false;
3851 if (Tok.is(AsmToken::Plus)) {
3852 Parser.Lex(); // Eat the '+' token.
3854 } else if (Tok.is(AsmToken::Minus)) {
3855 Parser.Lex(); // Eat the '-' token.
3859 if (Parser.getTok().is(AsmToken::Identifier))
3860 Reg = tryParseRegister();
3863 return MatchOperand_NoMatch;
3864 Error(Parser.getTok().getLoc(), "register expected");
3865 return MatchOperand_ParseFail;
3867 SMLoc E = Parser.getTok().getLoc();
3869 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3872 return MatchOperand_Success;
3875 /// cvtT2LdrdPre - Convert parsed operands to MCInst.
3876 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3877 /// when they refer multiple MIOperands inside a single one.
3879 cvtT2LdrdPre(MCInst &Inst,
3880 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3882 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3883 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3884 // Create a writeback register dummy placeholder.
3885 Inst.addOperand(MCOperand::CreateReg(0));
3887 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3889 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3892 /// cvtT2StrdPre - Convert parsed operands to MCInst.
3893 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3894 /// when they refer multiple MIOperands inside a single one.
3896 cvtT2StrdPre(MCInst &Inst,
3897 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3898 // Create a writeback register dummy placeholder.
3899 Inst.addOperand(MCOperand::CreateReg(0));
3901 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3902 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3904 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3906 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3909 /// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3910 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3911 /// when they refer multiple MIOperands inside a single one.
3913 cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
3914 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3915 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3917 // Create a writeback register dummy placeholder.
3918 Inst.addOperand(MCOperand::CreateImm(0));
3920 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3921 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3924 /// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3925 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3926 /// when they refer multiple MIOperands inside a single one.
3928 cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
3929 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3930 // Create a writeback register dummy placeholder.
3931 Inst.addOperand(MCOperand::CreateImm(0));
3932 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3933 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3934 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3937 /// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3938 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3939 /// when they refer multiple MIOperands inside a single one.
3941 cvtLdWriteBackRegAddrMode2(MCInst &Inst,
3942 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3943 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3945 // Create a writeback register dummy placeholder.
3946 Inst.addOperand(MCOperand::CreateImm(0));
3948 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3949 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3952 /// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3953 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3954 /// when they refer multiple MIOperands inside a single one.
3956 cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
3957 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3958 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3960 // Create a writeback register dummy placeholder.
3961 Inst.addOperand(MCOperand::CreateImm(0));
3963 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3964 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3968 /// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3969 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3970 /// when they refer multiple MIOperands inside a single one.
3972 cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
3973 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3974 // Create a writeback register dummy placeholder.
3975 Inst.addOperand(MCOperand::CreateImm(0));
3976 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3977 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3978 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3981 /// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3982 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3983 /// when they refer multiple MIOperands inside a single one.
3985 cvtStWriteBackRegAddrMode2(MCInst &Inst,
3986 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3987 // Create a writeback register dummy placeholder.
3988 Inst.addOperand(MCOperand::CreateImm(0));
3989 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3990 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3991 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3994 /// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3995 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3996 /// when they refer multiple MIOperands inside a single one.
3998 cvtStWriteBackRegAddrMode3(MCInst &Inst,
3999 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4000 // Create a writeback register dummy placeholder.
4001 Inst.addOperand(MCOperand::CreateImm(0));
4002 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4003 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4004 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4007 /// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4008 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4009 /// when they refer multiple MIOperands inside a single one.
4011 cvtLdExtTWriteBackImm(MCInst &Inst,
4012 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4014 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4015 // Create a writeback register dummy placeholder.
4016 Inst.addOperand(MCOperand::CreateImm(0));
4018 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4020 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4022 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4025 /// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
4026 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4027 /// when they refer multiple MIOperands inside a single one.
4029 cvtLdExtTWriteBackReg(MCInst &Inst,
4030 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4032 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4033 // Create a writeback register dummy placeholder.
4034 Inst.addOperand(MCOperand::CreateImm(0));
4036 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4038 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4040 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4043 /// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
4044 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4045 /// when they refer multiple MIOperands inside a single one.
4047 cvtStExtTWriteBackImm(MCInst &Inst,
4048 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4049 // Create a writeback register dummy placeholder.
4050 Inst.addOperand(MCOperand::CreateImm(0));
4052 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4054 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4056 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4058 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4061 /// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4062 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4063 /// when they refer multiple MIOperands inside a single one.
4065 cvtStExtTWriteBackReg(MCInst &Inst,
4066 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4067 // Create a writeback register dummy placeholder.
4068 Inst.addOperand(MCOperand::CreateImm(0));
4070 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4072 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4074 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4076 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4079 /// cvtLdrdPre - Convert parsed operands to MCInst.
4080 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4081 /// when they refer multiple MIOperands inside a single one.
4083 cvtLdrdPre(MCInst &Inst,
4084 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4086 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4087 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4088 // Create a writeback register dummy placeholder.
4089 Inst.addOperand(MCOperand::CreateImm(0));
4091 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4093 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4096 /// cvtStrdPre - Convert parsed operands to MCInst.
4097 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4098 /// when they refer multiple MIOperands inside a single one.
4100 cvtStrdPre(MCInst &Inst,
4101 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4102 // Create a writeback register dummy placeholder.
4103 Inst.addOperand(MCOperand::CreateImm(0));
4105 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4106 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4108 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4110 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4113 /// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4114 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4115 /// when they refer multiple MIOperands inside a single one.
4117 cvtLdWriteBackRegAddrMode3(MCInst &Inst,
4118 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4119 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4120 // Create a writeback register dummy placeholder.
4121 Inst.addOperand(MCOperand::CreateImm(0));
4122 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4123 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4126 /// cvtThumbMultiply - Convert parsed operands to MCInst.
4127 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4128 /// when they refer multiple MIOperands inside a single one.
4130 cvtThumbMultiply(MCInst &Inst,
4131 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4132 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4133 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4134 // If we have a three-operand form, make sure to set Rn to be the operand
4135 // that isn't the same as Rd.
4137 if (Operands.size() == 6 &&
4138 ((ARMOperand*)Operands[4])->getReg() ==
4139 ((ARMOperand*)Operands[3])->getReg())
4141 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4142 Inst.addOperand(Inst.getOperand(0));
4143 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4147 cvtVLDwbFixed(MCInst &Inst,
4148 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4150 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4151 // Create a writeback register dummy placeholder.
4152 Inst.addOperand(MCOperand::CreateImm(0));
4154 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4156 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4160 cvtVLDwbRegister(MCInst &Inst,
4161 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4163 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4164 // Create a writeback register dummy placeholder.
4165 Inst.addOperand(MCOperand::CreateImm(0));
4167 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4169 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4171 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4175 cvtVSTwbFixed(MCInst &Inst,
4176 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4177 // Create a writeback register dummy placeholder.
4178 Inst.addOperand(MCOperand::CreateImm(0));
4180 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4182 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4184 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4188 cvtVSTwbRegister(MCInst &Inst,
4189 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4190 // Create a writeback register dummy placeholder.
4191 Inst.addOperand(MCOperand::CreateImm(0));
4193 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4195 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4197 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4199 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4202 /// Parse an ARM memory expression, return false if successful else return true
4203 /// or an error. The first token must be a '[' when called.
4205 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4207 assert(Parser.getTok().is(AsmToken::LBrac) &&
4208 "Token is not a Left Bracket");
4209 S = Parser.getTok().getLoc();
4210 Parser.Lex(); // Eat left bracket token.
4212 const AsmToken &BaseRegTok = Parser.getTok();
4213 int BaseRegNum = tryParseRegister();
4214 if (BaseRegNum == -1)
4215 return Error(BaseRegTok.getLoc(), "register expected");
4217 // The next token must either be a comma or a closing bracket.
4218 const AsmToken &Tok = Parser.getTok();
4219 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
4220 return Error(Tok.getLoc(), "malformed memory operand");
4222 if (Tok.is(AsmToken::RBrac)) {
4224 Parser.Lex(); // Eat right bracket token.
4226 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4227 0, 0, false, S, E));
4229 // If there's a pre-indexing writeback marker, '!', just add it as a token
4230 // operand. It's rather odd, but syntactically valid.
4231 if (Parser.getTok().is(AsmToken::Exclaim)) {
4232 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4233 Parser.Lex(); // Eat the '!'.
4239 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4240 Parser.Lex(); // Eat the comma.
4242 // If we have a ':', it's an alignment specifier.
4243 if (Parser.getTok().is(AsmToken::Colon)) {
4244 Parser.Lex(); // Eat the ':'.
4245 E = Parser.getTok().getLoc();
4248 if (getParser().ParseExpression(Expr))
4251 // The expression has to be a constant. Memory references with relocations
4252 // don't come through here, as they use the <label> forms of the relevant
4254 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4256 return Error (E, "constant expression expected");
4259 switch (CE->getValue()) {
4262 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4263 case 16: Align = 2; break;
4264 case 32: Align = 4; break;
4265 case 64: Align = 8; break;
4266 case 128: Align = 16; break;
4267 case 256: Align = 32; break;
4270 // Now we should have the closing ']'
4271 E = Parser.getTok().getLoc();
4272 if (Parser.getTok().isNot(AsmToken::RBrac))
4273 return Error(E, "']' expected");
4274 Parser.Lex(); // Eat right bracket token.
4276 // Don't worry about range checking the value here. That's handled by
4277 // the is*() predicates.
4278 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4279 ARM_AM::no_shift, 0, Align,
4282 // If there's a pre-indexing writeback marker, '!', just add it as a token
4284 if (Parser.getTok().is(AsmToken::Exclaim)) {
4285 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4286 Parser.Lex(); // Eat the '!'.
4292 // If we have a '#', it's an immediate offset, else assume it's a register
4293 // offset. Be friendly and also accept a plain integer (without a leading
4294 // hash) for gas compatibility.
4295 if (Parser.getTok().is(AsmToken::Hash) ||
4296 Parser.getTok().is(AsmToken::Dollar) ||
4297 Parser.getTok().is(AsmToken::Integer)) {
4298 if (Parser.getTok().isNot(AsmToken::Integer))
4299 Parser.Lex(); // Eat the '#'.
4300 E = Parser.getTok().getLoc();
4302 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4303 const MCExpr *Offset;
4304 if (getParser().ParseExpression(Offset))
4307 // The expression has to be a constant. Memory references with relocations
4308 // don't come through here, as they use the <label> forms of the relevant
4310 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4312 return Error (E, "constant expression expected");
4314 // If the constant was #-0, represent it as INT32_MIN.
4315 int32_t Val = CE->getValue();
4316 if (isNegative && Val == 0)
4317 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4319 // Now we should have the closing ']'
4320 E = Parser.getTok().getLoc();
4321 if (Parser.getTok().isNot(AsmToken::RBrac))
4322 return Error(E, "']' expected");
4323 Parser.Lex(); // Eat right bracket token.
4325 // Don't worry about range checking the value here. That's handled by
4326 // the is*() predicates.
4327 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4328 ARM_AM::no_shift, 0, 0,
4331 // If there's a pre-indexing writeback marker, '!', just add it as a token
4333 if (Parser.getTok().is(AsmToken::Exclaim)) {
4334 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4335 Parser.Lex(); // Eat the '!'.
4341 // The register offset is optionally preceded by a '+' or '-'
4342 bool isNegative = false;
4343 if (Parser.getTok().is(AsmToken::Minus)) {
4345 Parser.Lex(); // Eat the '-'.
4346 } else if (Parser.getTok().is(AsmToken::Plus)) {
4348 Parser.Lex(); // Eat the '+'.
4351 E = Parser.getTok().getLoc();
4352 int OffsetRegNum = tryParseRegister();
4353 if (OffsetRegNum == -1)
4354 return Error(E, "register expected");
4356 // If there's a shift operator, handle it.
4357 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4358 unsigned ShiftImm = 0;
4359 if (Parser.getTok().is(AsmToken::Comma)) {
4360 Parser.Lex(); // Eat the ','.
4361 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4365 // Now we should have the closing ']'
4366 E = Parser.getTok().getLoc();
4367 if (Parser.getTok().isNot(AsmToken::RBrac))
4368 return Error(E, "']' expected");
4369 Parser.Lex(); // Eat right bracket token.
4371 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4372 ShiftType, ShiftImm, 0, isNegative,
4375 // If there's a pre-indexing writeback marker, '!', just add it as a token
4377 if (Parser.getTok().is(AsmToken::Exclaim)) {
4378 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4379 Parser.Lex(); // Eat the '!'.
4385 /// parseMemRegOffsetShift - one of these two:
4386 /// ( lsl | lsr | asr | ror ) , # shift_amount
4388 /// return true if it parses a shift otherwise it returns false.
4389 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4391 SMLoc Loc = Parser.getTok().getLoc();
4392 const AsmToken &Tok = Parser.getTok();
4393 if (Tok.isNot(AsmToken::Identifier))
4395 StringRef ShiftName = Tok.getString();
4396 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4397 ShiftName == "asl" || ShiftName == "ASL")
4399 else if (ShiftName == "lsr" || ShiftName == "LSR")
4401 else if (ShiftName == "asr" || ShiftName == "ASR")
4403 else if (ShiftName == "ror" || ShiftName == "ROR")
4405 else if (ShiftName == "rrx" || ShiftName == "RRX")
4408 return Error(Loc, "illegal shift operator");
4409 Parser.Lex(); // Eat shift type token.
4411 // rrx stands alone.
4413 if (St != ARM_AM::rrx) {
4414 Loc = Parser.getTok().getLoc();
4415 // A '#' and a shift amount.
4416 const AsmToken &HashTok = Parser.getTok();
4417 if (HashTok.isNot(AsmToken::Hash) &&
4418 HashTok.isNot(AsmToken::Dollar))
4419 return Error(HashTok.getLoc(), "'#' expected");
4420 Parser.Lex(); // Eat hash token.
4423 if (getParser().ParseExpression(Expr))
4425 // Range check the immediate.
4426 // lsl, ror: 0 <= imm <= 31
4427 // lsr, asr: 0 <= imm <= 32
4428 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4430 return Error(Loc, "shift amount must be an immediate");
4431 int64_t Imm = CE->getValue();
4433 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4434 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4435 return Error(Loc, "immediate shift value out of range");
4442 /// parseFPImm - A floating point immediate expression operand.
4443 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4444 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4445 // Anything that can accept a floating point constant as an operand
4446 // needs to go through here, as the regular ParseExpression is
4449 // This routine still creates a generic Immediate operand, containing
4450 // a bitcast of the 64-bit floating point value. The various operands
4451 // that accept floats can check whether the value is valid for them
4452 // via the standard is*() predicates.
4454 SMLoc S = Parser.getTok().getLoc();
4456 if (Parser.getTok().isNot(AsmToken::Hash) &&
4457 Parser.getTok().isNot(AsmToken::Dollar))
4458 return MatchOperand_NoMatch;
4460 // Disambiguate the VMOV forms that can accept an FP immediate.
4461 // vmov.f32 <sreg>, #imm
4462 // vmov.f64 <dreg>, #imm
4463 // vmov.f32 <dreg>, #imm @ vector f32x2
4464 // vmov.f32 <qreg>, #imm @ vector f32x4
4466 // There are also the NEON VMOV instructions which expect an
4467 // integer constant. Make sure we don't try to parse an FPImm
4469 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4470 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4471 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4472 TyOp->getToken() != ".f64"))
4473 return MatchOperand_NoMatch;
4475 Parser.Lex(); // Eat the '#'.
4477 // Handle negation, as that still comes through as a separate token.
4478 bool isNegative = false;
4479 if (Parser.getTok().is(AsmToken::Minus)) {
4483 const AsmToken &Tok = Parser.getTok();
4484 SMLoc Loc = Tok.getLoc();
4485 if (Tok.is(AsmToken::Real)) {
4486 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4487 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4488 // If we had a '-' in front, toggle the sign bit.
4489 IntVal ^= (uint64_t)isNegative << 31;
4490 Parser.Lex(); // Eat the token.
4491 Operands.push_back(ARMOperand::CreateImm(
4492 MCConstantExpr::Create(IntVal, getContext()),
4493 S, Parser.getTok().getLoc()));
4494 return MatchOperand_Success;
4496 // Also handle plain integers. Instructions which allow floating point
4497 // immediates also allow a raw encoded 8-bit value.
4498 if (Tok.is(AsmToken::Integer)) {
4499 int64_t Val = Tok.getIntVal();
4500 Parser.Lex(); // Eat the token.
4501 if (Val > 255 || Val < 0) {
4502 Error(Loc, "encoded floating point value out of range");
4503 return MatchOperand_ParseFail;
4505 double RealVal = ARM_AM::getFPImmFloat(Val);
4506 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4507 Operands.push_back(ARMOperand::CreateImm(
4508 MCConstantExpr::Create(Val, getContext()), S,
4509 Parser.getTok().getLoc()));
4510 return MatchOperand_Success;
4513 Error(Loc, "invalid floating point immediate");
4514 return MatchOperand_ParseFail;
4517 /// Parse a arm instruction operand. For now this parses the operand regardless
4518 /// of the mnemonic.
4519 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4520 StringRef Mnemonic) {
4523 // Check if the current operand has a custom associated parser, if so, try to
4524 // custom parse the operand, or fallback to the general approach.
4525 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4526 if (ResTy == MatchOperand_Success)
4528 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4529 // there was a match, but an error occurred, in which case, just return that
4530 // the operand parsing failed.
4531 if (ResTy == MatchOperand_ParseFail)
4534 switch (getLexer().getKind()) {
4536 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4538 case AsmToken::Identifier: {
4539 if (!tryParseRegisterWithWriteBack(Operands))
4541 int Res = tryParseShiftRegister(Operands);
4542 if (Res == 0) // success
4544 else if (Res == -1) // irrecoverable error
4546 // If this is VMRS, check for the apsr_nzcv operand.
4547 if (Mnemonic == "vmrs" &&
4548 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4549 S = Parser.getTok().getLoc();
4551 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4555 // Fall though for the Identifier case that is not a register or a
4558 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4559 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4560 case AsmToken::String: // quoted label names.
4561 case AsmToken::Dot: { // . as a branch target
4562 // This was not a register so parse other operands that start with an
4563 // identifier (like labels) as expressions and create them as immediates.
4564 const MCExpr *IdVal;
4565 S = Parser.getTok().getLoc();
4566 if (getParser().ParseExpression(IdVal))
4568 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4569 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4572 case AsmToken::LBrac:
4573 return parseMemory(Operands);
4574 case AsmToken::LCurly:
4575 return parseRegisterList(Operands);
4576 case AsmToken::Dollar:
4577 case AsmToken::Hash: {
4578 // #42 -> immediate.
4579 S = Parser.getTok().getLoc();
4582 if (Parser.getTok().isNot(AsmToken::Colon)) {
4583 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4584 const MCExpr *ImmVal;
4585 if (getParser().ParseExpression(ImmVal))
4587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4589 int32_t Val = CE->getValue();
4590 if (isNegative && Val == 0)
4591 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4593 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4594 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4597 // w/ a ':' after the '#', it's just like a plain ':'.
4600 case AsmToken::Colon: {
4601 // ":lower16:" and ":upper16:" expression prefixes
4602 // FIXME: Check it's an expression prefix,
4603 // e.g. (FOO - :lower16:BAR) isn't legal.
4604 ARMMCExpr::VariantKind RefKind;
4605 if (parsePrefix(RefKind))
4608 const MCExpr *SubExprVal;
4609 if (getParser().ParseExpression(SubExprVal))
4612 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4614 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4615 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4621 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4622 // :lower16: and :upper16:.
4623 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4624 RefKind = ARMMCExpr::VK_ARM_None;
4626 // :lower16: and :upper16: modifiers
4627 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4628 Parser.Lex(); // Eat ':'
4630 if (getLexer().isNot(AsmToken::Identifier)) {
4631 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4635 StringRef IDVal = Parser.getTok().getIdentifier();
4636 if (IDVal == "lower16") {
4637 RefKind = ARMMCExpr::VK_ARM_LO16;
4638 } else if (IDVal == "upper16") {
4639 RefKind = ARMMCExpr::VK_ARM_HI16;
4641 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4646 if (getLexer().isNot(AsmToken::Colon)) {
4647 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4650 Parser.Lex(); // Eat the last ':'
4654 /// \brief Given a mnemonic, split out possible predication code and carry
4655 /// setting letters to form a canonical mnemonic and flags.
4657 // FIXME: Would be nice to autogen this.
4658 // FIXME: This is a bit of a maze of special cases.
4659 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4660 unsigned &PredicationCode,
4662 unsigned &ProcessorIMod,
4663 StringRef &ITMask) {
4664 PredicationCode = ARMCC::AL;
4665 CarrySetting = false;
4668 // Ignore some mnemonics we know aren't predicated forms.
4670 // FIXME: Would be nice to autogen this.
4671 if ((Mnemonic == "movs" && isThumb()) ||
4672 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4673 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4674 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4675 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4676 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4677 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4678 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4679 Mnemonic == "fmuls")
4682 // First, split out any predication code. Ignore mnemonics we know aren't
4683 // predicated but do have a carry-set and so weren't caught above.
4684 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4685 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4686 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4687 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4688 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4689 .Case("eq", ARMCC::EQ)
4690 .Case("ne", ARMCC::NE)
4691 .Case("hs", ARMCC::HS)
4692 .Case("cs", ARMCC::HS)
4693 .Case("lo", ARMCC::LO)
4694 .Case("cc", ARMCC::LO)
4695 .Case("mi", ARMCC::MI)
4696 .Case("pl", ARMCC::PL)
4697 .Case("vs", ARMCC::VS)
4698 .Case("vc", ARMCC::VC)
4699 .Case("hi", ARMCC::HI)
4700 .Case("ls", ARMCC::LS)
4701 .Case("ge", ARMCC::GE)
4702 .Case("lt", ARMCC::LT)
4703 .Case("gt", ARMCC::GT)
4704 .Case("le", ARMCC::LE)
4705 .Case("al", ARMCC::AL)
4708 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4709 PredicationCode = CC;
4713 // Next, determine if we have a carry setting bit. We explicitly ignore all
4714 // the instructions we know end in 's'.
4715 if (Mnemonic.endswith("s") &&
4716 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4717 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4718 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4719 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4720 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4721 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4722 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4723 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4724 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4725 (Mnemonic == "movs" && isThumb()))) {
4726 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4727 CarrySetting = true;
4730 // The "cps" instruction can have a interrupt mode operand which is glued into
4731 // the mnemonic. Check if this is the case, split it and parse the imod op
4732 if (Mnemonic.startswith("cps")) {
4733 // Split out any imod code.
4735 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4736 .Case("ie", ARM_PROC::IE)
4737 .Case("id", ARM_PROC::ID)
4740 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4741 ProcessorIMod = IMod;
4745 // The "it" instruction has the condition mask on the end of the mnemonic.
4746 if (Mnemonic.startswith("it")) {
4747 ITMask = Mnemonic.slice(2, Mnemonic.size());
4748 Mnemonic = Mnemonic.slice(0, 2);
4754 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4755 /// inclusion of carry set or predication code operands.
4757 // FIXME: It would be nice to autogen this.
4759 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
4760 bool &CanAcceptPredicationCode) {
4761 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4762 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4763 Mnemonic == "add" || Mnemonic == "adc" ||
4764 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4765 Mnemonic == "orr" || Mnemonic == "mvn" ||
4766 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4767 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4768 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4769 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4770 Mnemonic == "mla" || Mnemonic == "smlal" ||
4771 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4772 CanAcceptCarrySet = true;
4774 CanAcceptCarrySet = false;
4776 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4777 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4778 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4779 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
4780 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4781 (Mnemonic == "clrex" && !isThumb()) ||
4782 (Mnemonic == "nop" && isThumbOne()) ||
4783 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4784 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4785 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
4786 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4788 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
4789 CanAcceptPredicationCode = false;
4791 CanAcceptPredicationCode = true;
4794 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
4795 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
4796 CanAcceptPredicationCode = false;
4800 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4801 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4802 // FIXME: This is all horribly hacky. We really need a better way to deal
4803 // with optional operands like this in the matcher table.
4805 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4806 // another does not. Specifically, the MOVW instruction does not. So we
4807 // special case it here and remove the defaulted (non-setting) cc_out
4808 // operand if that's the instruction we're trying to match.
4810 // We do this as post-processing of the explicit operands rather than just
4811 // conditionally adding the cc_out in the first place because we need
4812 // to check the type of the parsed immediate operand.
4813 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4814 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4815 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4816 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4819 // Register-register 'add' for thumb does not have a cc_out operand
4820 // when there are only two register operands.
4821 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4822 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4823 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4824 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4826 // Register-register 'add' for thumb does not have a cc_out operand
4827 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4828 // have to check the immediate range here since Thumb2 has a variant
4829 // that can handle a different range and has a cc_out operand.
4830 if (((isThumb() && Mnemonic == "add") ||
4831 (isThumbTwo() && Mnemonic == "sub")) &&
4832 Operands.size() == 6 &&
4833 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4834 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4835 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4836 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4837 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4838 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4840 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4841 // imm0_4095 variant. That's the least-preferred variant when
4842 // selecting via the generic "add" mnemonic, so to know that we
4843 // should remove the cc_out operand, we have to explicitly check that
4844 // it's not one of the other variants. Ugh.
4845 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4846 Operands.size() == 6 &&
4847 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4848 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4849 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4850 // Nest conditions rather than one big 'if' statement for readability.
4852 // If either register is a high reg, it's either one of the SP
4853 // variants (handled above) or a 32-bit encoding, so we just
4854 // check against T3. If the second register is the PC, this is an
4855 // alternate form of ADR, which uses encoding T4, so check for that too.
4856 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4857 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
4858 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4859 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4861 // If both registers are low, we're in an IT block, and the immediate is
4862 // in range, we should use encoding T1 instead, which has a cc_out.
4864 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4865 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4866 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4869 // Otherwise, we use encoding T4, which does not have a cc_out
4874 // The thumb2 multiply instruction doesn't have a CCOut register, so
4875 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4876 // use the 16-bit encoding or not.
4877 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4878 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4879 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4880 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4881 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4882 // If the registers aren't low regs, the destination reg isn't the
4883 // same as one of the source regs, or the cc_out operand is zero
4884 // outside of an IT block, we have to use the 32-bit encoding, so
4885 // remove the cc_out operand.
4886 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4887 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4888 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4890 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4891 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4892 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4893 static_cast<ARMOperand*>(Operands[4])->getReg())))
4896 // Also check the 'mul' syntax variant that doesn't specify an explicit
4897 // destination register.
4898 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4899 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4900 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4901 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4902 // If the registers aren't low regs or the cc_out operand is zero
4903 // outside of an IT block, we have to use the 32-bit encoding, so
4904 // remove the cc_out operand.
4905 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4906 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4912 // Register-register 'add/sub' for thumb does not have a cc_out operand
4913 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4914 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4915 // right, this will result in better diagnostics (which operand is off)
4917 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4918 (Operands.size() == 5 || Operands.size() == 6) &&
4919 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4920 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4921 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4922 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4923 (Operands.size() == 6 &&
4924 static_cast<ARMOperand*>(Operands[5])->isImm())))
4930 static bool isDataTypeToken(StringRef Tok) {
4931 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4932 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4933 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4934 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4935 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4936 Tok == ".f" || Tok == ".d";
4939 // FIXME: This bit should probably be handled via an explicit match class
4940 // in the .td files that matches the suffix instead of having it be
4941 // a literal string token the way it is now.
4942 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4943 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4946 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
4947 /// Parse an arm instruction mnemonic followed by its operands.
4948 bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4949 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4950 // Apply mnemonic aliases before doing anything else, as the destination
4951 // mnemnonic may include suffices and we want to handle them normally.
4952 // The generic tblgen'erated code does this later, at the start of
4953 // MatchInstructionImpl(), but that's too late for aliases that include
4954 // any sort of suffix.
4955 unsigned AvailableFeatures = getAvailableFeatures();
4956 applyMnemonicAliases(Name, AvailableFeatures);
4958 // First check for the ARM-specific .req directive.
4959 if (Parser.getTok().is(AsmToken::Identifier) &&
4960 Parser.getTok().getIdentifier() == ".req") {
4961 parseDirectiveReq(Name, NameLoc);
4962 // We always return 'error' for this, as we're done with this
4963 // statement and don't need to match the 'instruction."
4967 // Create the leading tokens for the mnemonic, split by '.' characters.
4968 size_t Start = 0, Next = Name.find('.');
4969 StringRef Mnemonic = Name.slice(Start, Next);
4971 // Split out the predication code and carry setting flag from the mnemonic.
4972 unsigned PredicationCode;
4973 unsigned ProcessorIMod;
4976 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
4977 ProcessorIMod, ITMask);
4979 // In Thumb1, only the branch (B) instruction can be predicated.
4980 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4981 Parser.EatToEndOfStatement();
4982 return Error(NameLoc, "conditional execution not supported in Thumb1");
4985 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4987 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4988 // is the mask as it will be for the IT encoding if the conditional
4989 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4990 // where the conditional bit0 is zero, the instruction post-processing
4991 // will adjust the mask accordingly.
4992 if (Mnemonic == "it") {
4993 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4994 if (ITMask.size() > 3) {
4995 Parser.EatToEndOfStatement();
4996 return Error(Loc, "too many conditions on IT instruction");
4999 for (unsigned i = ITMask.size(); i != 0; --i) {
5000 char pos = ITMask[i - 1];
5001 if (pos != 't' && pos != 'e') {
5002 Parser.EatToEndOfStatement();
5003 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5006 if (ITMask[i - 1] == 't')
5009 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5012 // FIXME: This is all a pretty gross hack. We should automatically handle
5013 // optional operands like this via tblgen.
5015 // Next, add the CCOut and ConditionCode operands, if needed.
5017 // For mnemonics which can ever incorporate a carry setting bit or predication
5018 // code, our matching model involves us always generating CCOut and
5019 // ConditionCode operands to match the mnemonic "as written" and then we let
5020 // the matcher deal with finding the right instruction or generating an
5021 // appropriate error.
5022 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5023 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
5025 // If we had a carry-set on an instruction that can't do that, issue an
5027 if (!CanAcceptCarrySet && CarrySetting) {
5028 Parser.EatToEndOfStatement();
5029 return Error(NameLoc, "instruction '" + Mnemonic +
5030 "' can not set flags, but 's' suffix specified");
5032 // If we had a predication code on an instruction that can't do that, issue an
5034 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5035 Parser.EatToEndOfStatement();
5036 return Error(NameLoc, "instruction '" + Mnemonic +
5037 "' is not predicable, but condition code specified");
5040 // Add the carry setting operand, if necessary.
5041 if (CanAcceptCarrySet) {
5042 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5043 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5047 // Add the predication code operand, if necessary.
5048 if (CanAcceptPredicationCode) {
5049 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5051 Operands.push_back(ARMOperand::CreateCondCode(
5052 ARMCC::CondCodes(PredicationCode), Loc));
5055 // Add the processor imod operand, if necessary.
5056 if (ProcessorIMod) {
5057 Operands.push_back(ARMOperand::CreateImm(
5058 MCConstantExpr::Create(ProcessorIMod, getContext()),
5062 // Add the remaining tokens in the mnemonic.
5063 while (Next != StringRef::npos) {
5065 Next = Name.find('.', Start + 1);
5066 StringRef ExtraToken = Name.slice(Start, Next);
5068 // Some NEON instructions have an optional datatype suffix that is
5069 // completely ignored. Check for that.
5070 if (isDataTypeToken(ExtraToken) &&
5071 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5074 if (ExtraToken != ".n") {
5075 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5076 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5080 // Read the remaining operands.
5081 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5082 // Read the first operand.
5083 if (parseOperand(Operands, Mnemonic)) {
5084 Parser.EatToEndOfStatement();
5088 while (getLexer().is(AsmToken::Comma)) {
5089 Parser.Lex(); // Eat the comma.
5091 // Parse and remember the operand.
5092 if (parseOperand(Operands, Mnemonic)) {
5093 Parser.EatToEndOfStatement();
5099 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5100 SMLoc Loc = getLexer().getLoc();
5101 Parser.EatToEndOfStatement();
5102 return Error(Loc, "unexpected token in argument list");
5105 Parser.Lex(); // Consume the EndOfStatement
5107 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5108 // do and don't have a cc_out optional-def operand. With some spot-checks
5109 // of the operand list, we can figure out which variant we're trying to
5110 // parse and adjust accordingly before actually matching. We shouldn't ever
5111 // try to remove a cc_out operand that was explicitly set on the the
5112 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5113 // table driven matcher doesn't fit well with the ARM instruction set.
5114 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5115 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5116 Operands.erase(Operands.begin() + 1);
5120 // ARM mode 'blx' need special handling, as the register operand version
5121 // is predicable, but the label operand version is not. So, we can't rely
5122 // on the Mnemonic based checking to correctly figure out when to put
5123 // a k_CondCode operand in the list. If we're trying to match the label
5124 // version, remove the k_CondCode operand here.
5125 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5126 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5127 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5128 Operands.erase(Operands.begin() + 1);
5132 // The vector-compare-to-zero instructions have a literal token "#0" at
5133 // the end that comes to here as an immediate operand. Convert it to a
5134 // token to play nicely with the matcher.
5135 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5136 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5137 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5138 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5139 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5140 if (CE && CE->getValue() == 0) {
5141 Operands.erase(Operands.begin() + 5);
5142 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5146 // VCMP{E} does the same thing, but with a different operand count.
5147 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5148 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5149 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5150 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5151 if (CE && CE->getValue() == 0) {
5152 Operands.erase(Operands.begin() + 4);
5153 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5157 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
5158 // end. Convert it to a token here. Take care not to convert those
5159 // that should hit the Thumb2 encoding.
5160 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
5161 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5162 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5163 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5164 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5165 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5166 if (CE && CE->getValue() == 0 &&
5168 // The cc_out operand matches the IT block.
5169 ((inITBlock() != CarrySetting) &&
5170 // Neither register operand is a high register.
5171 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5172 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
5173 Operands.erase(Operands.begin() + 5);
5174 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5182 // Validate context-sensitive operand constraints.
5184 // return 'true' if register list contains non-low GPR registers,
5185 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5186 // 'containsReg' to true.
5187 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5188 unsigned HiReg, bool &containsReg) {
5189 containsReg = false;
5190 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5191 unsigned OpReg = Inst.getOperand(i).getReg();
5194 // Anything other than a low register isn't legal here.
5195 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5201 // Check if the specified regisgter is in the register list of the inst,
5202 // starting at the indicated operand number.
5203 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5204 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5205 unsigned OpReg = Inst.getOperand(i).getReg();
5212 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5213 // the ARMInsts array) instead. Getting that here requires awkward
5214 // API changes, though. Better way?
5216 extern const MCInstrDesc ARMInsts[];
5218 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
5219 return ARMInsts[Opcode];
5222 // FIXME: We would really like to be able to tablegen'erate this.
5224 validateInstruction(MCInst &Inst,
5225 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5226 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
5227 SMLoc Loc = Operands[0]->getStartLoc();
5228 // Check the IT block state first.
5229 // NOTE: BKPT instruction has the interesting property of being
5230 // allowed in IT blocks, but not being predicable. It just always
5232 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5233 Inst.getOpcode() != ARM::BKPT) {
5235 if (ITState.FirstCond)
5236 ITState.FirstCond = false;
5238 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5239 // The instruction must be predicable.
5240 if (!MCID.isPredicable())
5241 return Error(Loc, "instructions in IT block must be predicable");
5242 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5243 unsigned ITCond = bit ? ITState.Cond :
5244 ARMCC::getOppositeCondition(ITState.Cond);
5245 if (Cond != ITCond) {
5246 // Find the condition code Operand to get its SMLoc information.
5248 for (unsigned i = 1; i < Operands.size(); ++i)
5249 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5250 CondLoc = Operands[i]->getStartLoc();
5251 return Error(CondLoc, "incorrect condition in IT block; got '" +
5252 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5253 "', but expected '" +
5254 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5256 // Check for non-'al' condition codes outside of the IT block.
5257 } else if (isThumbTwo() && MCID.isPredicable() &&
5258 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5259 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5260 Inst.getOpcode() != ARM::t2B)
5261 return Error(Loc, "predicated instructions must be in IT block");
5263 switch (Inst.getOpcode()) {
5266 case ARM::LDRD_POST:
5268 // Rt2 must be Rt + 1.
5269 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5270 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5272 return Error(Operands[3]->getStartLoc(),
5273 "destination operands must be sequential");
5277 // Rt2 must be Rt + 1.
5278 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5279 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5281 return Error(Operands[3]->getStartLoc(),
5282 "source operands must be sequential");
5286 case ARM::STRD_POST:
5288 // Rt2 must be Rt + 1.
5289 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5290 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5292 return Error(Operands[3]->getStartLoc(),
5293 "source operands must be sequential");
5298 // width must be in range [1, 32-lsb]
5299 unsigned lsb = Inst.getOperand(2).getImm();
5300 unsigned widthm1 = Inst.getOperand(3).getImm();
5301 if (widthm1 >= 32 - lsb)
5302 return Error(Operands[5]->getStartLoc(),
5303 "bitfield width must be in range [1,32-lsb]");
5307 // If we're parsing Thumb2, the .w variant is available and handles
5308 // most cases that are normally illegal for a Thumb1 LDM
5309 // instruction. We'll make the transformation in processInstruction()
5312 // Thumb LDM instructions are writeback iff the base register is not
5313 // in the register list.
5314 unsigned Rn = Inst.getOperand(0).getReg();
5315 bool hasWritebackToken =
5316 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5317 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5318 bool listContainsBase;
5319 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5320 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5321 "registers must be in range r0-r7");
5322 // If we should have writeback, then there should be a '!' token.
5323 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5324 return Error(Operands[2]->getStartLoc(),
5325 "writeback operator '!' expected");
5326 // If we should not have writeback, there must not be a '!'. This is
5327 // true even for the 32-bit wide encodings.
5328 if (listContainsBase && hasWritebackToken)
5329 return Error(Operands[3]->getStartLoc(),
5330 "writeback operator '!' not allowed when base register "
5331 "in register list");
5335 case ARM::t2LDMIA_UPD: {
5336 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5337 return Error(Operands[4]->getStartLoc(),
5338 "writeback operator '!' not allowed when base register "
5339 "in register list");
5343 // The second source operand must be the same register as the destination
5346 // In this case, we must directly check the parsed operands because the
5347 // cvtThumbMultiply() function is written in such a way that it guarantees
5348 // this first statement is always true for the new Inst. Essentially, the
5349 // destination is unconditionally copied into the second source operand
5350 // without checking to see if it matches what we actually parsed.
5351 if (Operands.size() == 6 &&
5352 (((ARMOperand*)Operands[3])->getReg() !=
5353 ((ARMOperand*)Operands[5])->getReg()) &&
5354 (((ARMOperand*)Operands[3])->getReg() !=
5355 ((ARMOperand*)Operands[4])->getReg())) {
5356 return Error(Operands[3]->getStartLoc(),
5357 "destination register must match source register");
5361 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5362 // so only issue a diagnostic for thumb1. The instructions will be
5363 // switched to the t2 encodings in processInstruction() if necessary.
5365 bool listContainsBase;
5366 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5368 return Error(Operands[2]->getStartLoc(),
5369 "registers must be in range r0-r7 or pc");
5373 bool listContainsBase;
5374 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5376 return Error(Operands[2]->getStartLoc(),
5377 "registers must be in range r0-r7 or lr");
5380 case ARM::tSTMIA_UPD: {
5381 bool listContainsBase;
5382 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5383 return Error(Operands[4]->getStartLoc(),
5384 "registers must be in range r0-r7");
5387 case ARM::tADDrSP: {
5388 // If the non-SP source operand and the destination operand are not the
5389 // same, we need thumb2 (for the wide encoding), or we have an error.
5390 if (!isThumbTwo() &&
5391 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5392 return Error(Operands[4]->getStartLoc(),
5393 "source register must be the same as destination");
5402 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5404 default: llvm_unreachable("unexpected opcode!");
5406 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5407 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5408 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5409 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5410 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5411 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5412 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5413 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5414 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5417 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5418 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5419 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5420 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5421 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5423 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5424 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5425 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5426 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5427 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5429 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5430 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5431 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5432 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5433 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5436 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5437 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5438 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5439 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5440 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5441 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5442 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5443 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5444 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5445 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5446 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5447 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5448 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5449 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5450 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5453 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5454 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5455 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5456 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5457 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5458 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5459 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5460 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5461 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5462 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5463 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5464 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5465 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5466 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5467 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5468 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5469 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5470 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5473 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5474 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5475 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5476 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5477 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5478 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5479 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5480 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5481 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5482 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5483 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5484 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5485 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5486 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5487 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5490 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5491 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5492 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5493 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5494 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5495 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5496 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5497 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5498 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5499 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5500 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5501 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5502 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5503 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5504 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5505 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5506 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5507 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5511 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5513 default: llvm_unreachable("unexpected opcode!");
5515 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5516 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5517 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5518 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5519 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5520 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5521 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5522 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5523 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5526 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5527 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5528 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5529 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5530 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5531 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5532 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5533 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5534 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5535 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5536 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5537 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5538 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5539 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5540 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5543 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5544 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5545 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5546 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5547 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5548 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5549 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5550 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5551 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5552 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5553 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5554 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5555 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5556 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5557 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5558 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5559 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5560 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5563 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5564 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5565 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5566 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5567 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5568 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5569 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5570 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5571 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5572 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5573 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5574 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5575 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5576 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5577 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5580 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5581 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5582 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5583 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5584 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5585 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5586 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5587 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5588 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5589 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5590 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5591 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5592 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5593 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5594 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5595 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5596 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5597 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5600 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5601 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5602 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5603 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5604 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5605 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5606 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5607 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5608 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5609 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5610 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5611 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5612 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5613 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5614 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5617 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5618 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5619 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5620 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5621 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5622 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5623 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5624 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5625 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5626 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5627 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5628 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5629 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5630 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5631 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5632 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5633 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5634 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5637 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5638 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5639 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5640 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5641 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5642 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5643 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5644 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5645 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5646 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5647 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5648 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5649 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5650 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5651 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5652 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5653 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5654 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5659 processInstruction(MCInst &Inst,
5660 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5661 switch (Inst.getOpcode()) {
5662 // Aliases for alternate PC+imm syntax of LDR instructions.
5663 case ARM::t2LDRpcrel:
5664 Inst.setOpcode(ARM::t2LDRpci);
5666 case ARM::t2LDRBpcrel:
5667 Inst.setOpcode(ARM::t2LDRBpci);
5669 case ARM::t2LDRHpcrel:
5670 Inst.setOpcode(ARM::t2LDRHpci);
5672 case ARM::t2LDRSBpcrel:
5673 Inst.setOpcode(ARM::t2LDRSBpci);
5675 case ARM::t2LDRSHpcrel:
5676 Inst.setOpcode(ARM::t2LDRSHpci);
5678 // Handle NEON VST complex aliases.
5679 case ARM::VST1LNdWB_register_Asm_8:
5680 case ARM::VST1LNdWB_register_Asm_16:
5681 case ARM::VST1LNdWB_register_Asm_32: {
5683 // Shuffle the operands around so the lane index operand is in the
5686 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5687 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5688 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5689 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5690 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5691 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5692 TmpInst.addOperand(Inst.getOperand(1)); // lane
5693 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5694 TmpInst.addOperand(Inst.getOperand(6));
5699 case ARM::VST2LNdWB_register_Asm_8:
5700 case ARM::VST2LNdWB_register_Asm_16:
5701 case ARM::VST2LNdWB_register_Asm_32:
5702 case ARM::VST2LNqWB_register_Asm_16:
5703 case ARM::VST2LNqWB_register_Asm_32: {
5705 // Shuffle the operands around so the lane index operand is in the
5708 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5709 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5710 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5711 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5712 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5713 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5714 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5716 TmpInst.addOperand(Inst.getOperand(1)); // lane
5717 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5718 TmpInst.addOperand(Inst.getOperand(6));
5723 case ARM::VST3LNdWB_register_Asm_8:
5724 case ARM::VST3LNdWB_register_Asm_16:
5725 case ARM::VST3LNdWB_register_Asm_32:
5726 case ARM::VST3LNqWB_register_Asm_16:
5727 case ARM::VST3LNqWB_register_Asm_32: {
5729 // Shuffle the operands around so the lane index operand is in the
5732 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5733 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5734 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5735 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5736 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5737 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5738 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5740 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5742 TmpInst.addOperand(Inst.getOperand(1)); // lane
5743 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5744 TmpInst.addOperand(Inst.getOperand(6));
5749 case ARM::VST4LNdWB_register_Asm_8:
5750 case ARM::VST4LNdWB_register_Asm_16:
5751 case ARM::VST4LNdWB_register_Asm_32:
5752 case ARM::VST4LNqWB_register_Asm_16:
5753 case ARM::VST4LNqWB_register_Asm_32: {
5755 // Shuffle the operands around so the lane index operand is in the
5758 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5759 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5760 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5761 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5762 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5763 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5764 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5766 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5768 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5770 TmpInst.addOperand(Inst.getOperand(1)); // lane
5771 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5772 TmpInst.addOperand(Inst.getOperand(6));
5777 case ARM::VST1LNdWB_fixed_Asm_8:
5778 case ARM::VST1LNdWB_fixed_Asm_16:
5779 case ARM::VST1LNdWB_fixed_Asm_32: {
5781 // Shuffle the operands around so the lane index operand is in the
5784 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5785 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5786 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5787 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5788 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5789 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5790 TmpInst.addOperand(Inst.getOperand(1)); // lane
5791 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5792 TmpInst.addOperand(Inst.getOperand(5));
5797 case ARM::VST2LNdWB_fixed_Asm_8:
5798 case ARM::VST2LNdWB_fixed_Asm_16:
5799 case ARM::VST2LNdWB_fixed_Asm_32:
5800 case ARM::VST2LNqWB_fixed_Asm_16:
5801 case ARM::VST2LNqWB_fixed_Asm_32: {
5803 // Shuffle the operands around so the lane index operand is in the
5806 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5807 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5808 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5809 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5810 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5811 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5812 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5814 TmpInst.addOperand(Inst.getOperand(1)); // lane
5815 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5816 TmpInst.addOperand(Inst.getOperand(5));
5821 case ARM::VST3LNdWB_fixed_Asm_8:
5822 case ARM::VST3LNdWB_fixed_Asm_16:
5823 case ARM::VST3LNdWB_fixed_Asm_32:
5824 case ARM::VST3LNqWB_fixed_Asm_16:
5825 case ARM::VST3LNqWB_fixed_Asm_32: {
5827 // Shuffle the operands around so the lane index operand is in the
5830 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5831 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5832 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5833 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5834 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5835 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5836 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5838 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5840 TmpInst.addOperand(Inst.getOperand(1)); // lane
5841 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5842 TmpInst.addOperand(Inst.getOperand(5));
5847 case ARM::VST4LNdWB_fixed_Asm_8:
5848 case ARM::VST4LNdWB_fixed_Asm_16:
5849 case ARM::VST4LNdWB_fixed_Asm_32:
5850 case ARM::VST4LNqWB_fixed_Asm_16:
5851 case ARM::VST4LNqWB_fixed_Asm_32: {
5853 // Shuffle the operands around so the lane index operand is in the
5856 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5857 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5858 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5859 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5860 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5861 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5862 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5864 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5866 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5868 TmpInst.addOperand(Inst.getOperand(1)); // lane
5869 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5870 TmpInst.addOperand(Inst.getOperand(5));
5875 case ARM::VST1LNdAsm_8:
5876 case ARM::VST1LNdAsm_16:
5877 case ARM::VST1LNdAsm_32: {
5879 // Shuffle the operands around so the lane index operand is in the
5882 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5883 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5884 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5885 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5886 TmpInst.addOperand(Inst.getOperand(1)); // lane
5887 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5888 TmpInst.addOperand(Inst.getOperand(5));
5893 case ARM::VST2LNdAsm_8:
5894 case ARM::VST2LNdAsm_16:
5895 case ARM::VST2LNdAsm_32:
5896 case ARM::VST2LNqAsm_16:
5897 case ARM::VST2LNqAsm_32: {
5899 // Shuffle the operands around so the lane index operand is in the
5902 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5903 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5904 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5905 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5906 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5908 TmpInst.addOperand(Inst.getOperand(1)); // lane
5909 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5910 TmpInst.addOperand(Inst.getOperand(5));
5915 case ARM::VST3LNdAsm_8:
5916 case ARM::VST3LNdAsm_16:
5917 case ARM::VST3LNdAsm_32:
5918 case ARM::VST3LNqAsm_16:
5919 case ARM::VST3LNqAsm_32: {
5921 // Shuffle the operands around so the lane index operand is in the
5924 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5925 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5926 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5927 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5928 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5930 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5932 TmpInst.addOperand(Inst.getOperand(1)); // lane
5933 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5934 TmpInst.addOperand(Inst.getOperand(5));
5939 case ARM::VST4LNdAsm_8:
5940 case ARM::VST4LNdAsm_16:
5941 case ARM::VST4LNdAsm_32:
5942 case ARM::VST4LNqAsm_16:
5943 case ARM::VST4LNqAsm_32: {
5945 // Shuffle the operands around so the lane index operand is in the
5948 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5949 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5950 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5951 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5952 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5954 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5956 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5958 TmpInst.addOperand(Inst.getOperand(1)); // lane
5959 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5960 TmpInst.addOperand(Inst.getOperand(5));
5965 // Handle NEON VLD complex aliases.
5966 case ARM::VLD1LNdWB_register_Asm_8:
5967 case ARM::VLD1LNdWB_register_Asm_16:
5968 case ARM::VLD1LNdWB_register_Asm_32: {
5970 // Shuffle the operands around so the lane index operand is in the
5973 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5974 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5975 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5976 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5977 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5978 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5979 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5980 TmpInst.addOperand(Inst.getOperand(1)); // lane
5981 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5982 TmpInst.addOperand(Inst.getOperand(6));
5987 case ARM::VLD2LNdWB_register_Asm_8:
5988 case ARM::VLD2LNdWB_register_Asm_16:
5989 case ARM::VLD2LNdWB_register_Asm_32:
5990 case ARM::VLD2LNqWB_register_Asm_16:
5991 case ARM::VLD2LNqWB_register_Asm_32: {
5993 // Shuffle the operands around so the lane index operand is in the
5996 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5997 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5998 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
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(Inst.getOperand(4)); // Rm
6004 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6005 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6007 TmpInst.addOperand(Inst.getOperand(1)); // lane
6008 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6009 TmpInst.addOperand(Inst.getOperand(6));
6014 case ARM::VLD3LNdWB_register_Asm_8:
6015 case ARM::VLD3LNdWB_register_Asm_16:
6016 case ARM::VLD3LNdWB_register_Asm_32:
6017 case ARM::VLD3LNqWB_register_Asm_16:
6018 case ARM::VLD3LNqWB_register_Asm_32: {
6020 // Shuffle the operands around so the lane index operand is in the
6023 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6024 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6025 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6027 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6029 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6030 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6031 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6032 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6033 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6034 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6036 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6038 TmpInst.addOperand(Inst.getOperand(1)); // lane
6039 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6040 TmpInst.addOperand(Inst.getOperand(6));
6045 case ARM::VLD4LNdWB_register_Asm_8:
6046 case ARM::VLD4LNdWB_register_Asm_16:
6047 case ARM::VLD4LNdWB_register_Asm_32:
6048 case ARM::VLD4LNqWB_register_Asm_16:
6049 case ARM::VLD4LNqWB_register_Asm_32: {
6051 // Shuffle the operands around so the lane index operand is in the
6054 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6055 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6056 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6058 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6060 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6062 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6063 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6064 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6065 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6066 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6067 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6069 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6071 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6073 TmpInst.addOperand(Inst.getOperand(1)); // lane
6074 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6075 TmpInst.addOperand(Inst.getOperand(6));
6080 case ARM::VLD1LNdWB_fixed_Asm_8:
6081 case ARM::VLD1LNdWB_fixed_Asm_16:
6082 case ARM::VLD1LNdWB_fixed_Asm_32: {
6084 // Shuffle the operands around so the lane index operand is in the
6087 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6088 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6089 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6090 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6091 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6092 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6093 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6094 TmpInst.addOperand(Inst.getOperand(1)); // lane
6095 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6096 TmpInst.addOperand(Inst.getOperand(5));
6101 case ARM::VLD2LNdWB_fixed_Asm_8:
6102 case ARM::VLD2LNdWB_fixed_Asm_16:
6103 case ARM::VLD2LNdWB_fixed_Asm_32:
6104 case ARM::VLD2LNqWB_fixed_Asm_16:
6105 case ARM::VLD2LNqWB_fixed_Asm_32: {
6107 // Shuffle the operands around so the lane index operand is in the
6110 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6111 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6112 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6114 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6115 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6116 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6117 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6118 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6119 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6121 TmpInst.addOperand(Inst.getOperand(1)); // lane
6122 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6123 TmpInst.addOperand(Inst.getOperand(5));
6128 case ARM::VLD3LNdWB_fixed_Asm_8:
6129 case ARM::VLD3LNdWB_fixed_Asm_16:
6130 case ARM::VLD3LNdWB_fixed_Asm_32:
6131 case ARM::VLD3LNqWB_fixed_Asm_16:
6132 case ARM::VLD3LNqWB_fixed_Asm_32: {
6134 // Shuffle the operands around so the lane index operand is in the
6137 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6138 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6139 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6141 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6143 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6144 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6145 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6146 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6147 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6148 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6150 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6152 TmpInst.addOperand(Inst.getOperand(1)); // lane
6153 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6154 TmpInst.addOperand(Inst.getOperand(5));
6159 case ARM::VLD4LNdWB_fixed_Asm_8:
6160 case ARM::VLD4LNdWB_fixed_Asm_16:
6161 case ARM::VLD4LNdWB_fixed_Asm_32:
6162 case ARM::VLD4LNqWB_fixed_Asm_16:
6163 case ARM::VLD4LNqWB_fixed_Asm_32: {
6165 // Shuffle the operands around so the lane index operand is in the
6168 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6169 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6170 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6172 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6174 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6176 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6177 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6178 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6179 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6180 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6181 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6183 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6185 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6187 TmpInst.addOperand(Inst.getOperand(1)); // lane
6188 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6189 TmpInst.addOperand(Inst.getOperand(5));
6194 case ARM::VLD1LNdAsm_8:
6195 case ARM::VLD1LNdAsm_16:
6196 case ARM::VLD1LNdAsm_32: {
6198 // Shuffle the operands around so the lane index operand is in the
6201 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6202 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6203 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6204 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6205 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6206 TmpInst.addOperand(Inst.getOperand(1)); // lane
6207 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6208 TmpInst.addOperand(Inst.getOperand(5));
6213 case ARM::VLD2LNdAsm_8:
6214 case ARM::VLD2LNdAsm_16:
6215 case ARM::VLD2LNdAsm_32:
6216 case ARM::VLD2LNqAsm_16:
6217 case ARM::VLD2LNqAsm_32: {
6219 // Shuffle the operands around so the lane index operand is in the
6222 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6223 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6224 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6226 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6227 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6228 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6229 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6231 TmpInst.addOperand(Inst.getOperand(1)); // lane
6232 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6233 TmpInst.addOperand(Inst.getOperand(5));
6238 case ARM::VLD3LNdAsm_8:
6239 case ARM::VLD3LNdAsm_16:
6240 case ARM::VLD3LNdAsm_32:
6241 case ARM::VLD3LNqAsm_16:
6242 case ARM::VLD3LNqAsm_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(Inst.getOperand(2)); // Rn
6254 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6255 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6258 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6260 TmpInst.addOperand(Inst.getOperand(1)); // lane
6261 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6262 TmpInst.addOperand(Inst.getOperand(5));
6267 case ARM::VLD4LNdAsm_8:
6268 case ARM::VLD4LNdAsm_16:
6269 case ARM::VLD4LNdAsm_32:
6270 case ARM::VLD4LNqAsm_16:
6271 case ARM::VLD4LNqAsm_32: {
6273 // Shuffle the operands around so the lane index operand is in the
6276 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6277 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6278 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6280 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6282 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6284 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6285 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6286 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6287 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6293 TmpInst.addOperand(Inst.getOperand(1)); // lane
6294 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6295 TmpInst.addOperand(Inst.getOperand(5));
6300 // VLD3DUP single 3-element structure to all lanes instructions.
6301 case ARM::VLD3DUPdAsm_8:
6302 case ARM::VLD3DUPdAsm_16:
6303 case ARM::VLD3DUPdAsm_32:
6304 case ARM::VLD3DUPqAsm_8:
6305 case ARM::VLD3DUPqAsm_16:
6306 case ARM::VLD3DUPqAsm_32: {
6309 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6310 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6311 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6313 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6315 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6316 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6317 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6318 TmpInst.addOperand(Inst.getOperand(4));
6323 case ARM::VLD3DUPdWB_fixed_Asm_8:
6324 case ARM::VLD3DUPdWB_fixed_Asm_16:
6325 case ARM::VLD3DUPdWB_fixed_Asm_32:
6326 case ARM::VLD3DUPqWB_fixed_Asm_8:
6327 case ARM::VLD3DUPqWB_fixed_Asm_16:
6328 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6331 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6332 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6335 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6337 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6338 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6339 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6340 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6341 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6342 TmpInst.addOperand(Inst.getOperand(4));
6347 case ARM::VLD3DUPdWB_register_Asm_8:
6348 case ARM::VLD3DUPdWB_register_Asm_16:
6349 case ARM::VLD3DUPdWB_register_Asm_32:
6350 case ARM::VLD3DUPqWB_register_Asm_8:
6351 case ARM::VLD3DUPqWB_register_Asm_16:
6352 case ARM::VLD3DUPqWB_register_Asm_32: {
6355 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6356 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6357 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6359 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6361 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6362 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6363 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6364 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6365 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6366 TmpInst.addOperand(Inst.getOperand(5));
6371 // VLD3 multiple 3-element structure instructions.
6372 case ARM::VLD3dAsm_8:
6373 case ARM::VLD3dAsm_16:
6374 case ARM::VLD3dAsm_32:
6375 case ARM::VLD3qAsm_8:
6376 case ARM::VLD3qAsm_16:
6377 case ARM::VLD3qAsm_32: {
6380 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6381 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6382 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6384 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6386 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6387 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6388 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6389 TmpInst.addOperand(Inst.getOperand(4));
6394 case ARM::VLD3dWB_fixed_Asm_8:
6395 case ARM::VLD3dWB_fixed_Asm_16:
6396 case ARM::VLD3dWB_fixed_Asm_32:
6397 case ARM::VLD3qWB_fixed_Asm_8:
6398 case ARM::VLD3qWB_fixed_Asm_16:
6399 case ARM::VLD3qWB_fixed_Asm_32: {
6402 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6403 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6408 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6409 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6410 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6411 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6412 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6413 TmpInst.addOperand(Inst.getOperand(4));
6418 case ARM::VLD3dWB_register_Asm_8:
6419 case ARM::VLD3dWB_register_Asm_16:
6420 case ARM::VLD3dWB_register_Asm_32:
6421 case ARM::VLD3qWB_register_Asm_8:
6422 case ARM::VLD3qWB_register_Asm_16:
6423 case ARM::VLD3qWB_register_Asm_32: {
6426 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6427 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6430 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6432 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6433 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6434 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6435 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6436 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6437 TmpInst.addOperand(Inst.getOperand(5));
6442 // VLD4DUP single 3-element structure to all lanes instructions.
6443 case ARM::VLD4DUPdAsm_8:
6444 case ARM::VLD4DUPdAsm_16:
6445 case ARM::VLD4DUPdAsm_32:
6446 case ARM::VLD4DUPqAsm_8:
6447 case ARM::VLD4DUPqAsm_16:
6448 case ARM::VLD4DUPqAsm_32: {
6451 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6452 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6453 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6455 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6457 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6459 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6460 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6461 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6462 TmpInst.addOperand(Inst.getOperand(4));
6467 case ARM::VLD4DUPdWB_fixed_Asm_8:
6468 case ARM::VLD4DUPdWB_fixed_Asm_16:
6469 case ARM::VLD4DUPdWB_fixed_Asm_32:
6470 case ARM::VLD4DUPqWB_fixed_Asm_8:
6471 case ARM::VLD4DUPqWB_fixed_Asm_16:
6472 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6475 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6476 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6477 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6479 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6481 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6483 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6484 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6485 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6486 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6487 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6488 TmpInst.addOperand(Inst.getOperand(4));
6493 case ARM::VLD4DUPdWB_register_Asm_8:
6494 case ARM::VLD4DUPdWB_register_Asm_16:
6495 case ARM::VLD4DUPdWB_register_Asm_32:
6496 case ARM::VLD4DUPqWB_register_Asm_8:
6497 case ARM::VLD4DUPqWB_register_Asm_16:
6498 case ARM::VLD4DUPqWB_register_Asm_32: {
6501 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6502 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6503 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6505 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6507 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6509 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6510 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6511 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6512 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6513 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6514 TmpInst.addOperand(Inst.getOperand(5));
6519 // VLD4 multiple 4-element structure instructions.
6520 case ARM::VLD4dAsm_8:
6521 case ARM::VLD4dAsm_16:
6522 case ARM::VLD4dAsm_32:
6523 case ARM::VLD4qAsm_8:
6524 case ARM::VLD4qAsm_16:
6525 case ARM::VLD4qAsm_32: {
6528 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6529 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6534 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6536 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6537 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6538 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6539 TmpInst.addOperand(Inst.getOperand(4));
6544 case ARM::VLD4dWB_fixed_Asm_8:
6545 case ARM::VLD4dWB_fixed_Asm_16:
6546 case ARM::VLD4dWB_fixed_Asm_32:
6547 case ARM::VLD4qWB_fixed_Asm_8:
6548 case ARM::VLD4qWB_fixed_Asm_16:
6549 case ARM::VLD4qWB_fixed_Asm_32: {
6552 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6553 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6558 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6560 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6561 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6562 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6563 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6564 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6565 TmpInst.addOperand(Inst.getOperand(4));
6570 case ARM::VLD4dWB_register_Asm_8:
6571 case ARM::VLD4dWB_register_Asm_16:
6572 case ARM::VLD4dWB_register_Asm_32:
6573 case ARM::VLD4qWB_register_Asm_8:
6574 case ARM::VLD4qWB_register_Asm_16:
6575 case ARM::VLD4qWB_register_Asm_32: {
6578 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6579 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6582 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6584 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6586 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6587 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6588 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6589 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6590 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6591 TmpInst.addOperand(Inst.getOperand(5));
6596 // VST3 multiple 3-element structure instructions.
6597 case ARM::VST3dAsm_8:
6598 case ARM::VST3dAsm_16:
6599 case ARM::VST3dAsm_32:
6600 case ARM::VST3qAsm_8:
6601 case ARM::VST3qAsm_16:
6602 case ARM::VST3qAsm_32: {
6605 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6606 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6607 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6608 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6609 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6611 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6613 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6614 TmpInst.addOperand(Inst.getOperand(4));
6619 case ARM::VST3dWB_fixed_Asm_8:
6620 case ARM::VST3dWB_fixed_Asm_16:
6621 case ARM::VST3dWB_fixed_Asm_32:
6622 case ARM::VST3qWB_fixed_Asm_8:
6623 case ARM::VST3qWB_fixed_Asm_16:
6624 case ARM::VST3qWB_fixed_Asm_32: {
6627 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6628 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6629 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6630 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6631 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6632 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6633 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6635 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6637 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6638 TmpInst.addOperand(Inst.getOperand(4));
6643 case ARM::VST3dWB_register_Asm_8:
6644 case ARM::VST3dWB_register_Asm_16:
6645 case ARM::VST3dWB_register_Asm_32:
6646 case ARM::VST3qWB_register_Asm_8:
6647 case ARM::VST3qWB_register_Asm_16:
6648 case ARM::VST3qWB_register_Asm_32: {
6651 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6652 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6653 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6654 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6655 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6656 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6657 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6659 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6661 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6662 TmpInst.addOperand(Inst.getOperand(5));
6667 // VST4 multiple 3-element structure instructions.
6668 case ARM::VST4dAsm_8:
6669 case ARM::VST4dAsm_16:
6670 case ARM::VST4dAsm_32:
6671 case ARM::VST4qAsm_8:
6672 case ARM::VST4qAsm_16:
6673 case ARM::VST4qAsm_32: {
6676 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6677 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6678 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6679 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6680 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6682 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6684 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6686 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6687 TmpInst.addOperand(Inst.getOperand(4));
6692 case ARM::VST4dWB_fixed_Asm_8:
6693 case ARM::VST4dWB_fixed_Asm_16:
6694 case ARM::VST4dWB_fixed_Asm_32:
6695 case ARM::VST4qWB_fixed_Asm_8:
6696 case ARM::VST4qWB_fixed_Asm_16:
6697 case ARM::VST4qWB_fixed_Asm_32: {
6700 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6701 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6702 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6703 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6704 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6705 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6706 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6708 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6710 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6712 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6713 TmpInst.addOperand(Inst.getOperand(4));
6718 case ARM::VST4dWB_register_Asm_8:
6719 case ARM::VST4dWB_register_Asm_16:
6720 case ARM::VST4dWB_register_Asm_32:
6721 case ARM::VST4qWB_register_Asm_8:
6722 case ARM::VST4qWB_register_Asm_16:
6723 case ARM::VST4qWB_register_Asm_32: {
6726 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6727 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6728 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6729 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6730 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6731 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6732 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6734 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6736 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6738 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6739 TmpInst.addOperand(Inst.getOperand(5));
6744 // Handle encoding choice for the shift-immediate instructions.
6747 case ARM::t2ASRri: {
6748 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6749 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6750 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6751 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6752 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6754 switch (Inst.getOpcode()) {
6755 default: llvm_unreachable("unexpected opcode");
6756 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6757 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6758 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6760 // The Thumb1 operands aren't in the same order. Awesome, eh?
6762 TmpInst.setOpcode(NewOpc);
6763 TmpInst.addOperand(Inst.getOperand(0));
6764 TmpInst.addOperand(Inst.getOperand(5));
6765 TmpInst.addOperand(Inst.getOperand(1));
6766 TmpInst.addOperand(Inst.getOperand(2));
6767 TmpInst.addOperand(Inst.getOperand(3));
6768 TmpInst.addOperand(Inst.getOperand(4));
6775 // Handle the Thumb2 mode MOV complex aliases.
6777 case ARM::t2MOVSsr: {
6778 // Which instruction to expand to depends on the CCOut operand and
6779 // whether we're in an IT block if the register operands are low
6781 bool isNarrow = false;
6782 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6783 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6784 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6785 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6786 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6790 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6791 default: llvm_unreachable("unexpected opcode!");
6792 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6793 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6794 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6795 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6797 TmpInst.setOpcode(newOpc);
6798 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6800 TmpInst.addOperand(MCOperand::CreateReg(
6801 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6802 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6803 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6804 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6805 TmpInst.addOperand(Inst.getOperand(5));
6807 TmpInst.addOperand(MCOperand::CreateReg(
6808 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6813 case ARM::t2MOVSsi: {
6814 // Which instruction to expand to depends on the CCOut operand and
6815 // whether we're in an IT block if the register operands are low
6817 bool isNarrow = false;
6818 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6819 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6820 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6824 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6825 default: llvm_unreachable("unexpected opcode!");
6826 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6827 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6828 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6829 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
6830 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
6832 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6833 if (Amount == 32) Amount = 0;
6834 TmpInst.setOpcode(newOpc);
6835 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6837 TmpInst.addOperand(MCOperand::CreateReg(
6838 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6839 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6840 if (newOpc != ARM::t2RRX)
6841 TmpInst.addOperand(MCOperand::CreateImm(Amount));
6842 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6843 TmpInst.addOperand(Inst.getOperand(4));
6845 TmpInst.addOperand(MCOperand::CreateReg(
6846 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6850 // Handle the ARM mode MOV complex aliases.
6855 ARM_AM::ShiftOpc ShiftTy;
6856 switch(Inst.getOpcode()) {
6857 default: llvm_unreachable("unexpected opcode!");
6858 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6859 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6860 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6861 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6863 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6865 TmpInst.setOpcode(ARM::MOVsr);
6866 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6867 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6868 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6869 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6870 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6871 TmpInst.addOperand(Inst.getOperand(4));
6872 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6880 ARM_AM::ShiftOpc ShiftTy;
6881 switch(Inst.getOpcode()) {
6882 default: llvm_unreachable("unexpected opcode!");
6883 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6884 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6885 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6886 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6888 // A shift by zero is a plain MOVr, not a MOVsi.
6889 unsigned Amt = Inst.getOperand(2).getImm();
6890 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
6891 // A shift by 32 should be encoded as 0 when permitted
6892 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6894 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
6896 TmpInst.setOpcode(Opc);
6897 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6898 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6899 if (Opc == ARM::MOVsi)
6900 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6901 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6902 TmpInst.addOperand(Inst.getOperand(4));
6903 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6908 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6910 TmpInst.setOpcode(ARM::MOVsi);
6911 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6912 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6913 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6914 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6915 TmpInst.addOperand(Inst.getOperand(3));
6916 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6920 case ARM::t2LDMIA_UPD: {
6921 // If this is a load of a single register, then we should use
6922 // a post-indexed LDR instruction instead, per the ARM ARM.
6923 if (Inst.getNumOperands() != 5)
6926 TmpInst.setOpcode(ARM::t2LDR_POST);
6927 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6928 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6929 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6930 TmpInst.addOperand(MCOperand::CreateImm(4));
6931 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6932 TmpInst.addOperand(Inst.getOperand(3));
6936 case ARM::t2STMDB_UPD: {
6937 // If this is a store of a single register, then we should use
6938 // a pre-indexed STR instruction instead, per the ARM ARM.
6939 if (Inst.getNumOperands() != 5)
6942 TmpInst.setOpcode(ARM::t2STR_PRE);
6943 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6944 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6945 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6946 TmpInst.addOperand(MCOperand::CreateImm(-4));
6947 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6948 TmpInst.addOperand(Inst.getOperand(3));
6952 case ARM::LDMIA_UPD:
6953 // If this is a load of a single register via a 'pop', then we should use
6954 // a post-indexed LDR instruction instead, per the ARM ARM.
6955 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6956 Inst.getNumOperands() == 5) {
6958 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6959 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6960 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6961 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6962 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6963 TmpInst.addOperand(MCOperand::CreateImm(4));
6964 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6965 TmpInst.addOperand(Inst.getOperand(3));
6970 case ARM::STMDB_UPD:
6971 // If this is a store of a single register via a 'push', then we should use
6972 // a pre-indexed STR instruction instead, per the ARM ARM.
6973 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6974 Inst.getNumOperands() == 5) {
6976 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6977 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6978 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6979 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6980 TmpInst.addOperand(MCOperand::CreateImm(-4));
6981 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6982 TmpInst.addOperand(Inst.getOperand(3));
6986 case ARM::t2ADDri12:
6987 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6988 // mnemonic was used (not "addw"), encoding T3 is preferred.
6989 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6990 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6992 Inst.setOpcode(ARM::t2ADDri);
6993 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6995 case ARM::t2SUBri12:
6996 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6997 // mnemonic was used (not "subw"), encoding T3 is preferred.
6998 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6999 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7001 Inst.setOpcode(ARM::t2SUBri);
7002 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7005 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7006 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7007 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7008 // to encoding T1 if <Rd> is omitted."
7009 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7010 Inst.setOpcode(ARM::tADDi3);
7015 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7016 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7017 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7018 // to encoding T1 if <Rd> is omitted."
7019 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7020 Inst.setOpcode(ARM::tSUBi3);
7025 case ARM::t2SUBri: {
7026 // If the destination and first source operand are the same, and
7027 // the flags are compatible with the current IT status, use encoding T2
7028 // instead of T3. For compatibility with the system 'as'. Make sure the
7029 // wide encoding wasn't explicit.
7030 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7031 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7032 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7033 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7034 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7035 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7036 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7039 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7040 ARM::tADDi8 : ARM::tSUBi8);
7041 TmpInst.addOperand(Inst.getOperand(0));
7042 TmpInst.addOperand(Inst.getOperand(5));
7043 TmpInst.addOperand(Inst.getOperand(0));
7044 TmpInst.addOperand(Inst.getOperand(2));
7045 TmpInst.addOperand(Inst.getOperand(3));
7046 TmpInst.addOperand(Inst.getOperand(4));
7050 case ARM::t2ADDrr: {
7051 // If the destination and first source operand are the same, and
7052 // there's no setting of the flags, use encoding T2 instead of T3.
7053 // Note that this is only for ADD, not SUB. This mirrors the system
7054 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7055 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7056 Inst.getOperand(5).getReg() != 0 ||
7057 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7058 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7061 TmpInst.setOpcode(ARM::tADDhirr);
7062 TmpInst.addOperand(Inst.getOperand(0));
7063 TmpInst.addOperand(Inst.getOperand(0));
7064 TmpInst.addOperand(Inst.getOperand(2));
7065 TmpInst.addOperand(Inst.getOperand(3));
7066 TmpInst.addOperand(Inst.getOperand(4));
7070 case ARM::tADDrSP: {
7071 // If the non-SP source operand and the destination operand are not the
7072 // same, we need to use the 32-bit encoding if it's available.
7073 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7074 Inst.setOpcode(ARM::t2ADDrr);
7075 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7081 // A Thumb conditional branch outside of an IT block is a tBcc.
7082 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7083 Inst.setOpcode(ARM::tBcc);
7088 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7089 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7090 Inst.setOpcode(ARM::t2Bcc);
7095 // If the conditional is AL or we're in an IT block, we really want t2B.
7096 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7097 Inst.setOpcode(ARM::t2B);
7102 // If the conditional is AL, we really want tB.
7103 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7104 Inst.setOpcode(ARM::tB);
7109 // If the register list contains any high registers, or if the writeback
7110 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7111 // instead if we're in Thumb2. Otherwise, this should have generated
7112 // an error in validateInstruction().
7113 unsigned Rn = Inst.getOperand(0).getReg();
7114 bool hasWritebackToken =
7115 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7116 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7117 bool listContainsBase;
7118 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7119 (!listContainsBase && !hasWritebackToken) ||
7120 (listContainsBase && hasWritebackToken)) {
7121 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7122 assert (isThumbTwo());
7123 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7124 // If we're switching to the updating version, we need to insert
7125 // the writeback tied operand.
7126 if (hasWritebackToken)
7127 Inst.insert(Inst.begin(),
7128 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7133 case ARM::tSTMIA_UPD: {
7134 // If the register list contains any high registers, we need to use
7135 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7136 // should have generated an error in validateInstruction().
7137 unsigned Rn = Inst.getOperand(0).getReg();
7138 bool listContainsBase;
7139 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7140 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7141 assert (isThumbTwo());
7142 Inst.setOpcode(ARM::t2STMIA_UPD);
7148 bool listContainsBase;
7149 // If the register list contains any high registers, we need to use
7150 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7151 // should have generated an error in validateInstruction().
7152 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7154 assert (isThumbTwo());
7155 Inst.setOpcode(ARM::t2LDMIA_UPD);
7156 // Add the base register and writeback operands.
7157 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7158 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7162 bool listContainsBase;
7163 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7165 assert (isThumbTwo());
7166 Inst.setOpcode(ARM::t2STMDB_UPD);
7167 // Add the base register and writeback operands.
7168 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7169 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7173 // If we can use the 16-bit encoding and the user didn't explicitly
7174 // request the 32-bit variant, transform it here.
7175 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7176 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7177 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7178 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7179 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7180 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7181 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7182 // The operands aren't in the same order for tMOVi8...
7184 TmpInst.setOpcode(ARM::tMOVi8);
7185 TmpInst.addOperand(Inst.getOperand(0));
7186 TmpInst.addOperand(Inst.getOperand(4));
7187 TmpInst.addOperand(Inst.getOperand(1));
7188 TmpInst.addOperand(Inst.getOperand(2));
7189 TmpInst.addOperand(Inst.getOperand(3));
7196 // If we can use the 16-bit encoding and the user didn't explicitly
7197 // request the 32-bit variant, transform it here.
7198 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7199 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7200 Inst.getOperand(2).getImm() == ARMCC::AL &&
7201 Inst.getOperand(4).getReg() == ARM::CPSR &&
7202 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7203 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7204 // The operands aren't the same for tMOV[S]r... (no cc_out)
7206 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7207 TmpInst.addOperand(Inst.getOperand(0));
7208 TmpInst.addOperand(Inst.getOperand(1));
7209 TmpInst.addOperand(Inst.getOperand(2));
7210 TmpInst.addOperand(Inst.getOperand(3));
7220 // If we can use the 16-bit encoding and the user didn't explicitly
7221 // request the 32-bit variant, transform it here.
7222 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7223 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7224 Inst.getOperand(2).getImm() == 0 &&
7225 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7226 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7228 switch (Inst.getOpcode()) {
7229 default: llvm_unreachable("Illegal opcode!");
7230 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7231 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7232 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7233 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7235 // The operands aren't the same for thumb1 (no rotate operand).
7237 TmpInst.setOpcode(NewOpc);
7238 TmpInst.addOperand(Inst.getOperand(0));
7239 TmpInst.addOperand(Inst.getOperand(1));
7240 TmpInst.addOperand(Inst.getOperand(3));
7241 TmpInst.addOperand(Inst.getOperand(4));
7248 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7249 // rrx shifts and asr/lsr of #32 is encoded as 0
7250 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7252 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7253 // Shifting by zero is accepted as a vanilla 'MOVr'
7255 TmpInst.setOpcode(ARM::MOVr);
7256 TmpInst.addOperand(Inst.getOperand(0));
7257 TmpInst.addOperand(Inst.getOperand(1));
7258 TmpInst.addOperand(Inst.getOperand(3));
7259 TmpInst.addOperand(Inst.getOperand(4));
7260 TmpInst.addOperand(Inst.getOperand(5));
7273 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7274 if (SOpc == ARM_AM::rrx) return false;
7275 switch (Inst.getOpcode()) {
7276 default: llvm_unreachable("unexpected opcode!");
7277 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7278 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7279 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7280 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7281 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7282 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7284 // If the shift is by zero, use the non-shifted instruction definition.
7285 // The exception is for right shifts, where 0 == 32
7286 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7287 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7289 TmpInst.setOpcode(newOpc);
7290 TmpInst.addOperand(Inst.getOperand(0));
7291 TmpInst.addOperand(Inst.getOperand(1));
7292 TmpInst.addOperand(Inst.getOperand(2));
7293 TmpInst.addOperand(Inst.getOperand(4));
7294 TmpInst.addOperand(Inst.getOperand(5));
7295 TmpInst.addOperand(Inst.getOperand(6));
7303 // The mask bits for all but the first condition are represented as
7304 // the low bit of the condition code value implies 't'. We currently
7305 // always have 1 implies 't', so XOR toggle the bits if the low bit
7306 // of the condition code is zero.
7307 MCOperand &MO = Inst.getOperand(1);
7308 unsigned Mask = MO.getImm();
7309 unsigned OrigMask = Mask;
7310 unsigned TZ = CountTrailingZeros_32(Mask);
7311 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7312 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7313 for (unsigned i = 3; i != TZ; --i)
7318 // Set up the IT block state according to the IT instruction we just
7320 assert(!inITBlock() && "nested IT blocks?!");
7321 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7322 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7323 ITState.CurPosition = 0;
7324 ITState.FirstCond = true;
7334 // Assemblers should use the narrow encodings of these instructions when permissible.
7335 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7336 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7337 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7338 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7339 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7340 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7341 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7343 switch (Inst.getOpcode()) {
7344 default: llvm_unreachable("unexpected opcode");
7345 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7346 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7347 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7348 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7349 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7350 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7353 TmpInst.setOpcode(NewOpc);
7354 TmpInst.addOperand(Inst.getOperand(0));
7355 TmpInst.addOperand(Inst.getOperand(5));
7356 TmpInst.addOperand(Inst.getOperand(1));
7357 TmpInst.addOperand(Inst.getOperand(2));
7358 TmpInst.addOperand(Inst.getOperand(3));
7359 TmpInst.addOperand(Inst.getOperand(4));
7370 // Assemblers should use the narrow encodings of these instructions when permissible.
7371 // These instructions are special in that they are commutable, so shorter encodings
7372 // are available more often.
7373 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7374 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7375 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7376 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7377 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7378 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7379 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7380 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7382 switch (Inst.getOpcode()) {
7383 default: llvm_unreachable("unexpected opcode");
7384 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7385 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7386 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7387 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7390 TmpInst.setOpcode(NewOpc);
7391 TmpInst.addOperand(Inst.getOperand(0));
7392 TmpInst.addOperand(Inst.getOperand(5));
7393 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7394 TmpInst.addOperand(Inst.getOperand(1));
7395 TmpInst.addOperand(Inst.getOperand(2));
7397 TmpInst.addOperand(Inst.getOperand(2));
7398 TmpInst.addOperand(Inst.getOperand(1));
7400 TmpInst.addOperand(Inst.getOperand(3));
7401 TmpInst.addOperand(Inst.getOperand(4));
7411 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7412 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7413 // suffix depending on whether they're in an IT block or not.
7414 unsigned Opc = Inst.getOpcode();
7415 const MCInstrDesc &MCID = getInstDesc(Opc);
7416 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7417 assert(MCID.hasOptionalDef() &&
7418 "optionally flag setting instruction missing optional def operand");
7419 assert(MCID.NumOperands == Inst.getNumOperands() &&
7420 "operand count mismatch!");
7421 // Find the optional-def operand (cc_out).
7424 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7427 // If we're parsing Thumb1, reject it completely.
7428 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7429 return Match_MnemonicFail;
7430 // If we're parsing Thumb2, which form is legal depends on whether we're
7432 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7434 return Match_RequiresITBlock;
7435 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7437 return Match_RequiresNotITBlock;
7439 // Some high-register supporting Thumb1 encodings only allow both registers
7440 // to be from r0-r7 when in Thumb2.
7441 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7442 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7443 isARMLowRegister(Inst.getOperand(2).getReg()))
7444 return Match_RequiresThumb2;
7445 // Others only require ARMv6 or later.
7446 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7447 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7448 isARMLowRegister(Inst.getOperand(1).getReg()))
7449 return Match_RequiresV6;
7450 return Match_Success;
7453 static const char *getSubtargetFeatureName(unsigned Val);
7455 MatchAndEmitInstruction(SMLoc IDLoc,
7456 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7461 unsigned MatchResult;
7463 MatchResult = MatchInstructionImpl(Operands, Kind, Inst, ErrorInfo);
7464 switch (MatchResult) {
7467 // Context sensitive operand constraints aren't handled by the matcher,
7468 // so check them here.
7469 if (validateInstruction(Inst, Operands)) {
7470 // Still progress the IT block, otherwise one wrong condition causes
7471 // nasty cascading errors.
7472 forwardITPosition();
7476 // Some instructions need post-processing to, for example, tweak which
7477 // encoding is selected. Loop on it while changes happen so the
7478 // individual transformations can chain off each other. E.g.,
7479 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7480 while (processInstruction(Inst, Operands))
7483 // Only move forward at the very end so that everything in validate
7484 // and process gets a consistent answer about whether we're in an IT
7486 forwardITPosition();
7488 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7489 // doesn't actually encode.
7490 if (Inst.getOpcode() == ARM::ITasm)
7494 Out.EmitInstruction(Inst);
7496 case Match_MissingFeature: {
7497 assert(ErrorInfo && "Unknown missing feature!");
7498 // Special case the error message for the very common case where only
7499 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7500 std::string Msg = "instruction requires:";
7502 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7503 if (ErrorInfo & Mask) {
7505 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7509 return Error(IDLoc, Msg);
7511 case Match_InvalidOperand: {
7512 SMLoc ErrorLoc = IDLoc;
7513 if (ErrorInfo != ~0U) {
7514 if (ErrorInfo >= Operands.size())
7515 return Error(IDLoc, "too few operands for instruction");
7517 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7518 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7521 return Error(ErrorLoc, "invalid operand for instruction");
7523 case Match_MnemonicFail:
7524 return Error(IDLoc, "invalid instruction",
7525 ((ARMOperand*)Operands[0])->getLocRange());
7526 case Match_RequiresNotITBlock:
7527 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7528 case Match_RequiresITBlock:
7529 return Error(IDLoc, "instruction only valid inside IT block");
7530 case Match_RequiresV6:
7531 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7532 case Match_RequiresThumb2:
7533 return Error(IDLoc, "instruction variant requires Thumb2");
7534 case Match_ImmRange0_15: {
7535 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7536 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7537 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7541 llvm_unreachable("Implement any new match types added!");
7544 /// parseDirective parses the arm specific directives
7545 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7546 StringRef IDVal = DirectiveID.getIdentifier();
7547 if (IDVal == ".word")
7548 return parseDirectiveWord(4, DirectiveID.getLoc());
7549 else if (IDVal == ".thumb")
7550 return parseDirectiveThumb(DirectiveID.getLoc());
7551 else if (IDVal == ".arm")
7552 return parseDirectiveARM(DirectiveID.getLoc());
7553 else if (IDVal == ".thumb_func")
7554 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7555 else if (IDVal == ".code")
7556 return parseDirectiveCode(DirectiveID.getLoc());
7557 else if (IDVal == ".syntax")
7558 return parseDirectiveSyntax(DirectiveID.getLoc());
7559 else if (IDVal == ".unreq")
7560 return parseDirectiveUnreq(DirectiveID.getLoc());
7561 else if (IDVal == ".arch")
7562 return parseDirectiveArch(DirectiveID.getLoc());
7563 else if (IDVal == ".eabi_attribute")
7564 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7568 /// parseDirectiveWord
7569 /// ::= .word [ expression (, expression)* ]
7570 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7571 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7573 const MCExpr *Value;
7574 if (getParser().ParseExpression(Value))
7577 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
7579 if (getLexer().is(AsmToken::EndOfStatement))
7582 // FIXME: Improve diagnostic.
7583 if (getLexer().isNot(AsmToken::Comma))
7584 return Error(L, "unexpected token in directive");
7593 /// parseDirectiveThumb
7595 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7596 if (getLexer().isNot(AsmToken::EndOfStatement))
7597 return Error(L, "unexpected token in directive");
7602 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7606 /// parseDirectiveARM
7608 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7609 if (getLexer().isNot(AsmToken::EndOfStatement))
7610 return Error(L, "unexpected token in directive");
7615 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7619 /// parseDirectiveThumbFunc
7620 /// ::= .thumbfunc symbol_name
7621 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7622 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7623 bool isMachO = MAI.hasSubsectionsViaSymbols();
7625 bool needFuncName = true;
7627 // Darwin asm has (optionally) function name after .thumb_func direction
7630 const AsmToken &Tok = Parser.getTok();
7631 if (Tok.isNot(AsmToken::EndOfStatement)) {
7632 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7633 return Error(L, "unexpected token in .thumb_func directive");
7634 Name = Tok.getIdentifier();
7635 Parser.Lex(); // Consume the identifier token.
7636 needFuncName = false;
7640 if (getLexer().isNot(AsmToken::EndOfStatement))
7641 return Error(L, "unexpected token in directive");
7643 // Eat the end of statement and any blank lines that follow.
7644 while (getLexer().is(AsmToken::EndOfStatement))
7647 // FIXME: assuming function name will be the line following .thumb_func
7648 // We really should be checking the next symbol definition even if there's
7649 // stuff in between.
7651 Name = Parser.getTok().getIdentifier();
7654 // Mark symbol as a thumb symbol.
7655 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7656 getParser().getStreamer().EmitThumbFunc(Func);
7660 /// parseDirectiveSyntax
7661 /// ::= .syntax unified | divided
7662 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7663 const AsmToken &Tok = Parser.getTok();
7664 if (Tok.isNot(AsmToken::Identifier))
7665 return Error(L, "unexpected token in .syntax directive");
7666 StringRef Mode = Tok.getString();
7667 if (Mode == "unified" || Mode == "UNIFIED")
7669 else if (Mode == "divided" || Mode == "DIVIDED")
7670 return Error(L, "'.syntax divided' arm asssembly not supported");
7672 return Error(L, "unrecognized syntax mode in .syntax directive");
7674 if (getLexer().isNot(AsmToken::EndOfStatement))
7675 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7678 // TODO tell the MC streamer the mode
7679 // getParser().getStreamer().Emit???();
7683 /// parseDirectiveCode
7684 /// ::= .code 16 | 32
7685 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7686 const AsmToken &Tok = Parser.getTok();
7687 if (Tok.isNot(AsmToken::Integer))
7688 return Error(L, "unexpected token in .code directive");
7689 int64_t Val = Parser.getTok().getIntVal();
7695 return Error(L, "invalid operand to .code directive");
7697 if (getLexer().isNot(AsmToken::EndOfStatement))
7698 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7704 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7708 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7714 /// parseDirectiveReq
7715 /// ::= name .req registername
7716 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7717 Parser.Lex(); // Eat the '.req' token.
7719 SMLoc SRegLoc, ERegLoc;
7720 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7721 Parser.EatToEndOfStatement();
7722 return Error(SRegLoc, "register name expected");
7725 // Shouldn't be anything else.
7726 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7727 Parser.EatToEndOfStatement();
7728 return Error(Parser.getTok().getLoc(),
7729 "unexpected input in .req directive.");
7732 Parser.Lex(); // Consume the EndOfStatement
7734 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7735 return Error(SRegLoc, "redefinition of '" + Name +
7736 "' does not match original.");
7741 /// parseDirectiveUneq
7742 /// ::= .unreq registername
7743 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7744 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7745 Parser.EatToEndOfStatement();
7746 return Error(L, "unexpected input in .unreq directive.");
7748 RegisterReqs.erase(Parser.getTok().getIdentifier());
7749 Parser.Lex(); // Eat the identifier.
7753 /// parseDirectiveArch
7755 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7759 /// parseDirectiveEabiAttr
7760 /// ::= .eabi_attribute int, int
7761 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7765 extern "C" void LLVMInitializeARMAsmLexer();
7767 /// Force static initialization.
7768 extern "C" void LLVMInitializeARMAsmParser() {
7769 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7770 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
7771 LLVMInitializeARMAsmLexer();
7774 #define GET_REGISTER_MATCHER
7775 #define GET_SUBTARGET_FEATURE_NAME
7776 #define GET_MATCHER_IMPLEMENTATION
7777 #include "ARMGenAsmMatcher.inc"