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(ParseInstructionInfo &Info, StringRef Name,
258 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
259 bool ParseDirective(AsmToken DirectiveID);
261 unsigned checkTargetMatchPredicate(MCInst &Inst);
263 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
264 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
265 MCStreamer &Out, unsigned &ErrorInfo,
266 bool MatchingInlineAsm);
268 } // end anonymous namespace
272 /// ARMOperand - Instances of this class represent a parsed ARM machine
274 class ARMOperand : public MCParsedAsmOperand {
294 k_VectorListAllLanes,
300 k_BitfieldDescriptor,
304 SMLoc StartLoc, EndLoc;
305 SmallVector<unsigned, 8> Registers;
309 ARMCC::CondCodes Val;
329 ARM_PROC::IFlags Val;
345 // A vector register list is a sequential list of 1 to 4 registers.
361 /// Combined record for all forms of ARM address expressions.
364 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
366 const MCConstantExpr *OffsetImm; // Offset immediate value
367 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
368 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
369 unsigned ShiftImm; // shift for OffsetReg.
370 unsigned Alignment; // 0 = no alignment specified
371 // n = alignment in bytes (2, 4, 8, 16, or 32)
372 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
378 ARM_AM::ShiftOpc ShiftTy;
387 ARM_AM::ShiftOpc ShiftTy;
393 ARM_AM::ShiftOpc ShiftTy;
406 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
408 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
410 StartLoc = o.StartLoc;
427 case k_DPRRegisterList:
428 case k_SPRRegisterList:
429 Registers = o.Registers;
432 case k_VectorListAllLanes:
433 case k_VectorListIndexed:
434 VectorList = o.VectorList;
441 CoprocOption = o.CoprocOption;
446 case k_MemBarrierOpt:
452 case k_PostIndexRegister:
453 PostIdxReg = o.PostIdxReg;
461 case k_ShifterImmediate:
462 ShifterImm = o.ShifterImm;
464 case k_ShiftedRegister:
465 RegShiftedReg = o.RegShiftedReg;
467 case k_ShiftedImmediate:
468 RegShiftedImm = o.RegShiftedImm;
470 case k_RotateImmediate:
473 case k_BitfieldDescriptor:
474 Bitfield = o.Bitfield;
477 VectorIndex = o.VectorIndex;
482 /// getStartLoc - Get the location of the first token of this operand.
483 SMLoc getStartLoc() const { return StartLoc; }
484 /// getEndLoc - Get the location of the last token of this operand.
485 SMLoc getEndLoc() const { return EndLoc; }
486 /// getLocRange - Get the range between the first and last token of this
488 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
490 ARMCC::CondCodes getCondCode() const {
491 assert(Kind == k_CondCode && "Invalid access!");
495 unsigned getCoproc() const {
496 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
500 StringRef getToken() const {
501 assert(Kind == k_Token && "Invalid access!");
502 return StringRef(Tok.Data, Tok.Length);
505 unsigned getReg() const {
506 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
510 const SmallVectorImpl<unsigned> &getRegList() const {
511 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
512 Kind == k_SPRRegisterList) && "Invalid access!");
516 const MCExpr *getImm() const {
517 assert(isImm() && "Invalid access!");
521 unsigned getVectorIndex() const {
522 assert(Kind == k_VectorIndex && "Invalid access!");
523 return VectorIndex.Val;
526 ARM_MB::MemBOpt getMemBarrierOpt() const {
527 assert(Kind == k_MemBarrierOpt && "Invalid access!");
531 ARM_PROC::IFlags getProcIFlags() const {
532 assert(Kind == k_ProcIFlags && "Invalid access!");
536 unsigned getMSRMask() const {
537 assert(Kind == k_MSRMask && "Invalid access!");
541 bool isCoprocNum() const { return Kind == k_CoprocNum; }
542 bool isCoprocReg() const { return Kind == k_CoprocReg; }
543 bool isCoprocOption() const { return Kind == k_CoprocOption; }
544 bool isCondCode() const { return Kind == k_CondCode; }
545 bool isCCOut() const { return Kind == k_CCOut; }
546 bool isITMask() const { return Kind == k_ITCondMask; }
547 bool isITCondCode() const { return Kind == k_CondCode; }
548 bool isImm() const { return Kind == k_Immediate; }
549 bool isFPImm() const {
550 if (!isImm()) return false;
551 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
552 if (!CE) return false;
553 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
556 bool isFBits16() const {
557 if (!isImm()) return false;
558 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
559 if (!CE) return false;
560 int64_t Value = CE->getValue();
561 return Value >= 0 && Value <= 16;
563 bool isFBits32() const {
564 if (!isImm()) return false;
565 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
566 if (!CE) return false;
567 int64_t Value = CE->getValue();
568 return Value >= 1 && Value <= 32;
570 bool isImm8s4() const {
571 if (!isImm()) return false;
572 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
573 if (!CE) return false;
574 int64_t Value = CE->getValue();
575 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
577 bool isImm0_1020s4() const {
578 if (!isImm()) return false;
579 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
580 if (!CE) return false;
581 int64_t Value = CE->getValue();
582 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
584 bool isImm0_508s4() const {
585 if (!isImm()) return false;
586 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
587 if (!CE) return false;
588 int64_t Value = CE->getValue();
589 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
591 bool isImm0_508s4Neg() const {
592 if (!isImm()) return false;
593 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
594 if (!CE) return false;
595 int64_t Value = -CE->getValue();
596 // explicitly exclude zero. we want that to use the normal 0_508 version.
597 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
599 bool isImm0_255() const {
600 if (!isImm()) return false;
601 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
602 if (!CE) return false;
603 int64_t Value = CE->getValue();
604 return Value >= 0 && Value < 256;
606 bool isImm0_4095() const {
607 if (!isImm()) return false;
608 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
609 if (!CE) return false;
610 int64_t Value = CE->getValue();
611 return Value >= 0 && Value < 4096;
613 bool isImm0_4095Neg() const {
614 if (!isImm()) return false;
615 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
616 if (!CE) return false;
617 int64_t Value = -CE->getValue();
618 return Value > 0 && Value < 4096;
620 bool isImm0_1() const {
621 if (!isImm()) return false;
622 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
623 if (!CE) return false;
624 int64_t Value = CE->getValue();
625 return Value >= 0 && Value < 2;
627 bool isImm0_3() const {
628 if (!isImm()) return false;
629 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
630 if (!CE) return false;
631 int64_t Value = CE->getValue();
632 return Value >= 0 && Value < 4;
634 bool isImm0_7() const {
635 if (!isImm()) return false;
636 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
637 if (!CE) return false;
638 int64_t Value = CE->getValue();
639 return Value >= 0 && Value < 8;
641 bool isImm0_15() const {
642 if (!isImm()) return false;
643 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
644 if (!CE) return false;
645 int64_t Value = CE->getValue();
646 return Value >= 0 && Value < 16;
648 bool isImm0_31() const {
649 if (!isImm()) return false;
650 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
651 if (!CE) return false;
652 int64_t Value = CE->getValue();
653 return Value >= 0 && Value < 32;
655 bool isImm0_63() const {
656 if (!isImm()) return false;
657 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
658 if (!CE) return false;
659 int64_t Value = CE->getValue();
660 return Value >= 0 && Value < 64;
662 bool isImm8() const {
663 if (!isImm()) return false;
664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
665 if (!CE) return false;
666 int64_t Value = CE->getValue();
669 bool isImm16() const {
670 if (!isImm()) return false;
671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
672 if (!CE) return false;
673 int64_t Value = CE->getValue();
676 bool isImm32() const {
677 if (!isImm()) return false;
678 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
679 if (!CE) return false;
680 int64_t Value = CE->getValue();
683 bool isShrImm8() const {
684 if (!isImm()) return false;
685 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
686 if (!CE) return false;
687 int64_t Value = CE->getValue();
688 return Value > 0 && Value <= 8;
690 bool isShrImm16() const {
691 if (!isImm()) return false;
692 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
693 if (!CE) return false;
694 int64_t Value = CE->getValue();
695 return Value > 0 && Value <= 16;
697 bool isShrImm32() const {
698 if (!isImm()) return false;
699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
700 if (!CE) return false;
701 int64_t Value = CE->getValue();
702 return Value > 0 && Value <= 32;
704 bool isShrImm64() const {
705 if (!isImm()) return false;
706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
707 if (!CE) return false;
708 int64_t Value = CE->getValue();
709 return Value > 0 && Value <= 64;
711 bool isImm1_7() const {
712 if (!isImm()) return false;
713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
714 if (!CE) return false;
715 int64_t Value = CE->getValue();
716 return Value > 0 && Value < 8;
718 bool isImm1_15() const {
719 if (!isImm()) return false;
720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
721 if (!CE) return false;
722 int64_t Value = CE->getValue();
723 return Value > 0 && Value < 16;
725 bool isImm1_31() const {
726 if (!isImm()) return false;
727 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
728 if (!CE) return false;
729 int64_t Value = CE->getValue();
730 return Value > 0 && Value < 32;
732 bool isImm1_16() const {
733 if (!isImm()) return false;
734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
735 if (!CE) return false;
736 int64_t Value = CE->getValue();
737 return Value > 0 && Value < 17;
739 bool isImm1_32() const {
740 if (!isImm()) return false;
741 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
742 if (!CE) return false;
743 int64_t Value = CE->getValue();
744 return Value > 0 && Value < 33;
746 bool isImm0_32() const {
747 if (!isImm()) return false;
748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
749 if (!CE) return false;
750 int64_t Value = CE->getValue();
751 return Value >= 0 && Value < 33;
753 bool isImm0_65535() const {
754 if (!isImm()) return false;
755 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
756 if (!CE) return false;
757 int64_t Value = CE->getValue();
758 return Value >= 0 && Value < 65536;
760 bool isImm0_65535Expr() const {
761 if (!isImm()) return false;
762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
763 // If it's not a constant expression, it'll generate a fixup and be
765 if (!CE) return true;
766 int64_t Value = CE->getValue();
767 return Value >= 0 && Value < 65536;
769 bool isImm24bit() const {
770 if (!isImm()) return false;
771 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
772 if (!CE) return false;
773 int64_t Value = CE->getValue();
774 return Value >= 0 && Value <= 0xffffff;
776 bool isImmThumbSR() const {
777 if (!isImm()) return false;
778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
779 if (!CE) return false;
780 int64_t Value = CE->getValue();
781 return Value > 0 && Value < 33;
783 bool isPKHLSLImm() const {
784 if (!isImm()) return false;
785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
786 if (!CE) return false;
787 int64_t Value = CE->getValue();
788 return Value >= 0 && Value < 32;
790 bool isPKHASRImm() const {
791 if (!isImm()) return false;
792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
793 if (!CE) return false;
794 int64_t Value = CE->getValue();
795 return Value > 0 && Value <= 32;
797 bool isAdrLabel() const {
798 // If we have an immediate that's not a constant, treat it as a label
799 // reference needing a fixup. If it is a constant, but it can't fit
800 // into shift immediate encoding, we reject it.
801 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
802 else return (isARMSOImm() || isARMSOImmNeg());
804 bool isARMSOImm() const {
805 if (!isImm()) return false;
806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
807 if (!CE) return false;
808 int64_t Value = CE->getValue();
809 return ARM_AM::getSOImmVal(Value) != -1;
811 bool isARMSOImmNot() const {
812 if (!isImm()) return false;
813 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
814 if (!CE) return false;
815 int64_t Value = CE->getValue();
816 return ARM_AM::getSOImmVal(~Value) != -1;
818 bool isARMSOImmNeg() const {
819 if (!isImm()) return false;
820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
821 if (!CE) return false;
822 int64_t Value = CE->getValue();
823 // Only use this when not representable as a plain so_imm.
824 return ARM_AM::getSOImmVal(Value) == -1 &&
825 ARM_AM::getSOImmVal(-Value) != -1;
827 bool isT2SOImm() const {
828 if (!isImm()) return false;
829 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
830 if (!CE) return false;
831 int64_t Value = CE->getValue();
832 return ARM_AM::getT2SOImmVal(Value) != -1;
834 bool isT2SOImmNot() const {
835 if (!isImm()) return false;
836 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
837 if (!CE) return false;
838 int64_t Value = CE->getValue();
839 return ARM_AM::getT2SOImmVal(~Value) != -1;
841 bool isT2SOImmNeg() const {
842 if (!isImm()) return false;
843 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
844 if (!CE) return false;
845 int64_t Value = CE->getValue();
846 // Only use this when not representable as a plain so_imm.
847 return ARM_AM::getT2SOImmVal(Value) == -1 &&
848 ARM_AM::getT2SOImmVal(-Value) != -1;
850 bool isSetEndImm() const {
851 if (!isImm()) return false;
852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
853 if (!CE) return false;
854 int64_t Value = CE->getValue();
855 return Value == 1 || Value == 0;
857 bool isReg() const { return Kind == k_Register; }
858 bool isRegList() const { return Kind == k_RegisterList; }
859 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
860 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
861 bool isToken() const { return Kind == k_Token; }
862 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
863 bool isMem() const { return Kind == k_Memory; }
864 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
865 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
866 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
867 bool isRotImm() const { return Kind == k_RotateImmediate; }
868 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
869 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
870 bool isPostIdxReg() const {
871 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
873 bool isMemNoOffset(bool alignOK = false) const {
876 // No offset of any kind.
877 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
878 (alignOK || Memory.Alignment == 0);
880 bool isMemPCRelImm12() const {
881 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
883 // Base register must be PC.
884 if (Memory.BaseRegNum != ARM::PC)
886 // Immediate offset in range [-4095, 4095].
887 if (!Memory.OffsetImm) return true;
888 int64_t Val = Memory.OffsetImm->getValue();
889 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
891 bool isAlignedMemory() const {
892 return isMemNoOffset(true);
894 bool isAddrMode2() const {
895 if (!isMem() || Memory.Alignment != 0) return false;
896 // Check for register offset.
897 if (Memory.OffsetRegNum) return true;
898 // Immediate offset in range [-4095, 4095].
899 if (!Memory.OffsetImm) return true;
900 int64_t Val = Memory.OffsetImm->getValue();
901 return Val > -4096 && Val < 4096;
903 bool isAM2OffsetImm() const {
904 if (!isImm()) return false;
905 // Immediate offset in range [-4095, 4095].
906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
907 if (!CE) return false;
908 int64_t Val = CE->getValue();
909 return Val > -4096 && Val < 4096;
911 bool isAddrMode3() const {
912 // If we have an immediate that's not a constant, treat it as a label
913 // reference needing a fixup. If it is a constant, it's something else
915 if (isImm() && !isa<MCConstantExpr>(getImm()))
917 if (!isMem() || Memory.Alignment != 0) return false;
918 // No shifts are legal for AM3.
919 if (Memory.ShiftType != ARM_AM::no_shift) return false;
920 // Check for register offset.
921 if (Memory.OffsetRegNum) return true;
922 // Immediate offset in range [-255, 255].
923 if (!Memory.OffsetImm) return true;
924 int64_t Val = Memory.OffsetImm->getValue();
925 // The #-0 offset is encoded as INT32_MIN, and we have to check
927 return (Val > -256 && Val < 256) || Val == INT32_MIN;
929 bool isAM3Offset() const {
930 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
932 if (Kind == k_PostIndexRegister)
933 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
934 // Immediate offset in range [-255, 255].
935 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
936 if (!CE) return false;
937 int64_t Val = CE->getValue();
938 // Special case, #-0 is INT32_MIN.
939 return (Val > -256 && Val < 256) || Val == INT32_MIN;
941 bool isAddrMode5() const {
942 // If we have an immediate that's not a constant, treat it as a label
943 // reference needing a fixup. If it is a constant, it's something else
945 if (isImm() && !isa<MCConstantExpr>(getImm()))
947 if (!isMem() || Memory.Alignment != 0) return false;
948 // Check for register offset.
949 if (Memory.OffsetRegNum) return false;
950 // Immediate offset in range [-1020, 1020] and a multiple of 4.
951 if (!Memory.OffsetImm) return true;
952 int64_t Val = Memory.OffsetImm->getValue();
953 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
956 bool isMemTBB() const {
957 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
958 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
962 bool isMemTBH() const {
963 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
964 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
965 Memory.Alignment != 0 )
969 bool isMemRegOffset() const {
970 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
974 bool isT2MemRegOffset() const {
975 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
976 Memory.Alignment != 0)
978 // Only lsl #{0, 1, 2, 3} allowed.
979 if (Memory.ShiftType == ARM_AM::no_shift)
981 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
985 bool isMemThumbRR() const {
986 // Thumb reg+reg addressing is simple. Just two registers, a base and
987 // an offset. No shifts, negations or any other complicating factors.
988 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
989 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
991 return isARMLowRegister(Memory.BaseRegNum) &&
992 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
994 bool isMemThumbRIs4() const {
995 if (!isMem() || Memory.OffsetRegNum != 0 ||
996 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
998 // Immediate offset, multiple of 4 in range [0, 124].
999 if (!Memory.OffsetImm) return true;
1000 int64_t Val = Memory.OffsetImm->getValue();
1001 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1003 bool isMemThumbRIs2() const {
1004 if (!isMem() || Memory.OffsetRegNum != 0 ||
1005 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1007 // Immediate offset, multiple of 4 in range [0, 62].
1008 if (!Memory.OffsetImm) return true;
1009 int64_t Val = Memory.OffsetImm->getValue();
1010 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1012 bool isMemThumbRIs1() const {
1013 if (!isMem() || Memory.OffsetRegNum != 0 ||
1014 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1016 // Immediate offset in range [0, 31].
1017 if (!Memory.OffsetImm) return true;
1018 int64_t Val = Memory.OffsetImm->getValue();
1019 return Val >= 0 && Val <= 31;
1021 bool isMemThumbSPI() const {
1022 if (!isMem() || Memory.OffsetRegNum != 0 ||
1023 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1025 // Immediate offset, multiple of 4 in range [0, 1020].
1026 if (!Memory.OffsetImm) return true;
1027 int64_t Val = Memory.OffsetImm->getValue();
1028 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1030 bool isMemImm8s4Offset() const {
1031 // If we have an immediate that's not a constant, treat it as a label
1032 // reference needing a fixup. If it is a constant, it's something else
1033 // and we reject it.
1034 if (isImm() && !isa<MCConstantExpr>(getImm()))
1036 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1038 // Immediate offset a multiple of 4 in range [-1020, 1020].
1039 if (!Memory.OffsetImm) return true;
1040 int64_t Val = Memory.OffsetImm->getValue();
1041 // Special case, #-0 is INT32_MIN.
1042 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1044 bool isMemImm0_1020s4Offset() const {
1045 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1047 // Immediate offset a multiple of 4 in range [0, 1020].
1048 if (!Memory.OffsetImm) return true;
1049 int64_t Val = Memory.OffsetImm->getValue();
1050 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1052 bool isMemImm8Offset() const {
1053 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1055 // Base reg of PC isn't allowed for these encodings.
1056 if (Memory.BaseRegNum == ARM::PC) return false;
1057 // Immediate offset in range [-255, 255].
1058 if (!Memory.OffsetImm) return true;
1059 int64_t Val = Memory.OffsetImm->getValue();
1060 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1062 bool isMemPosImm8Offset() const {
1063 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1065 // Immediate offset in range [0, 255].
1066 if (!Memory.OffsetImm) return true;
1067 int64_t Val = Memory.OffsetImm->getValue();
1068 return Val >= 0 && Val < 256;
1070 bool isMemNegImm8Offset() const {
1071 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1073 // Base reg of PC isn't allowed for these encodings.
1074 if (Memory.BaseRegNum == ARM::PC) return false;
1075 // Immediate offset in range [-255, -1].
1076 if (!Memory.OffsetImm) return false;
1077 int64_t Val = Memory.OffsetImm->getValue();
1078 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1080 bool isMemUImm12Offset() const {
1081 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1083 // Immediate offset in range [0, 4095].
1084 if (!Memory.OffsetImm) return true;
1085 int64_t Val = Memory.OffsetImm->getValue();
1086 return (Val >= 0 && Val < 4096);
1088 bool isMemImm12Offset() const {
1089 // If we have an immediate that's not a constant, treat it as a label
1090 // reference needing a fixup. If it is a constant, it's something else
1091 // and we reject it.
1092 if (isImm() && !isa<MCConstantExpr>(getImm()))
1095 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1097 // Immediate offset in range [-4095, 4095].
1098 if (!Memory.OffsetImm) return true;
1099 int64_t Val = Memory.OffsetImm->getValue();
1100 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1102 bool isPostIdxImm8() const {
1103 if (!isImm()) return false;
1104 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1105 if (!CE) return false;
1106 int64_t Val = CE->getValue();
1107 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1109 bool isPostIdxImm8s4() const {
1110 if (!isImm()) return false;
1111 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1112 if (!CE) return false;
1113 int64_t Val = CE->getValue();
1114 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1118 bool isMSRMask() const { return Kind == k_MSRMask; }
1119 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1122 bool isSingleSpacedVectorList() const {
1123 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1125 bool isDoubleSpacedVectorList() const {
1126 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1128 bool isVecListOneD() const {
1129 if (!isSingleSpacedVectorList()) return false;
1130 return VectorList.Count == 1;
1133 bool isVecListDPair() const {
1134 if (!isSingleSpacedVectorList()) return false;
1135 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1136 .contains(VectorList.RegNum));
1139 bool isVecListThreeD() const {
1140 if (!isSingleSpacedVectorList()) return false;
1141 return VectorList.Count == 3;
1144 bool isVecListFourD() const {
1145 if (!isSingleSpacedVectorList()) return false;
1146 return VectorList.Count == 4;
1149 bool isVecListDPairSpaced() const {
1150 if (isSingleSpacedVectorList()) return false;
1151 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1152 .contains(VectorList.RegNum));
1155 bool isVecListThreeQ() const {
1156 if (!isDoubleSpacedVectorList()) return false;
1157 return VectorList.Count == 3;
1160 bool isVecListFourQ() const {
1161 if (!isDoubleSpacedVectorList()) return false;
1162 return VectorList.Count == 4;
1165 bool isSingleSpacedVectorAllLanes() const {
1166 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1168 bool isDoubleSpacedVectorAllLanes() const {
1169 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1171 bool isVecListOneDAllLanes() const {
1172 if (!isSingleSpacedVectorAllLanes()) return false;
1173 return VectorList.Count == 1;
1176 bool isVecListDPairAllLanes() const {
1177 if (!isSingleSpacedVectorAllLanes()) return false;
1178 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1179 .contains(VectorList.RegNum));
1182 bool isVecListDPairSpacedAllLanes() const {
1183 if (!isDoubleSpacedVectorAllLanes()) return false;
1184 return VectorList.Count == 2;
1187 bool isVecListThreeDAllLanes() const {
1188 if (!isSingleSpacedVectorAllLanes()) return false;
1189 return VectorList.Count == 3;
1192 bool isVecListThreeQAllLanes() const {
1193 if (!isDoubleSpacedVectorAllLanes()) return false;
1194 return VectorList.Count == 3;
1197 bool isVecListFourDAllLanes() const {
1198 if (!isSingleSpacedVectorAllLanes()) return false;
1199 return VectorList.Count == 4;
1202 bool isVecListFourQAllLanes() const {
1203 if (!isDoubleSpacedVectorAllLanes()) return false;
1204 return VectorList.Count == 4;
1207 bool isSingleSpacedVectorIndexed() const {
1208 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1210 bool isDoubleSpacedVectorIndexed() const {
1211 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1213 bool isVecListOneDByteIndexed() const {
1214 if (!isSingleSpacedVectorIndexed()) return false;
1215 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1218 bool isVecListOneDHWordIndexed() const {
1219 if (!isSingleSpacedVectorIndexed()) return false;
1220 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1223 bool isVecListOneDWordIndexed() const {
1224 if (!isSingleSpacedVectorIndexed()) return false;
1225 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1228 bool isVecListTwoDByteIndexed() const {
1229 if (!isSingleSpacedVectorIndexed()) return false;
1230 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1233 bool isVecListTwoDHWordIndexed() const {
1234 if (!isSingleSpacedVectorIndexed()) return false;
1235 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1238 bool isVecListTwoQWordIndexed() const {
1239 if (!isDoubleSpacedVectorIndexed()) return false;
1240 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1243 bool isVecListTwoQHWordIndexed() const {
1244 if (!isDoubleSpacedVectorIndexed()) return false;
1245 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1248 bool isVecListTwoDWordIndexed() const {
1249 if (!isSingleSpacedVectorIndexed()) return false;
1250 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1253 bool isVecListThreeDByteIndexed() const {
1254 if (!isSingleSpacedVectorIndexed()) return false;
1255 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1258 bool isVecListThreeDHWordIndexed() const {
1259 if (!isSingleSpacedVectorIndexed()) return false;
1260 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1263 bool isVecListThreeQWordIndexed() const {
1264 if (!isDoubleSpacedVectorIndexed()) return false;
1265 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1268 bool isVecListThreeQHWordIndexed() const {
1269 if (!isDoubleSpacedVectorIndexed()) return false;
1270 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1273 bool isVecListThreeDWordIndexed() const {
1274 if (!isSingleSpacedVectorIndexed()) return false;
1275 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1278 bool isVecListFourDByteIndexed() const {
1279 if (!isSingleSpacedVectorIndexed()) return false;
1280 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1283 bool isVecListFourDHWordIndexed() const {
1284 if (!isSingleSpacedVectorIndexed()) return false;
1285 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1288 bool isVecListFourQWordIndexed() const {
1289 if (!isDoubleSpacedVectorIndexed()) return false;
1290 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1293 bool isVecListFourQHWordIndexed() const {
1294 if (!isDoubleSpacedVectorIndexed()) return false;
1295 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1298 bool isVecListFourDWordIndexed() const {
1299 if (!isSingleSpacedVectorIndexed()) return false;
1300 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1303 bool isVectorIndex8() const {
1304 if (Kind != k_VectorIndex) return false;
1305 return VectorIndex.Val < 8;
1307 bool isVectorIndex16() const {
1308 if (Kind != k_VectorIndex) return false;
1309 return VectorIndex.Val < 4;
1311 bool isVectorIndex32() const {
1312 if (Kind != k_VectorIndex) return false;
1313 return VectorIndex.Val < 2;
1316 bool isNEONi8splat() const {
1317 if (!isImm()) return false;
1318 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1319 // Must be a constant.
1320 if (!CE) return false;
1321 int64_t Value = CE->getValue();
1322 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1324 return Value >= 0 && Value < 256;
1327 bool isNEONi16splat() const {
1328 if (!isImm()) return false;
1329 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1330 // Must be a constant.
1331 if (!CE) return false;
1332 int64_t Value = CE->getValue();
1333 // i16 value in the range [0,255] or [0x0100, 0xff00]
1334 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1337 bool isNEONi32splat() const {
1338 if (!isImm()) return false;
1339 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1340 // Must be a constant.
1341 if (!CE) return false;
1342 int64_t Value = CE->getValue();
1343 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1344 return (Value >= 0 && Value < 256) ||
1345 (Value >= 0x0100 && Value <= 0xff00) ||
1346 (Value >= 0x010000 && Value <= 0xff0000) ||
1347 (Value >= 0x01000000 && Value <= 0xff000000);
1350 bool isNEONi32vmov() const {
1351 if (!isImm()) return false;
1352 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1353 // Must be a constant.
1354 if (!CE) return false;
1355 int64_t Value = CE->getValue();
1356 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1357 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1358 return (Value >= 0 && Value < 256) ||
1359 (Value >= 0x0100 && Value <= 0xff00) ||
1360 (Value >= 0x010000 && Value <= 0xff0000) ||
1361 (Value >= 0x01000000 && Value <= 0xff000000) ||
1362 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1363 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1365 bool isNEONi32vmovNeg() const {
1366 if (!isImm()) return false;
1367 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1368 // Must be a constant.
1369 if (!CE) return false;
1370 int64_t Value = ~CE->getValue();
1371 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1372 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1373 return (Value >= 0 && Value < 256) ||
1374 (Value >= 0x0100 && Value <= 0xff00) ||
1375 (Value >= 0x010000 && Value <= 0xff0000) ||
1376 (Value >= 0x01000000 && Value <= 0xff000000) ||
1377 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1378 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1381 bool isNEONi64splat() const {
1382 if (!isImm()) return false;
1383 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1384 // Must be a constant.
1385 if (!CE) return false;
1386 uint64_t Value = CE->getValue();
1387 // i64 value with each byte being either 0 or 0xff.
1388 for (unsigned i = 0; i < 8; ++i)
1389 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1393 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1394 // Add as immediates when possible. Null MCExpr = 0.
1396 Inst.addOperand(MCOperand::CreateImm(0));
1397 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1398 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1400 Inst.addOperand(MCOperand::CreateExpr(Expr));
1403 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1404 assert(N == 2 && "Invalid number of operands!");
1405 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1406 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1407 Inst.addOperand(MCOperand::CreateReg(RegNum));
1410 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1411 assert(N == 1 && "Invalid number of operands!");
1412 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1415 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1416 assert(N == 1 && "Invalid number of operands!");
1417 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1420 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1421 assert(N == 1 && "Invalid number of operands!");
1422 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1425 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1426 assert(N == 1 && "Invalid number of operands!");
1427 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1430 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1431 assert(N == 1 && "Invalid number of operands!");
1432 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1435 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1436 assert(N == 1 && "Invalid number of operands!");
1437 Inst.addOperand(MCOperand::CreateReg(getReg()));
1440 void addRegOperands(MCInst &Inst, unsigned N) const {
1441 assert(N == 1 && "Invalid number of operands!");
1442 Inst.addOperand(MCOperand::CreateReg(getReg()));
1445 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1446 assert(N == 3 && "Invalid number of operands!");
1447 assert(isRegShiftedReg() &&
1448 "addRegShiftedRegOperands() on non RegShiftedReg!");
1449 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1450 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1451 Inst.addOperand(MCOperand::CreateImm(
1452 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1455 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1456 assert(N == 2 && "Invalid number of operands!");
1457 assert(isRegShiftedImm() &&
1458 "addRegShiftedImmOperands() on non RegShiftedImm!");
1459 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1460 // Shift of #32 is encoded as 0 where permitted
1461 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1462 Inst.addOperand(MCOperand::CreateImm(
1463 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1466 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1467 assert(N == 1 && "Invalid number of operands!");
1468 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1472 void addRegListOperands(MCInst &Inst, unsigned N) const {
1473 assert(N == 1 && "Invalid number of operands!");
1474 const SmallVectorImpl<unsigned> &RegList = getRegList();
1475 for (SmallVectorImpl<unsigned>::const_iterator
1476 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1477 Inst.addOperand(MCOperand::CreateReg(*I));
1480 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1481 addRegListOperands(Inst, N);
1484 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1485 addRegListOperands(Inst, N);
1488 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1489 assert(N == 1 && "Invalid number of operands!");
1490 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1491 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1494 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1495 assert(N == 1 && "Invalid number of operands!");
1496 // Munge the lsb/width into a bitfield mask.
1497 unsigned lsb = Bitfield.LSB;
1498 unsigned width = Bitfield.Width;
1499 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1500 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1501 (32 - (lsb + width)));
1502 Inst.addOperand(MCOperand::CreateImm(Mask));
1505 void addImmOperands(MCInst &Inst, unsigned N) const {
1506 assert(N == 1 && "Invalid number of operands!");
1507 addExpr(Inst, getImm());
1510 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1511 assert(N == 1 && "Invalid number of operands!");
1512 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1513 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1516 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1517 assert(N == 1 && "Invalid number of operands!");
1518 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1519 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1522 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1523 assert(N == 1 && "Invalid number of operands!");
1524 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1525 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1526 Inst.addOperand(MCOperand::CreateImm(Val));
1529 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1530 assert(N == 1 && "Invalid number of operands!");
1531 // FIXME: We really want to scale the value here, but the LDRD/STRD
1532 // instruction don't encode operands that way yet.
1533 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1534 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1537 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1538 assert(N == 1 && "Invalid number of operands!");
1539 // The immediate is scaled by four in the encoding and is stored
1540 // in the MCInst as such. Lop off the low two bits here.
1541 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1542 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1545 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1546 assert(N == 1 && "Invalid number of operands!");
1547 // The immediate is scaled by four in the encoding and is stored
1548 // in the MCInst as such. Lop off the low two bits here.
1549 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1550 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1553 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 // The immediate is scaled by four in the encoding and is stored
1556 // in the MCInst as such. Lop off the low two bits here.
1557 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1558 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1561 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1562 assert(N == 1 && "Invalid number of operands!");
1563 // The constant encodes as the immediate-1, and we store in the instruction
1564 // the bits as encoded, so subtract off one here.
1565 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1566 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1569 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1570 assert(N == 1 && "Invalid number of operands!");
1571 // The constant encodes as the immediate-1, and we store in the instruction
1572 // the bits as encoded, so subtract off one here.
1573 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1574 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1577 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1578 assert(N == 1 && "Invalid number of operands!");
1579 // The constant encodes as the immediate, except for 32, which encodes as
1581 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1582 unsigned Imm = CE->getValue();
1583 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1586 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1587 assert(N == 1 && "Invalid number of operands!");
1588 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1589 // the instruction as well.
1590 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1591 int Val = CE->getValue();
1592 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1595 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1596 assert(N == 1 && "Invalid number of operands!");
1597 // The operand is actually a t2_so_imm, but we have its bitwise
1598 // negation in the assembly source, so twiddle it here.
1599 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1600 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1603 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1604 assert(N == 1 && "Invalid number of operands!");
1605 // The operand is actually a t2_so_imm, but we have its
1606 // negation in the assembly source, so twiddle it here.
1607 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1608 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1611 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1612 assert(N == 1 && "Invalid number of operands!");
1613 // The operand is actually an imm0_4095, but we have its
1614 // negation in the assembly source, so twiddle it here.
1615 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1616 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1619 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1620 assert(N == 1 && "Invalid number of operands!");
1621 // The operand is actually a so_imm, but we have its bitwise
1622 // negation in the assembly source, so twiddle it here.
1623 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1624 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1627 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1628 assert(N == 1 && "Invalid number of operands!");
1629 // The operand is actually a so_imm, but we have its
1630 // negation in the assembly source, so twiddle it here.
1631 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1632 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1635 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1636 assert(N == 1 && "Invalid number of operands!");
1637 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1640 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1641 assert(N == 1 && "Invalid number of operands!");
1642 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1645 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1646 assert(N == 1 && "Invalid number of operands!");
1647 int32_t Imm = Memory.OffsetImm->getValue();
1648 // FIXME: Handle #-0
1649 if (Imm == INT32_MIN) Imm = 0;
1650 Inst.addOperand(MCOperand::CreateImm(Imm));
1653 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1654 assert(N == 1 && "Invalid number of operands!");
1655 assert(isImm() && "Not an immediate!");
1657 // If we have an immediate that's not a constant, treat it as a label
1658 // reference needing a fixup.
1659 if (!isa<MCConstantExpr>(getImm())) {
1660 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1665 int Val = CE->getValue();
1666 Inst.addOperand(MCOperand::CreateImm(Val));
1669 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1670 assert(N == 2 && "Invalid number of operands!");
1671 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1672 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1675 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1676 assert(N == 3 && "Invalid number of operands!");
1677 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1678 if (!Memory.OffsetRegNum) {
1679 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1680 // Special case for #-0
1681 if (Val == INT32_MIN) Val = 0;
1682 if (Val < 0) Val = -Val;
1683 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1685 // For register offset, we encode the shift type and negation flag
1687 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1688 Memory.ShiftImm, Memory.ShiftType);
1690 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1691 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1692 Inst.addOperand(MCOperand::CreateImm(Val));
1695 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1696 assert(N == 2 && "Invalid number of operands!");
1697 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1698 assert(CE && "non-constant AM2OffsetImm operand!");
1699 int32_t Val = CE->getValue();
1700 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1701 // Special case for #-0
1702 if (Val == INT32_MIN) Val = 0;
1703 if (Val < 0) Val = -Val;
1704 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1705 Inst.addOperand(MCOperand::CreateReg(0));
1706 Inst.addOperand(MCOperand::CreateImm(Val));
1709 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1710 assert(N == 3 && "Invalid number of operands!");
1711 // If we have an immediate that's not a constant, treat it as a label
1712 // reference needing a fixup. If it is a constant, it's something else
1713 // and we reject it.
1715 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1716 Inst.addOperand(MCOperand::CreateReg(0));
1717 Inst.addOperand(MCOperand::CreateImm(0));
1721 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1722 if (!Memory.OffsetRegNum) {
1723 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1724 // Special case for #-0
1725 if (Val == INT32_MIN) Val = 0;
1726 if (Val < 0) Val = -Val;
1727 Val = ARM_AM::getAM3Opc(AddSub, Val);
1729 // For register offset, we encode the shift type and negation flag
1731 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1733 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1734 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1735 Inst.addOperand(MCOperand::CreateImm(Val));
1738 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1739 assert(N == 2 && "Invalid number of operands!");
1740 if (Kind == k_PostIndexRegister) {
1742 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1743 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1744 Inst.addOperand(MCOperand::CreateImm(Val));
1749 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1750 int32_t Val = CE->getValue();
1751 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1752 // Special case for #-0
1753 if (Val == INT32_MIN) Val = 0;
1754 if (Val < 0) Val = -Val;
1755 Val = ARM_AM::getAM3Opc(AddSub, Val);
1756 Inst.addOperand(MCOperand::CreateReg(0));
1757 Inst.addOperand(MCOperand::CreateImm(Val));
1760 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1761 assert(N == 2 && "Invalid number of operands!");
1762 // If we have an immediate that's not a constant, treat it as a label
1763 // reference needing a fixup. If it is a constant, it's something else
1764 // and we reject it.
1766 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1767 Inst.addOperand(MCOperand::CreateImm(0));
1771 // The lower two bits are always zero and as such are not encoded.
1772 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1773 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1774 // Special case for #-0
1775 if (Val == INT32_MIN) Val = 0;
1776 if (Val < 0) Val = -Val;
1777 Val = ARM_AM::getAM5Opc(AddSub, Val);
1778 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1779 Inst.addOperand(MCOperand::CreateImm(Val));
1782 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1783 assert(N == 2 && "Invalid number of operands!");
1784 // If we have an immediate that's not a constant, treat it as a label
1785 // reference needing a fixup. If it is a constant, it's something else
1786 // and we reject it.
1788 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1789 Inst.addOperand(MCOperand::CreateImm(0));
1793 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1794 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1795 Inst.addOperand(MCOperand::CreateImm(Val));
1798 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1799 assert(N == 2 && "Invalid number of operands!");
1800 // The lower two bits are always zero and as such are not encoded.
1801 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1802 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1803 Inst.addOperand(MCOperand::CreateImm(Val));
1806 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1807 assert(N == 2 && "Invalid number of operands!");
1808 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1809 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1810 Inst.addOperand(MCOperand::CreateImm(Val));
1813 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1814 addMemImm8OffsetOperands(Inst, N);
1817 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1818 addMemImm8OffsetOperands(Inst, N);
1821 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1822 assert(N == 2 && "Invalid number of operands!");
1823 // If this is an immediate, it's a label reference.
1825 addExpr(Inst, getImm());
1826 Inst.addOperand(MCOperand::CreateImm(0));
1830 // Otherwise, it's a normal memory reg+offset.
1831 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1832 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1833 Inst.addOperand(MCOperand::CreateImm(Val));
1836 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1837 assert(N == 2 && "Invalid number of operands!");
1838 // If this is an immediate, it's a label reference.
1840 addExpr(Inst, getImm());
1841 Inst.addOperand(MCOperand::CreateImm(0));
1845 // Otherwise, it's a normal memory reg+offset.
1846 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1847 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1848 Inst.addOperand(MCOperand::CreateImm(Val));
1851 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1852 assert(N == 2 && "Invalid number of operands!");
1853 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1854 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1857 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1858 assert(N == 2 && "Invalid number of operands!");
1859 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1860 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1863 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1864 assert(N == 3 && "Invalid number of operands!");
1866 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1867 Memory.ShiftImm, Memory.ShiftType);
1868 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1869 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1870 Inst.addOperand(MCOperand::CreateImm(Val));
1873 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1874 assert(N == 3 && "Invalid number of operands!");
1875 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1876 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1877 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
1880 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1881 assert(N == 2 && "Invalid number of operands!");
1882 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1883 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1886 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1887 assert(N == 2 && "Invalid number of operands!");
1888 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1889 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1890 Inst.addOperand(MCOperand::CreateImm(Val));
1893 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1894 assert(N == 2 && "Invalid number of operands!");
1895 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1896 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1897 Inst.addOperand(MCOperand::CreateImm(Val));
1900 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1901 assert(N == 2 && "Invalid number of operands!");
1902 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1903 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1904 Inst.addOperand(MCOperand::CreateImm(Val));
1907 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1908 assert(N == 2 && "Invalid number of operands!");
1909 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1910 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1911 Inst.addOperand(MCOperand::CreateImm(Val));
1914 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1915 assert(N == 1 && "Invalid number of operands!");
1916 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1917 assert(CE && "non-constant post-idx-imm8 operand!");
1918 int Imm = CE->getValue();
1919 bool isAdd = Imm >= 0;
1920 if (Imm == INT32_MIN) Imm = 0;
1921 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1922 Inst.addOperand(MCOperand::CreateImm(Imm));
1925 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1926 assert(N == 1 && "Invalid number of operands!");
1927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1928 assert(CE && "non-constant post-idx-imm8s4 operand!");
1929 int Imm = CE->getValue();
1930 bool isAdd = Imm >= 0;
1931 if (Imm == INT32_MIN) Imm = 0;
1932 // Immediate is scaled by 4.
1933 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1934 Inst.addOperand(MCOperand::CreateImm(Imm));
1937 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1938 assert(N == 2 && "Invalid number of operands!");
1939 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1940 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1943 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1944 assert(N == 2 && "Invalid number of operands!");
1945 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1946 // The sign, shift type, and shift amount are encoded in a single operand
1947 // using the AM2 encoding helpers.
1948 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1949 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1950 PostIdxReg.ShiftTy);
1951 Inst.addOperand(MCOperand::CreateImm(Imm));
1954 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1955 assert(N == 1 && "Invalid number of operands!");
1956 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1959 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1960 assert(N == 1 && "Invalid number of operands!");
1961 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1964 void addVecListOperands(MCInst &Inst, unsigned N) const {
1965 assert(N == 1 && "Invalid number of operands!");
1966 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1969 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1970 assert(N == 2 && "Invalid number of operands!");
1971 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1972 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1975 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1976 assert(N == 1 && "Invalid number of operands!");
1977 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1980 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1981 assert(N == 1 && "Invalid number of operands!");
1982 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1985 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1986 assert(N == 1 && "Invalid number of operands!");
1987 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1990 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1991 assert(N == 1 && "Invalid number of operands!");
1992 // The immediate encodes the type of constant as well as the value.
1993 // Mask in that this is an i8 splat.
1994 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1995 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1998 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1999 assert(N == 1 && "Invalid number of operands!");
2000 // The immediate encodes the type of constant as well as the value.
2001 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2002 unsigned Value = CE->getValue();
2004 Value = (Value >> 8) | 0xa00;
2007 Inst.addOperand(MCOperand::CreateImm(Value));
2010 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2011 assert(N == 1 && "Invalid number of operands!");
2012 // The immediate encodes the type of constant as well as the value.
2013 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2014 unsigned Value = CE->getValue();
2015 if (Value >= 256 && Value <= 0xff00)
2016 Value = (Value >> 8) | 0x200;
2017 else if (Value > 0xffff && Value <= 0xff0000)
2018 Value = (Value >> 16) | 0x400;
2019 else if (Value > 0xffffff)
2020 Value = (Value >> 24) | 0x600;
2021 Inst.addOperand(MCOperand::CreateImm(Value));
2024 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2025 assert(N == 1 && "Invalid number of operands!");
2026 // The immediate encodes the type of constant as well as the value.
2027 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2028 unsigned Value = CE->getValue();
2029 if (Value >= 256 && Value <= 0xffff)
2030 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2031 else if (Value > 0xffff && Value <= 0xffffff)
2032 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2033 else if (Value > 0xffffff)
2034 Value = (Value >> 24) | 0x600;
2035 Inst.addOperand(MCOperand::CreateImm(Value));
2038 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2039 assert(N == 1 && "Invalid number of operands!");
2040 // The immediate encodes the type of constant as well as the value.
2041 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2042 unsigned Value = ~CE->getValue();
2043 if (Value >= 256 && Value <= 0xffff)
2044 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2045 else if (Value > 0xffff && Value <= 0xffffff)
2046 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2047 else if (Value > 0xffffff)
2048 Value = (Value >> 24) | 0x600;
2049 Inst.addOperand(MCOperand::CreateImm(Value));
2052 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2053 assert(N == 1 && "Invalid number of operands!");
2054 // The immediate encodes the type of constant as well as the value.
2055 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2056 uint64_t Value = CE->getValue();
2058 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2059 Imm |= (Value & 1) << i;
2061 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2064 virtual void print(raw_ostream &OS) const;
2066 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2067 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2068 Op->ITMask.Mask = Mask;
2074 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2075 ARMOperand *Op = new ARMOperand(k_CondCode);
2082 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2083 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2084 Op->Cop.Val = CopVal;
2090 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2091 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2092 Op->Cop.Val = CopVal;
2098 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2099 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2106 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2107 ARMOperand *Op = new ARMOperand(k_CCOut);
2108 Op->Reg.RegNum = RegNum;
2114 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2115 ARMOperand *Op = new ARMOperand(k_Token);
2116 Op->Tok.Data = Str.data();
2117 Op->Tok.Length = Str.size();
2123 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2124 ARMOperand *Op = new ARMOperand(k_Register);
2125 Op->Reg.RegNum = RegNum;
2131 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2136 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2137 Op->RegShiftedReg.ShiftTy = ShTy;
2138 Op->RegShiftedReg.SrcReg = SrcReg;
2139 Op->RegShiftedReg.ShiftReg = ShiftReg;
2140 Op->RegShiftedReg.ShiftImm = ShiftImm;
2146 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2150 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2151 Op->RegShiftedImm.ShiftTy = ShTy;
2152 Op->RegShiftedImm.SrcReg = SrcReg;
2153 Op->RegShiftedImm.ShiftImm = ShiftImm;
2159 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2161 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2162 Op->ShifterImm.isASR = isASR;
2163 Op->ShifterImm.Imm = Imm;
2169 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2170 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2171 Op->RotImm.Imm = Imm;
2177 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2179 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2180 Op->Bitfield.LSB = LSB;
2181 Op->Bitfield.Width = Width;
2188 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
2189 SMLoc StartLoc, SMLoc EndLoc) {
2190 KindTy Kind = k_RegisterList;
2192 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
2193 Kind = k_DPRRegisterList;
2194 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2195 contains(Regs.front().first))
2196 Kind = k_SPRRegisterList;
2198 ARMOperand *Op = new ARMOperand(Kind);
2199 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
2200 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2201 Op->Registers.push_back(I->first);
2202 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
2203 Op->StartLoc = StartLoc;
2204 Op->EndLoc = EndLoc;
2208 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2209 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2210 ARMOperand *Op = new ARMOperand(k_VectorList);
2211 Op->VectorList.RegNum = RegNum;
2212 Op->VectorList.Count = Count;
2213 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2219 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2220 bool isDoubleSpaced,
2222 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2223 Op->VectorList.RegNum = RegNum;
2224 Op->VectorList.Count = Count;
2225 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2231 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2233 bool isDoubleSpaced,
2235 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2236 Op->VectorList.RegNum = RegNum;
2237 Op->VectorList.Count = Count;
2238 Op->VectorList.LaneIndex = Index;
2239 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2245 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2247 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2248 Op->VectorIndex.Val = Idx;
2254 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2255 ARMOperand *Op = new ARMOperand(k_Immediate);
2262 static ARMOperand *CreateMem(unsigned BaseRegNum,
2263 const MCConstantExpr *OffsetImm,
2264 unsigned OffsetRegNum,
2265 ARM_AM::ShiftOpc ShiftType,
2270 ARMOperand *Op = new ARMOperand(k_Memory);
2271 Op->Memory.BaseRegNum = BaseRegNum;
2272 Op->Memory.OffsetImm = OffsetImm;
2273 Op->Memory.OffsetRegNum = OffsetRegNum;
2274 Op->Memory.ShiftType = ShiftType;
2275 Op->Memory.ShiftImm = ShiftImm;
2276 Op->Memory.Alignment = Alignment;
2277 Op->Memory.isNegative = isNegative;
2283 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2284 ARM_AM::ShiftOpc ShiftTy,
2287 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2288 Op->PostIdxReg.RegNum = RegNum;
2289 Op->PostIdxReg.isAdd = isAdd;
2290 Op->PostIdxReg.ShiftTy = ShiftTy;
2291 Op->PostIdxReg.ShiftImm = ShiftImm;
2297 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2298 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2299 Op->MBOpt.Val = Opt;
2305 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2306 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2307 Op->IFlags.Val = IFlags;
2313 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2314 ARMOperand *Op = new ARMOperand(k_MSRMask);
2315 Op->MMask.Val = MMask;
2322 } // end anonymous namespace.
2324 void ARMOperand::print(raw_ostream &OS) const {
2327 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2330 OS << "<ccout " << getReg() << ">";
2332 case k_ITCondMask: {
2333 static const char *const MaskStr[] = {
2334 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2335 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2337 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2338 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2342 OS << "<coprocessor number: " << getCoproc() << ">";
2345 OS << "<coprocessor register: " << getCoproc() << ">";
2347 case k_CoprocOption:
2348 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2351 OS << "<mask: " << getMSRMask() << ">";
2354 getImm()->print(OS);
2356 case k_MemBarrierOpt:
2357 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2361 << " base:" << Memory.BaseRegNum;
2364 case k_PostIndexRegister:
2365 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2366 << PostIdxReg.RegNum;
2367 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2368 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2369 << PostIdxReg.ShiftImm;
2372 case k_ProcIFlags: {
2373 OS << "<ARM_PROC::";
2374 unsigned IFlags = getProcIFlags();
2375 for (int i=2; i >= 0; --i)
2376 if (IFlags & (1 << i))
2377 OS << ARM_PROC::IFlagsToString(1 << i);
2382 OS << "<register " << getReg() << ">";
2384 case k_ShifterImmediate:
2385 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2386 << " #" << ShifterImm.Imm << ">";
2388 case k_ShiftedRegister:
2389 OS << "<so_reg_reg "
2390 << RegShiftedReg.SrcReg << " "
2391 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2392 << " " << RegShiftedReg.ShiftReg << ">";
2394 case k_ShiftedImmediate:
2395 OS << "<so_reg_imm "
2396 << RegShiftedImm.SrcReg << " "
2397 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2398 << " #" << RegShiftedImm.ShiftImm << ">";
2400 case k_RotateImmediate:
2401 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2403 case k_BitfieldDescriptor:
2404 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2405 << ", width: " << Bitfield.Width << ">";
2407 case k_RegisterList:
2408 case k_DPRRegisterList:
2409 case k_SPRRegisterList: {
2410 OS << "<register_list ";
2412 const SmallVectorImpl<unsigned> &RegList = getRegList();
2413 for (SmallVectorImpl<unsigned>::const_iterator
2414 I = RegList.begin(), E = RegList.end(); I != E; ) {
2416 if (++I < E) OS << ", ";
2423 OS << "<vector_list " << VectorList.Count << " * "
2424 << VectorList.RegNum << ">";
2426 case k_VectorListAllLanes:
2427 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2428 << VectorList.RegNum << ">";
2430 case k_VectorListIndexed:
2431 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2432 << VectorList.Count << " * " << VectorList.RegNum << ">";
2435 OS << "'" << getToken() << "'";
2438 OS << "<vectorindex " << getVectorIndex() << ">";
2443 /// @name Auto-generated Match Functions
2446 static unsigned MatchRegisterName(StringRef Name);
2450 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2451 SMLoc &StartLoc, SMLoc &EndLoc) {
2452 StartLoc = Parser.getTok().getLoc();
2453 RegNo = tryParseRegister();
2454 EndLoc = Parser.getTok().getLoc();
2456 return (RegNo == (unsigned)-1);
2459 /// Try to parse a register name. The token must be an Identifier when called,
2460 /// and if it is a register name the token is eaten and the register number is
2461 /// returned. Otherwise return -1.
2463 int ARMAsmParser::tryParseRegister() {
2464 const AsmToken &Tok = Parser.getTok();
2465 if (Tok.isNot(AsmToken::Identifier)) return -1;
2467 std::string lowerCase = Tok.getString().lower();
2468 unsigned RegNum = MatchRegisterName(lowerCase);
2470 RegNum = StringSwitch<unsigned>(lowerCase)
2471 .Case("r13", ARM::SP)
2472 .Case("r14", ARM::LR)
2473 .Case("r15", ARM::PC)
2474 .Case("ip", ARM::R12)
2475 // Additional register name aliases for 'gas' compatibility.
2476 .Case("a1", ARM::R0)
2477 .Case("a2", ARM::R1)
2478 .Case("a3", ARM::R2)
2479 .Case("a4", ARM::R3)
2480 .Case("v1", ARM::R4)
2481 .Case("v2", ARM::R5)
2482 .Case("v3", ARM::R6)
2483 .Case("v4", ARM::R7)
2484 .Case("v5", ARM::R8)
2485 .Case("v6", ARM::R9)
2486 .Case("v7", ARM::R10)
2487 .Case("v8", ARM::R11)
2488 .Case("sb", ARM::R9)
2489 .Case("sl", ARM::R10)
2490 .Case("fp", ARM::R11)
2494 // Check for aliases registered via .req. Canonicalize to lower case.
2495 // That's more consistent since register names are case insensitive, and
2496 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2497 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2498 // If no match, return failure.
2499 if (Entry == RegisterReqs.end())
2501 Parser.Lex(); // Eat identifier token.
2502 return Entry->getValue();
2505 Parser.Lex(); // Eat identifier token.
2510 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2511 // If a recoverable error occurs, return 1. If an irrecoverable error
2512 // occurs, return -1. An irrecoverable error is one where tokens have been
2513 // consumed in the process of trying to parse the shifter (i.e., when it is
2514 // indeed a shifter operand, but malformed).
2515 int ARMAsmParser::tryParseShiftRegister(
2516 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2517 SMLoc S = Parser.getTok().getLoc();
2518 const AsmToken &Tok = Parser.getTok();
2519 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2521 std::string lowerCase = Tok.getString().lower();
2522 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2523 .Case("asl", ARM_AM::lsl)
2524 .Case("lsl", ARM_AM::lsl)
2525 .Case("lsr", ARM_AM::lsr)
2526 .Case("asr", ARM_AM::asr)
2527 .Case("ror", ARM_AM::ror)
2528 .Case("rrx", ARM_AM::rrx)
2529 .Default(ARM_AM::no_shift);
2531 if (ShiftTy == ARM_AM::no_shift)
2534 Parser.Lex(); // Eat the operator.
2536 // The source register for the shift has already been added to the
2537 // operand list, so we need to pop it off and combine it into the shifted
2538 // register operand instead.
2539 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2540 if (!PrevOp->isReg())
2541 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2542 int SrcReg = PrevOp->getReg();
2545 if (ShiftTy == ARM_AM::rrx) {
2546 // RRX Doesn't have an explicit shift amount. The encoder expects
2547 // the shift register to be the same as the source register. Seems odd,
2551 // Figure out if this is shifted by a constant or a register (for non-RRX).
2552 if (Parser.getTok().is(AsmToken::Hash) ||
2553 Parser.getTok().is(AsmToken::Dollar)) {
2554 Parser.Lex(); // Eat hash.
2555 SMLoc ImmLoc = Parser.getTok().getLoc();
2556 const MCExpr *ShiftExpr = 0;
2557 if (getParser().ParseExpression(ShiftExpr)) {
2558 Error(ImmLoc, "invalid immediate shift value");
2561 // The expression must be evaluatable as an immediate.
2562 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2564 Error(ImmLoc, "invalid immediate shift value");
2567 // Range check the immediate.
2568 // lsl, ror: 0 <= imm <= 31
2569 // lsr, asr: 0 <= imm <= 32
2570 Imm = CE->getValue();
2572 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2573 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2574 Error(ImmLoc, "immediate shift value out of range");
2577 // shift by zero is a nop. Always send it through as lsl.
2578 // ('as' compatibility)
2580 ShiftTy = ARM_AM::lsl;
2581 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2582 ShiftReg = tryParseRegister();
2583 SMLoc L = Parser.getTok().getLoc();
2584 if (ShiftReg == -1) {
2585 Error (L, "expected immediate or register in shift operand");
2589 Error (Parser.getTok().getLoc(),
2590 "expected immediate or register in shift operand");
2595 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2596 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2598 S, Parser.getTok().getLoc()));
2600 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2601 S, Parser.getTok().getLoc()));
2607 /// Try to parse a register name. The token must be an Identifier when called.
2608 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2609 /// if there is a "writeback". 'true' if it's not a register.
2611 /// TODO this is likely to change to allow different register types and or to
2612 /// parse for a specific register type.
2614 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2615 SMLoc S = Parser.getTok().getLoc();
2616 int RegNo = tryParseRegister();
2620 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
2622 const AsmToken &ExclaimTok = Parser.getTok();
2623 if (ExclaimTok.is(AsmToken::Exclaim)) {
2624 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2625 ExclaimTok.getLoc()));
2626 Parser.Lex(); // Eat exclaim token
2630 // Also check for an index operand. This is only legal for vector registers,
2631 // but that'll get caught OK in operand matching, so we don't need to
2632 // explicitly filter everything else out here.
2633 if (Parser.getTok().is(AsmToken::LBrac)) {
2634 SMLoc SIdx = Parser.getTok().getLoc();
2635 Parser.Lex(); // Eat left bracket token.
2637 const MCExpr *ImmVal;
2638 if (getParser().ParseExpression(ImmVal))
2640 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2642 return TokError("immediate value expected for vector index");
2644 SMLoc E = Parser.getTok().getLoc();
2645 if (Parser.getTok().isNot(AsmToken::RBrac))
2646 return Error(E, "']' expected");
2648 Parser.Lex(); // Eat right bracket token.
2650 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2658 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2659 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2661 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2662 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2664 switch (Name.size()) {
2667 if (Name[0] != CoprocOp)
2683 if (Name[0] != CoprocOp || Name[1] != '1')
2687 case '0': return 10;
2688 case '1': return 11;
2689 case '2': return 12;
2690 case '3': return 13;
2691 case '4': return 14;
2692 case '5': return 15;
2697 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2698 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2699 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2700 SMLoc S = Parser.getTok().getLoc();
2701 const AsmToken &Tok = Parser.getTok();
2702 if (!Tok.is(AsmToken::Identifier))
2703 return MatchOperand_NoMatch;
2704 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2705 .Case("eq", ARMCC::EQ)
2706 .Case("ne", ARMCC::NE)
2707 .Case("hs", ARMCC::HS)
2708 .Case("cs", ARMCC::HS)
2709 .Case("lo", ARMCC::LO)
2710 .Case("cc", ARMCC::LO)
2711 .Case("mi", ARMCC::MI)
2712 .Case("pl", ARMCC::PL)
2713 .Case("vs", ARMCC::VS)
2714 .Case("vc", ARMCC::VC)
2715 .Case("hi", ARMCC::HI)
2716 .Case("ls", ARMCC::LS)
2717 .Case("ge", ARMCC::GE)
2718 .Case("lt", ARMCC::LT)
2719 .Case("gt", ARMCC::GT)
2720 .Case("le", ARMCC::LE)
2721 .Case("al", ARMCC::AL)
2724 return MatchOperand_NoMatch;
2725 Parser.Lex(); // Eat the token.
2727 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2729 return MatchOperand_Success;
2732 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2733 /// token must be an Identifier when called, and if it is a coprocessor
2734 /// number, the token is eaten and the operand is added to the operand list.
2735 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2736 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2737 SMLoc S = Parser.getTok().getLoc();
2738 const AsmToken &Tok = Parser.getTok();
2739 if (Tok.isNot(AsmToken::Identifier))
2740 return MatchOperand_NoMatch;
2742 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2744 return MatchOperand_NoMatch;
2746 Parser.Lex(); // Eat identifier token.
2747 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2748 return MatchOperand_Success;
2751 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2752 /// token must be an Identifier when called, and if it is a coprocessor
2753 /// number, the token is eaten and the operand is added to the operand list.
2754 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2755 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2756 SMLoc S = Parser.getTok().getLoc();
2757 const AsmToken &Tok = Parser.getTok();
2758 if (Tok.isNot(AsmToken::Identifier))
2759 return MatchOperand_NoMatch;
2761 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2763 return MatchOperand_NoMatch;
2765 Parser.Lex(); // Eat identifier token.
2766 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2767 return MatchOperand_Success;
2770 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2771 /// coproc_option : '{' imm0_255 '}'
2772 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2773 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2774 SMLoc S = Parser.getTok().getLoc();
2776 // If this isn't a '{', this isn't a coprocessor immediate operand.
2777 if (Parser.getTok().isNot(AsmToken::LCurly))
2778 return MatchOperand_NoMatch;
2779 Parser.Lex(); // Eat the '{'
2782 SMLoc Loc = Parser.getTok().getLoc();
2783 if (getParser().ParseExpression(Expr)) {
2784 Error(Loc, "illegal expression");
2785 return MatchOperand_ParseFail;
2787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2788 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2789 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2790 return MatchOperand_ParseFail;
2792 int Val = CE->getValue();
2794 // Check for and consume the closing '}'
2795 if (Parser.getTok().isNot(AsmToken::RCurly))
2796 return MatchOperand_ParseFail;
2797 SMLoc E = Parser.getTok().getLoc();
2798 Parser.Lex(); // Eat the '}'
2800 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2801 return MatchOperand_Success;
2804 // For register list parsing, we need to map from raw GPR register numbering
2805 // to the enumeration values. The enumeration values aren't sorted by
2806 // register number due to our using "sp", "lr" and "pc" as canonical names.
2807 static unsigned getNextRegister(unsigned Reg) {
2808 // If this is a GPR, we need to do it manually, otherwise we can rely
2809 // on the sort ordering of the enumeration since the other reg-classes
2811 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2814 default: llvm_unreachable("Invalid GPR number!");
2815 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2816 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2817 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2818 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2819 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2820 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2821 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2822 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2826 // Return the low-subreg of a given Q register.
2827 static unsigned getDRegFromQReg(unsigned QReg) {
2829 default: llvm_unreachable("expected a Q register!");
2830 case ARM::Q0: return ARM::D0;
2831 case ARM::Q1: return ARM::D2;
2832 case ARM::Q2: return ARM::D4;
2833 case ARM::Q3: return ARM::D6;
2834 case ARM::Q4: return ARM::D8;
2835 case ARM::Q5: return ARM::D10;
2836 case ARM::Q6: return ARM::D12;
2837 case ARM::Q7: return ARM::D14;
2838 case ARM::Q8: return ARM::D16;
2839 case ARM::Q9: return ARM::D18;
2840 case ARM::Q10: return ARM::D20;
2841 case ARM::Q11: return ARM::D22;
2842 case ARM::Q12: return ARM::D24;
2843 case ARM::Q13: return ARM::D26;
2844 case ARM::Q14: return ARM::D28;
2845 case ARM::Q15: return ARM::D30;
2849 /// Parse a register list.
2851 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2852 assert(Parser.getTok().is(AsmToken::LCurly) &&
2853 "Token is not a Left Curly Brace");
2854 SMLoc S = Parser.getTok().getLoc();
2855 Parser.Lex(); // Eat '{' token.
2856 SMLoc RegLoc = Parser.getTok().getLoc();
2858 // Check the first register in the list to see what register class
2859 // this is a list of.
2860 int Reg = tryParseRegister();
2862 return Error(RegLoc, "register expected");
2864 // The reglist instructions have at most 16 registers, so reserve
2865 // space for that many.
2866 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2868 // Allow Q regs and just interpret them as the two D sub-registers.
2869 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2870 Reg = getDRegFromQReg(Reg);
2871 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2874 const MCRegisterClass *RC;
2875 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2876 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2877 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2878 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2879 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2880 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2882 return Error(RegLoc, "invalid register in register list");
2884 // Store the register.
2885 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2887 // This starts immediately after the first register token in the list,
2888 // so we can see either a comma or a minus (range separator) as a legal
2890 while (Parser.getTok().is(AsmToken::Comma) ||
2891 Parser.getTok().is(AsmToken::Minus)) {
2892 if (Parser.getTok().is(AsmToken::Minus)) {
2893 Parser.Lex(); // Eat the minus.
2894 SMLoc EndLoc = Parser.getTok().getLoc();
2895 int EndReg = tryParseRegister();
2897 return Error(EndLoc, "register expected");
2898 // Allow Q regs and just interpret them as the two D sub-registers.
2899 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2900 EndReg = getDRegFromQReg(EndReg) + 1;
2901 // If the register is the same as the start reg, there's nothing
2905 // The register must be in the same register class as the first.
2906 if (!RC->contains(EndReg))
2907 return Error(EndLoc, "invalid register in register list");
2908 // Ranges must go from low to high.
2909 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
2910 return Error(EndLoc, "bad range in register list");
2912 // Add all the registers in the range to the register list.
2913 while (Reg != EndReg) {
2914 Reg = getNextRegister(Reg);
2915 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2919 Parser.Lex(); // Eat the comma.
2920 RegLoc = Parser.getTok().getLoc();
2922 const AsmToken RegTok = Parser.getTok();
2923 Reg = tryParseRegister();
2925 return Error(RegLoc, "register expected");
2926 // Allow Q regs and just interpret them as the two D sub-registers.
2927 bool isQReg = false;
2928 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2929 Reg = getDRegFromQReg(Reg);
2932 // The register must be in the same register class as the first.
2933 if (!RC->contains(Reg))
2934 return Error(RegLoc, "invalid register in register list");
2935 // List must be monotonically increasing.
2936 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
2937 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2938 Warning(RegLoc, "register list not in ascending order");
2940 return Error(RegLoc, "register list not in ascending order");
2942 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
2943 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2944 ") in register list");
2947 // VFP register lists must also be contiguous.
2948 // It's OK to use the enumeration values directly here rather, as the
2949 // VFP register classes have the enum sorted properly.
2950 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2952 return Error(RegLoc, "non-contiguous register range");
2953 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2955 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
2958 SMLoc E = Parser.getTok().getLoc();
2959 if (Parser.getTok().isNot(AsmToken::RCurly))
2960 return Error(E, "'}' expected");
2961 Parser.Lex(); // Eat '}' token.
2963 // Push the register list operand.
2964 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
2966 // The ARM system instruction variants for LDM/STM have a '^' token here.
2967 if (Parser.getTok().is(AsmToken::Caret)) {
2968 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2969 Parser.Lex(); // Eat '^' token.
2975 // Helper function to parse the lane index for vector lists.
2976 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2977 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2978 Index = 0; // Always return a defined index value.
2979 if (Parser.getTok().is(AsmToken::LBrac)) {
2980 Parser.Lex(); // Eat the '['.
2981 if (Parser.getTok().is(AsmToken::RBrac)) {
2982 // "Dn[]" is the 'all lanes' syntax.
2983 LaneKind = AllLanes;
2984 Parser.Lex(); // Eat the ']'.
2985 return MatchOperand_Success;
2988 // There's an optional '#' token here. Normally there wouldn't be, but
2989 // inline assemble puts one in, and it's friendly to accept that.
2990 if (Parser.getTok().is(AsmToken::Hash))
2991 Parser.Lex(); // Eat the '#'
2993 const MCExpr *LaneIndex;
2994 SMLoc Loc = Parser.getTok().getLoc();
2995 if (getParser().ParseExpression(LaneIndex)) {
2996 Error(Loc, "illegal expression");
2997 return MatchOperand_ParseFail;
2999 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3001 Error(Loc, "lane index must be empty or an integer");
3002 return MatchOperand_ParseFail;
3004 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3005 Error(Parser.getTok().getLoc(), "']' expected");
3006 return MatchOperand_ParseFail;
3008 Parser.Lex(); // Eat the ']'.
3009 int64_t Val = CE->getValue();
3011 // FIXME: Make this range check context sensitive for .8, .16, .32.
3012 if (Val < 0 || Val > 7) {
3013 Error(Parser.getTok().getLoc(), "lane index out of range");
3014 return MatchOperand_ParseFail;
3017 LaneKind = IndexedLane;
3018 return MatchOperand_Success;
3021 return MatchOperand_Success;
3024 // parse a vector register list
3025 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3026 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3027 VectorLaneTy LaneKind;
3029 SMLoc S = Parser.getTok().getLoc();
3030 // As an extension (to match gas), support a plain D register or Q register
3031 // (without encosing curly braces) as a single or double entry list,
3033 if (Parser.getTok().is(AsmToken::Identifier)) {
3034 int Reg = tryParseRegister();
3036 return MatchOperand_NoMatch;
3037 SMLoc E = Parser.getTok().getLoc();
3038 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3039 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
3040 if (Res != MatchOperand_Success)
3044 E = Parser.getTok().getLoc();
3045 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3048 E = Parser.getTok().getLoc();
3049 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3053 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3058 return MatchOperand_Success;
3060 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3061 Reg = getDRegFromQReg(Reg);
3062 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
3063 if (Res != MatchOperand_Success)
3067 E = Parser.getTok().getLoc();
3068 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3069 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3070 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3073 E = Parser.getTok().getLoc();
3074 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3075 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3076 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3080 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3085 return MatchOperand_Success;
3087 Error(S, "vector register expected");
3088 return MatchOperand_ParseFail;
3091 if (Parser.getTok().isNot(AsmToken::LCurly))
3092 return MatchOperand_NoMatch;
3094 Parser.Lex(); // Eat '{' token.
3095 SMLoc RegLoc = Parser.getTok().getLoc();
3097 int Reg = tryParseRegister();
3099 Error(RegLoc, "register expected");
3100 return MatchOperand_ParseFail;
3104 unsigned FirstReg = Reg;
3105 // The list is of D registers, but we also allow Q regs and just interpret
3106 // them as the two D sub-registers.
3107 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3108 FirstReg = Reg = getDRegFromQReg(Reg);
3109 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3110 // it's ambiguous with four-register single spaced.
3114 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
3115 return MatchOperand_ParseFail;
3117 while (Parser.getTok().is(AsmToken::Comma) ||
3118 Parser.getTok().is(AsmToken::Minus)) {
3119 if (Parser.getTok().is(AsmToken::Minus)) {
3121 Spacing = 1; // Register range implies a single spaced list.
3122 else if (Spacing == 2) {
3123 Error(Parser.getTok().getLoc(),
3124 "sequential registers in double spaced list");
3125 return MatchOperand_ParseFail;
3127 Parser.Lex(); // Eat the minus.
3128 SMLoc EndLoc = Parser.getTok().getLoc();
3129 int EndReg = tryParseRegister();
3131 Error(EndLoc, "register expected");
3132 return MatchOperand_ParseFail;
3134 // Allow Q regs and just interpret them as the two D sub-registers.
3135 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3136 EndReg = getDRegFromQReg(EndReg) + 1;
3137 // If the register is the same as the start reg, there's nothing
3141 // The register must be in the same register class as the first.
3142 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3143 Error(EndLoc, "invalid register in register list");
3144 return MatchOperand_ParseFail;
3146 // Ranges must go from low to high.
3148 Error(EndLoc, "bad range in register list");
3149 return MatchOperand_ParseFail;
3151 // Parse the lane specifier if present.
3152 VectorLaneTy NextLaneKind;
3153 unsigned NextLaneIndex;
3154 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3155 return MatchOperand_ParseFail;
3156 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3157 Error(EndLoc, "mismatched lane index in register list");
3158 return MatchOperand_ParseFail;
3160 EndLoc = Parser.getTok().getLoc();
3162 // Add all the registers in the range to the register list.
3163 Count += EndReg - Reg;
3167 Parser.Lex(); // Eat the comma.
3168 RegLoc = Parser.getTok().getLoc();
3170 Reg = tryParseRegister();
3172 Error(RegLoc, "register expected");
3173 return MatchOperand_ParseFail;
3175 // vector register lists must be contiguous.
3176 // It's OK to use the enumeration values directly here rather, as the
3177 // VFP register classes have the enum sorted properly.
3179 // The list is of D registers, but we also allow Q regs and just interpret
3180 // them as the two D sub-registers.
3181 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3183 Spacing = 1; // Register range implies a single spaced list.
3184 else if (Spacing == 2) {
3186 "invalid register in double-spaced list (must be 'D' register')");
3187 return MatchOperand_ParseFail;
3189 Reg = getDRegFromQReg(Reg);
3190 if (Reg != OldReg + 1) {
3191 Error(RegLoc, "non-contiguous register range");
3192 return MatchOperand_ParseFail;
3196 // Parse the lane specifier if present.
3197 VectorLaneTy NextLaneKind;
3198 unsigned NextLaneIndex;
3199 SMLoc EndLoc = Parser.getTok().getLoc();
3200 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3201 return MatchOperand_ParseFail;
3202 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3203 Error(EndLoc, "mismatched lane index in register list");
3204 return MatchOperand_ParseFail;
3208 // Normal D register.
3209 // Figure out the register spacing (single or double) of the list if
3210 // we don't know it already.
3212 Spacing = 1 + (Reg == OldReg + 2);
3214 // Just check that it's contiguous and keep going.
3215 if (Reg != OldReg + Spacing) {
3216 Error(RegLoc, "non-contiguous register range");
3217 return MatchOperand_ParseFail;
3220 // Parse the lane specifier if present.
3221 VectorLaneTy NextLaneKind;
3222 unsigned NextLaneIndex;
3223 SMLoc EndLoc = Parser.getTok().getLoc();
3224 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3225 return MatchOperand_ParseFail;
3226 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3227 Error(EndLoc, "mismatched lane index in register list");
3228 return MatchOperand_ParseFail;
3232 SMLoc E = Parser.getTok().getLoc();
3233 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3234 Error(E, "'}' expected");
3235 return MatchOperand_ParseFail;
3237 Parser.Lex(); // Eat '}' token.
3241 // Two-register operands have been converted to the
3242 // composite register classes.
3244 const MCRegisterClass *RC = (Spacing == 1) ?
3245 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3246 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3247 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3250 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3251 (Spacing == 2), S, E));
3254 // Two-register operands have been converted to the
3255 // composite register classes.
3257 const MCRegisterClass *RC = (Spacing == 1) ?
3258 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3259 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3260 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3262 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3267 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3273 return MatchOperand_Success;
3276 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3277 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3278 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3279 SMLoc S = Parser.getTok().getLoc();
3280 const AsmToken &Tok = Parser.getTok();
3283 if (Tok.is(AsmToken::Identifier)) {
3284 StringRef OptStr = Tok.getString();
3286 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3287 .Case("sy", ARM_MB::SY)
3288 .Case("st", ARM_MB::ST)
3289 .Case("sh", ARM_MB::ISH)
3290 .Case("ish", ARM_MB::ISH)
3291 .Case("shst", ARM_MB::ISHST)
3292 .Case("ishst", ARM_MB::ISHST)
3293 .Case("nsh", ARM_MB::NSH)
3294 .Case("un", ARM_MB::NSH)
3295 .Case("nshst", ARM_MB::NSHST)
3296 .Case("unst", ARM_MB::NSHST)
3297 .Case("osh", ARM_MB::OSH)
3298 .Case("oshst", ARM_MB::OSHST)
3302 return MatchOperand_NoMatch;
3304 Parser.Lex(); // Eat identifier token.
3305 } else if (Tok.is(AsmToken::Hash) ||
3306 Tok.is(AsmToken::Dollar) ||
3307 Tok.is(AsmToken::Integer)) {
3308 if (Parser.getTok().isNot(AsmToken::Integer))
3309 Parser.Lex(); // Eat the '#'.
3310 SMLoc Loc = Parser.getTok().getLoc();
3312 const MCExpr *MemBarrierID;
3313 if (getParser().ParseExpression(MemBarrierID)) {
3314 Error(Loc, "illegal expression");
3315 return MatchOperand_ParseFail;
3318 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3320 Error(Loc, "constant expression expected");
3321 return MatchOperand_ParseFail;
3324 int Val = CE->getValue();
3326 Error(Loc, "immediate value out of range");
3327 return MatchOperand_ParseFail;
3330 Opt = ARM_MB::RESERVED_0 + Val;
3332 return MatchOperand_ParseFail;
3334 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3335 return MatchOperand_Success;
3338 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3339 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3340 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3341 SMLoc S = Parser.getTok().getLoc();
3342 const AsmToken &Tok = Parser.getTok();
3343 if (!Tok.is(AsmToken::Identifier))
3344 return MatchOperand_NoMatch;
3345 StringRef IFlagsStr = Tok.getString();
3347 // An iflags string of "none" is interpreted to mean that none of the AIF
3348 // bits are set. Not a terribly useful instruction, but a valid encoding.
3349 unsigned IFlags = 0;
3350 if (IFlagsStr != "none") {
3351 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3352 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3353 .Case("a", ARM_PROC::A)
3354 .Case("i", ARM_PROC::I)
3355 .Case("f", ARM_PROC::F)
3358 // If some specific iflag is already set, it means that some letter is
3359 // present more than once, this is not acceptable.
3360 if (Flag == ~0U || (IFlags & Flag))
3361 return MatchOperand_NoMatch;
3367 Parser.Lex(); // Eat identifier token.
3368 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3369 return MatchOperand_Success;
3372 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3373 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3374 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3375 SMLoc S = Parser.getTok().getLoc();
3376 const AsmToken &Tok = Parser.getTok();
3377 if (!Tok.is(AsmToken::Identifier))
3378 return MatchOperand_NoMatch;
3379 StringRef Mask = Tok.getString();
3382 // See ARMv6-M 10.1.1
3383 std::string Name = Mask.lower();
3384 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3385 // Note: in the documentation:
3386 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3387 // for MSR APSR_nzcvq.
3388 // but we do make it an alias here. This is so to get the "mask encoding"
3389 // bits correct on MSR APSR writes.
3391 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3392 // should really only be allowed when writing a special register. Note
3393 // they get dropped in the MRS instruction reading a special register as
3394 // the SYSm field is only 8 bits.
3396 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3397 // includes the DSP extension but that is not checked.
3398 .Case("apsr", 0x800)
3399 .Case("apsr_nzcvq", 0x800)
3400 .Case("apsr_g", 0x400)
3401 .Case("apsr_nzcvqg", 0xc00)
3402 .Case("iapsr", 0x801)
3403 .Case("iapsr_nzcvq", 0x801)
3404 .Case("iapsr_g", 0x401)
3405 .Case("iapsr_nzcvqg", 0xc01)
3406 .Case("eapsr", 0x802)
3407 .Case("eapsr_nzcvq", 0x802)
3408 .Case("eapsr_g", 0x402)
3409 .Case("eapsr_nzcvqg", 0xc02)
3410 .Case("xpsr", 0x803)
3411 .Case("xpsr_nzcvq", 0x803)
3412 .Case("xpsr_g", 0x403)
3413 .Case("xpsr_nzcvqg", 0xc03)
3414 .Case("ipsr", 0x805)
3415 .Case("epsr", 0x806)
3416 .Case("iepsr", 0x807)
3419 .Case("primask", 0x810)
3420 .Case("basepri", 0x811)
3421 .Case("basepri_max", 0x812)
3422 .Case("faultmask", 0x813)
3423 .Case("control", 0x814)
3426 if (FlagsVal == ~0U)
3427 return MatchOperand_NoMatch;
3429 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3430 // basepri, basepri_max and faultmask only valid for V7m.
3431 return MatchOperand_NoMatch;
3433 Parser.Lex(); // Eat identifier token.
3434 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3435 return MatchOperand_Success;
3438 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3439 size_t Start = 0, Next = Mask.find('_');
3440 StringRef Flags = "";
3441 std::string SpecReg = Mask.slice(Start, Next).lower();
3442 if (Next != StringRef::npos)
3443 Flags = Mask.slice(Next+1, Mask.size());
3445 // FlagsVal contains the complete mask:
3447 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3448 unsigned FlagsVal = 0;
3450 if (SpecReg == "apsr") {
3451 FlagsVal = StringSwitch<unsigned>(Flags)
3452 .Case("nzcvq", 0x8) // same as CPSR_f
3453 .Case("g", 0x4) // same as CPSR_s
3454 .Case("nzcvqg", 0xc) // same as CPSR_fs
3457 if (FlagsVal == ~0U) {
3459 return MatchOperand_NoMatch;
3461 FlagsVal = 8; // No flag
3463 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3464 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3465 if (Flags == "all" || Flags == "")
3467 for (int i = 0, e = Flags.size(); i != e; ++i) {
3468 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3475 // If some specific flag is already set, it means that some letter is
3476 // present more than once, this is not acceptable.
3477 if (FlagsVal == ~0U || (FlagsVal & Flag))
3478 return MatchOperand_NoMatch;
3481 } else // No match for special register.
3482 return MatchOperand_NoMatch;
3484 // Special register without flags is NOT equivalent to "fc" flags.
3485 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3486 // two lines would enable gas compatibility at the expense of breaking
3492 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3493 if (SpecReg == "spsr")
3496 Parser.Lex(); // Eat identifier token.
3497 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3498 return MatchOperand_Success;
3501 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3502 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3503 int Low, int High) {
3504 const AsmToken &Tok = Parser.getTok();
3505 if (Tok.isNot(AsmToken::Identifier)) {
3506 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3507 return MatchOperand_ParseFail;
3509 StringRef ShiftName = Tok.getString();
3510 std::string LowerOp = Op.lower();
3511 std::string UpperOp = Op.upper();
3512 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3513 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3514 return MatchOperand_ParseFail;
3516 Parser.Lex(); // Eat shift type token.
3518 // There must be a '#' and a shift amount.
3519 if (Parser.getTok().isNot(AsmToken::Hash) &&
3520 Parser.getTok().isNot(AsmToken::Dollar)) {
3521 Error(Parser.getTok().getLoc(), "'#' expected");
3522 return MatchOperand_ParseFail;
3524 Parser.Lex(); // Eat hash token.
3526 const MCExpr *ShiftAmount;
3527 SMLoc Loc = Parser.getTok().getLoc();
3528 if (getParser().ParseExpression(ShiftAmount)) {
3529 Error(Loc, "illegal expression");
3530 return MatchOperand_ParseFail;
3532 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3534 Error(Loc, "constant expression expected");
3535 return MatchOperand_ParseFail;
3537 int Val = CE->getValue();
3538 if (Val < Low || Val > High) {
3539 Error(Loc, "immediate value out of range");
3540 return MatchOperand_ParseFail;
3543 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3545 return MatchOperand_Success;
3548 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3549 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3550 const AsmToken &Tok = Parser.getTok();
3551 SMLoc S = Tok.getLoc();
3552 if (Tok.isNot(AsmToken::Identifier)) {
3553 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3554 return MatchOperand_ParseFail;
3556 int Val = StringSwitch<int>(Tok.getString())
3560 Parser.Lex(); // Eat the token.
3563 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3564 return MatchOperand_ParseFail;
3566 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3568 S, Parser.getTok().getLoc()));
3569 return MatchOperand_Success;
3572 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3573 /// instructions. Legal values are:
3574 /// lsl #n 'n' in [0,31]
3575 /// asr #n 'n' in [1,32]
3576 /// n == 32 encoded as n == 0.
3577 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3578 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3579 const AsmToken &Tok = Parser.getTok();
3580 SMLoc S = Tok.getLoc();
3581 if (Tok.isNot(AsmToken::Identifier)) {
3582 Error(S, "shift operator 'asr' or 'lsl' expected");
3583 return MatchOperand_ParseFail;
3585 StringRef ShiftName = Tok.getString();
3587 if (ShiftName == "lsl" || ShiftName == "LSL")
3589 else if (ShiftName == "asr" || ShiftName == "ASR")
3592 Error(S, "shift operator 'asr' or 'lsl' expected");
3593 return MatchOperand_ParseFail;
3595 Parser.Lex(); // Eat the operator.
3597 // A '#' and a shift amount.
3598 if (Parser.getTok().isNot(AsmToken::Hash) &&
3599 Parser.getTok().isNot(AsmToken::Dollar)) {
3600 Error(Parser.getTok().getLoc(), "'#' expected");
3601 return MatchOperand_ParseFail;
3603 Parser.Lex(); // Eat hash token.
3605 const MCExpr *ShiftAmount;
3606 SMLoc E = Parser.getTok().getLoc();
3607 if (getParser().ParseExpression(ShiftAmount)) {
3608 Error(E, "malformed shift expression");
3609 return MatchOperand_ParseFail;
3611 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3613 Error(E, "shift amount must be an immediate");
3614 return MatchOperand_ParseFail;
3617 int64_t Val = CE->getValue();
3619 // Shift amount must be in [1,32]
3620 if (Val < 1 || Val > 32) {
3621 Error(E, "'asr' shift amount must be in range [1,32]");
3622 return MatchOperand_ParseFail;
3624 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3625 if (isThumb() && Val == 32) {
3626 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3627 return MatchOperand_ParseFail;
3629 if (Val == 32) Val = 0;
3631 // Shift amount must be in [1,32]
3632 if (Val < 0 || Val > 31) {
3633 Error(E, "'lsr' shift amount must be in range [0,31]");
3634 return MatchOperand_ParseFail;
3638 E = Parser.getTok().getLoc();
3639 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3641 return MatchOperand_Success;
3644 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3645 /// of instructions. Legal values are:
3646 /// ror #n 'n' in {0, 8, 16, 24}
3647 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3648 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3649 const AsmToken &Tok = Parser.getTok();
3650 SMLoc S = Tok.getLoc();
3651 if (Tok.isNot(AsmToken::Identifier))
3652 return MatchOperand_NoMatch;
3653 StringRef ShiftName = Tok.getString();
3654 if (ShiftName != "ror" && ShiftName != "ROR")
3655 return MatchOperand_NoMatch;
3656 Parser.Lex(); // Eat the operator.
3658 // A '#' and a rotate amount.
3659 if (Parser.getTok().isNot(AsmToken::Hash) &&
3660 Parser.getTok().isNot(AsmToken::Dollar)) {
3661 Error(Parser.getTok().getLoc(), "'#' expected");
3662 return MatchOperand_ParseFail;
3664 Parser.Lex(); // Eat hash token.
3666 const MCExpr *ShiftAmount;
3667 SMLoc E = Parser.getTok().getLoc();
3668 if (getParser().ParseExpression(ShiftAmount)) {
3669 Error(E, "malformed rotate expression");
3670 return MatchOperand_ParseFail;
3672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3674 Error(E, "rotate amount must be an immediate");
3675 return MatchOperand_ParseFail;
3678 int64_t Val = CE->getValue();
3679 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3680 // normally, zero is represented in asm by omitting the rotate operand
3682 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3683 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3684 return MatchOperand_ParseFail;
3687 E = Parser.getTok().getLoc();
3688 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3690 return MatchOperand_Success;
3693 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3694 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3695 SMLoc S = Parser.getTok().getLoc();
3696 // The bitfield descriptor is really two operands, the LSB and the width.
3697 if (Parser.getTok().isNot(AsmToken::Hash) &&
3698 Parser.getTok().isNot(AsmToken::Dollar)) {
3699 Error(Parser.getTok().getLoc(), "'#' expected");
3700 return MatchOperand_ParseFail;
3702 Parser.Lex(); // Eat hash token.
3704 const MCExpr *LSBExpr;
3705 SMLoc E = Parser.getTok().getLoc();
3706 if (getParser().ParseExpression(LSBExpr)) {
3707 Error(E, "malformed immediate expression");
3708 return MatchOperand_ParseFail;
3710 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3712 Error(E, "'lsb' operand must be an immediate");
3713 return MatchOperand_ParseFail;
3716 int64_t LSB = CE->getValue();
3717 // The LSB must be in the range [0,31]
3718 if (LSB < 0 || LSB > 31) {
3719 Error(E, "'lsb' operand must be in the range [0,31]");
3720 return MatchOperand_ParseFail;
3722 E = Parser.getTok().getLoc();
3724 // Expect another immediate operand.
3725 if (Parser.getTok().isNot(AsmToken::Comma)) {
3726 Error(Parser.getTok().getLoc(), "too few operands");
3727 return MatchOperand_ParseFail;
3729 Parser.Lex(); // Eat hash token.
3730 if (Parser.getTok().isNot(AsmToken::Hash) &&
3731 Parser.getTok().isNot(AsmToken::Dollar)) {
3732 Error(Parser.getTok().getLoc(), "'#' expected");
3733 return MatchOperand_ParseFail;
3735 Parser.Lex(); // Eat hash token.
3737 const MCExpr *WidthExpr;
3738 if (getParser().ParseExpression(WidthExpr)) {
3739 Error(E, "malformed immediate expression");
3740 return MatchOperand_ParseFail;
3742 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3744 Error(E, "'width' operand must be an immediate");
3745 return MatchOperand_ParseFail;
3748 int64_t Width = CE->getValue();
3749 // The LSB must be in the range [1,32-lsb]
3750 if (Width < 1 || Width > 32 - LSB) {
3751 Error(E, "'width' operand must be in the range [1,32-lsb]");
3752 return MatchOperand_ParseFail;
3754 E = Parser.getTok().getLoc();
3756 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3758 return MatchOperand_Success;
3761 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3762 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3763 // Check for a post-index addressing register operand. Specifically:
3764 // postidx_reg := '+' register {, shift}
3765 // | '-' register {, shift}
3766 // | register {, shift}
3768 // This method must return MatchOperand_NoMatch without consuming any tokens
3769 // in the case where there is no match, as other alternatives take other
3771 AsmToken Tok = Parser.getTok();
3772 SMLoc S = Tok.getLoc();
3773 bool haveEaten = false;
3776 if (Tok.is(AsmToken::Plus)) {
3777 Parser.Lex(); // Eat the '+' token.
3779 } else if (Tok.is(AsmToken::Minus)) {
3780 Parser.Lex(); // Eat the '-' token.
3784 if (Parser.getTok().is(AsmToken::Identifier))
3785 Reg = tryParseRegister();
3788 return MatchOperand_NoMatch;
3789 Error(Parser.getTok().getLoc(), "register expected");
3790 return MatchOperand_ParseFail;
3792 SMLoc E = Parser.getTok().getLoc();
3794 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3795 unsigned ShiftImm = 0;
3796 if (Parser.getTok().is(AsmToken::Comma)) {
3797 Parser.Lex(); // Eat the ','.
3798 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3799 return MatchOperand_ParseFail;
3802 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3805 return MatchOperand_Success;
3808 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3809 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3810 // Check for a post-index addressing register operand. Specifically:
3811 // am3offset := '+' register
3818 // This method must return MatchOperand_NoMatch without consuming any tokens
3819 // in the case where there is no match, as other alternatives take other
3821 AsmToken Tok = Parser.getTok();
3822 SMLoc S = Tok.getLoc();
3824 // Do immediates first, as we always parse those if we have a '#'.
3825 if (Parser.getTok().is(AsmToken::Hash) ||
3826 Parser.getTok().is(AsmToken::Dollar)) {
3827 Parser.Lex(); // Eat the '#'.
3828 // Explicitly look for a '-', as we need to encode negative zero
3830 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3831 const MCExpr *Offset;
3832 if (getParser().ParseExpression(Offset))
3833 return MatchOperand_ParseFail;
3834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3836 Error(S, "constant expression expected");
3837 return MatchOperand_ParseFail;
3839 SMLoc E = Tok.getLoc();
3840 // Negative zero is encoded as the flag value INT32_MIN.
3841 int32_t Val = CE->getValue();
3842 if (isNegative && Val == 0)
3846 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3848 return MatchOperand_Success;
3852 bool haveEaten = false;
3855 if (Tok.is(AsmToken::Plus)) {
3856 Parser.Lex(); // Eat the '+' token.
3858 } else if (Tok.is(AsmToken::Minus)) {
3859 Parser.Lex(); // Eat the '-' token.
3863 if (Parser.getTok().is(AsmToken::Identifier))
3864 Reg = tryParseRegister();
3867 return MatchOperand_NoMatch;
3868 Error(Parser.getTok().getLoc(), "register expected");
3869 return MatchOperand_ParseFail;
3871 SMLoc E = Parser.getTok().getLoc();
3873 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3876 return MatchOperand_Success;
3879 /// cvtT2LdrdPre - Convert parsed operands to MCInst.
3880 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3881 /// when they refer multiple MIOperands inside a single one.
3883 cvtT2LdrdPre(MCInst &Inst,
3884 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3886 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3887 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3888 // Create a writeback register dummy placeholder.
3889 Inst.addOperand(MCOperand::CreateReg(0));
3891 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3893 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3896 /// cvtT2StrdPre - Convert parsed operands to MCInst.
3897 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3898 /// when they refer multiple MIOperands inside a single one.
3900 cvtT2StrdPre(MCInst &Inst,
3901 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3902 // Create a writeback register dummy placeholder.
3903 Inst.addOperand(MCOperand::CreateReg(0));
3905 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3906 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3908 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3910 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3913 /// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3914 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3915 /// when they refer multiple MIOperands inside a single one.
3917 cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
3918 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3919 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3921 // Create a writeback register dummy placeholder.
3922 Inst.addOperand(MCOperand::CreateImm(0));
3924 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3925 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3928 /// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3929 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3930 /// when they refer multiple MIOperands inside a single one.
3932 cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
3933 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3934 // Create a writeback register dummy placeholder.
3935 Inst.addOperand(MCOperand::CreateImm(0));
3936 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3937 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3938 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3941 /// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3942 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3943 /// when they refer multiple MIOperands inside a single one.
3945 cvtLdWriteBackRegAddrMode2(MCInst &Inst,
3946 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3947 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3949 // Create a writeback register dummy placeholder.
3950 Inst.addOperand(MCOperand::CreateImm(0));
3952 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3953 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3956 /// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3957 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3958 /// when they refer multiple MIOperands inside a single one.
3960 cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
3961 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3962 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3964 // Create a writeback register dummy placeholder.
3965 Inst.addOperand(MCOperand::CreateImm(0));
3967 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3968 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3972 /// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3973 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3974 /// when they refer multiple MIOperands inside a single one.
3976 cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
3977 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3978 // Create a writeback register dummy placeholder.
3979 Inst.addOperand(MCOperand::CreateImm(0));
3980 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3981 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3982 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3985 /// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3986 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3987 /// when they refer multiple MIOperands inside a single one.
3989 cvtStWriteBackRegAddrMode2(MCInst &Inst,
3990 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3991 // Create a writeback register dummy placeholder.
3992 Inst.addOperand(MCOperand::CreateImm(0));
3993 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3994 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3995 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3998 /// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3999 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4000 /// when they refer multiple MIOperands inside a single one.
4002 cvtStWriteBackRegAddrMode3(MCInst &Inst,
4003 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4004 // Create a writeback register dummy placeholder.
4005 Inst.addOperand(MCOperand::CreateImm(0));
4006 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4007 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4008 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4011 /// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4012 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4013 /// when they refer multiple MIOperands inside a single one.
4015 cvtLdExtTWriteBackImm(MCInst &Inst,
4016 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4018 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4019 // Create a writeback register dummy placeholder.
4020 Inst.addOperand(MCOperand::CreateImm(0));
4022 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4024 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4026 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4029 /// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
4030 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4031 /// when they refer multiple MIOperands inside a single one.
4033 cvtLdExtTWriteBackReg(MCInst &Inst,
4034 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4036 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4037 // Create a writeback register dummy placeholder.
4038 Inst.addOperand(MCOperand::CreateImm(0));
4040 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4042 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4044 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4047 /// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
4048 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4049 /// when they refer multiple MIOperands inside a single one.
4051 cvtStExtTWriteBackImm(MCInst &Inst,
4052 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4053 // Create a writeback register dummy placeholder.
4054 Inst.addOperand(MCOperand::CreateImm(0));
4056 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4058 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4060 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4062 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4065 /// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4066 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4067 /// when they refer multiple MIOperands inside a single one.
4069 cvtStExtTWriteBackReg(MCInst &Inst,
4070 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4071 // Create a writeback register dummy placeholder.
4072 Inst.addOperand(MCOperand::CreateImm(0));
4074 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4076 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4078 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4080 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4083 /// cvtLdrdPre - Convert parsed operands to MCInst.
4084 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4085 /// when they refer multiple MIOperands inside a single one.
4087 cvtLdrdPre(MCInst &Inst,
4088 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4090 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4091 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4092 // Create a writeback register dummy placeholder.
4093 Inst.addOperand(MCOperand::CreateImm(0));
4095 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4097 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4100 /// cvtStrdPre - Convert parsed operands to MCInst.
4101 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4102 /// when they refer multiple MIOperands inside a single one.
4104 cvtStrdPre(MCInst &Inst,
4105 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4106 // Create a writeback register dummy placeholder.
4107 Inst.addOperand(MCOperand::CreateImm(0));
4109 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4110 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4112 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4114 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4117 /// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4118 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4119 /// when they refer multiple MIOperands inside a single one.
4121 cvtLdWriteBackRegAddrMode3(MCInst &Inst,
4122 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4123 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4124 // Create a writeback register dummy placeholder.
4125 Inst.addOperand(MCOperand::CreateImm(0));
4126 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4127 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4130 /// cvtThumbMultiply - Convert parsed operands to MCInst.
4131 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4132 /// when they refer multiple MIOperands inside a single one.
4134 cvtThumbMultiply(MCInst &Inst,
4135 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4136 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4137 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4138 // If we have a three-operand form, make sure to set Rn to be the operand
4139 // that isn't the same as Rd.
4141 if (Operands.size() == 6 &&
4142 ((ARMOperand*)Operands[4])->getReg() ==
4143 ((ARMOperand*)Operands[3])->getReg())
4145 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4146 Inst.addOperand(Inst.getOperand(0));
4147 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4151 cvtVLDwbFixed(MCInst &Inst,
4152 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4154 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4155 // Create a writeback register dummy placeholder.
4156 Inst.addOperand(MCOperand::CreateImm(0));
4158 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4160 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4164 cvtVLDwbRegister(MCInst &Inst,
4165 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4167 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4168 // Create a writeback register dummy placeholder.
4169 Inst.addOperand(MCOperand::CreateImm(0));
4171 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4173 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4175 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4179 cvtVSTwbFixed(MCInst &Inst,
4180 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4181 // Create a writeback register dummy placeholder.
4182 Inst.addOperand(MCOperand::CreateImm(0));
4184 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4186 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4188 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4192 cvtVSTwbRegister(MCInst &Inst,
4193 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4194 // Create a writeback register dummy placeholder.
4195 Inst.addOperand(MCOperand::CreateImm(0));
4197 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4199 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4201 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4203 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4206 /// Parse an ARM memory expression, return false if successful else return true
4207 /// or an error. The first token must be a '[' when called.
4209 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4211 assert(Parser.getTok().is(AsmToken::LBrac) &&
4212 "Token is not a Left Bracket");
4213 S = Parser.getTok().getLoc();
4214 Parser.Lex(); // Eat left bracket token.
4216 const AsmToken &BaseRegTok = Parser.getTok();
4217 int BaseRegNum = tryParseRegister();
4218 if (BaseRegNum == -1)
4219 return Error(BaseRegTok.getLoc(), "register expected");
4221 // The next token must either be a comma or a closing bracket.
4222 const AsmToken &Tok = Parser.getTok();
4223 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
4224 return Error(Tok.getLoc(), "malformed memory operand");
4226 if (Tok.is(AsmToken::RBrac)) {
4228 Parser.Lex(); // Eat right bracket token.
4230 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4231 0, 0, false, S, E));
4233 // If there's a pre-indexing writeback marker, '!', just add it as a token
4234 // operand. It's rather odd, but syntactically valid.
4235 if (Parser.getTok().is(AsmToken::Exclaim)) {
4236 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4237 Parser.Lex(); // Eat the '!'.
4243 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4244 Parser.Lex(); // Eat the comma.
4246 // If we have a ':', it's an alignment specifier.
4247 if (Parser.getTok().is(AsmToken::Colon)) {
4248 Parser.Lex(); // Eat the ':'.
4249 E = Parser.getTok().getLoc();
4252 if (getParser().ParseExpression(Expr))
4255 // The expression has to be a constant. Memory references with relocations
4256 // don't come through here, as they use the <label> forms of the relevant
4258 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4260 return Error (E, "constant expression expected");
4263 switch (CE->getValue()) {
4266 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4267 case 16: Align = 2; break;
4268 case 32: Align = 4; break;
4269 case 64: Align = 8; break;
4270 case 128: Align = 16; break;
4271 case 256: Align = 32; break;
4274 // Now we should have the closing ']'
4275 E = Parser.getTok().getLoc();
4276 if (Parser.getTok().isNot(AsmToken::RBrac))
4277 return Error(E, "']' expected");
4278 Parser.Lex(); // Eat right bracket token.
4280 // Don't worry about range checking the value here. That's handled by
4281 // the is*() predicates.
4282 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4283 ARM_AM::no_shift, 0, Align,
4286 // If there's a pre-indexing writeback marker, '!', just add it as a token
4288 if (Parser.getTok().is(AsmToken::Exclaim)) {
4289 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4290 Parser.Lex(); // Eat the '!'.
4296 // If we have a '#', it's an immediate offset, else assume it's a register
4297 // offset. Be friendly and also accept a plain integer (without a leading
4298 // hash) for gas compatibility.
4299 if (Parser.getTok().is(AsmToken::Hash) ||
4300 Parser.getTok().is(AsmToken::Dollar) ||
4301 Parser.getTok().is(AsmToken::Integer)) {
4302 if (Parser.getTok().isNot(AsmToken::Integer))
4303 Parser.Lex(); // Eat the '#'.
4304 E = Parser.getTok().getLoc();
4306 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4307 const MCExpr *Offset;
4308 if (getParser().ParseExpression(Offset))
4311 // The expression has to be a constant. Memory references with relocations
4312 // don't come through here, as they use the <label> forms of the relevant
4314 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4316 return Error (E, "constant expression expected");
4318 // If the constant was #-0, represent it as INT32_MIN.
4319 int32_t Val = CE->getValue();
4320 if (isNegative && Val == 0)
4321 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4323 // Now we should have the closing ']'
4324 E = Parser.getTok().getLoc();
4325 if (Parser.getTok().isNot(AsmToken::RBrac))
4326 return Error(E, "']' expected");
4327 Parser.Lex(); // Eat right bracket token.
4329 // Don't worry about range checking the value here. That's handled by
4330 // the is*() predicates.
4331 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4332 ARM_AM::no_shift, 0, 0,
4335 // If there's a pre-indexing writeback marker, '!', just add it as a token
4337 if (Parser.getTok().is(AsmToken::Exclaim)) {
4338 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4339 Parser.Lex(); // Eat the '!'.
4345 // The register offset is optionally preceded by a '+' or '-'
4346 bool isNegative = false;
4347 if (Parser.getTok().is(AsmToken::Minus)) {
4349 Parser.Lex(); // Eat the '-'.
4350 } else if (Parser.getTok().is(AsmToken::Plus)) {
4352 Parser.Lex(); // Eat the '+'.
4355 E = Parser.getTok().getLoc();
4356 int OffsetRegNum = tryParseRegister();
4357 if (OffsetRegNum == -1)
4358 return Error(E, "register expected");
4360 // If there's a shift operator, handle it.
4361 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4362 unsigned ShiftImm = 0;
4363 if (Parser.getTok().is(AsmToken::Comma)) {
4364 Parser.Lex(); // Eat the ','.
4365 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4369 // Now we should have the closing ']'
4370 E = Parser.getTok().getLoc();
4371 if (Parser.getTok().isNot(AsmToken::RBrac))
4372 return Error(E, "']' expected");
4373 Parser.Lex(); // Eat right bracket token.
4375 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4376 ShiftType, ShiftImm, 0, isNegative,
4379 // If there's a pre-indexing writeback marker, '!', just add it as a token
4381 if (Parser.getTok().is(AsmToken::Exclaim)) {
4382 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4383 Parser.Lex(); // Eat the '!'.
4389 /// parseMemRegOffsetShift - one of these two:
4390 /// ( lsl | lsr | asr | ror ) , # shift_amount
4392 /// return true if it parses a shift otherwise it returns false.
4393 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4395 SMLoc Loc = Parser.getTok().getLoc();
4396 const AsmToken &Tok = Parser.getTok();
4397 if (Tok.isNot(AsmToken::Identifier))
4399 StringRef ShiftName = Tok.getString();
4400 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4401 ShiftName == "asl" || ShiftName == "ASL")
4403 else if (ShiftName == "lsr" || ShiftName == "LSR")
4405 else if (ShiftName == "asr" || ShiftName == "ASR")
4407 else if (ShiftName == "ror" || ShiftName == "ROR")
4409 else if (ShiftName == "rrx" || ShiftName == "RRX")
4412 return Error(Loc, "illegal shift operator");
4413 Parser.Lex(); // Eat shift type token.
4415 // rrx stands alone.
4417 if (St != ARM_AM::rrx) {
4418 Loc = Parser.getTok().getLoc();
4419 // A '#' and a shift amount.
4420 const AsmToken &HashTok = Parser.getTok();
4421 if (HashTok.isNot(AsmToken::Hash) &&
4422 HashTok.isNot(AsmToken::Dollar))
4423 return Error(HashTok.getLoc(), "'#' expected");
4424 Parser.Lex(); // Eat hash token.
4427 if (getParser().ParseExpression(Expr))
4429 // Range check the immediate.
4430 // lsl, ror: 0 <= imm <= 31
4431 // lsr, asr: 0 <= imm <= 32
4432 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4434 return Error(Loc, "shift amount must be an immediate");
4435 int64_t Imm = CE->getValue();
4437 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4438 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4439 return Error(Loc, "immediate shift value out of range");
4440 // If <ShiftTy> #0, turn it into a no_shift.
4443 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4452 /// parseFPImm - A floating point immediate expression operand.
4453 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4454 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4455 // Anything that can accept a floating point constant as an operand
4456 // needs to go through here, as the regular ParseExpression is
4459 // This routine still creates a generic Immediate operand, containing
4460 // a bitcast of the 64-bit floating point value. The various operands
4461 // that accept floats can check whether the value is valid for them
4462 // via the standard is*() predicates.
4464 SMLoc S = Parser.getTok().getLoc();
4466 if (Parser.getTok().isNot(AsmToken::Hash) &&
4467 Parser.getTok().isNot(AsmToken::Dollar))
4468 return MatchOperand_NoMatch;
4470 // Disambiguate the VMOV forms that can accept an FP immediate.
4471 // vmov.f32 <sreg>, #imm
4472 // vmov.f64 <dreg>, #imm
4473 // vmov.f32 <dreg>, #imm @ vector f32x2
4474 // vmov.f32 <qreg>, #imm @ vector f32x4
4476 // There are also the NEON VMOV instructions which expect an
4477 // integer constant. Make sure we don't try to parse an FPImm
4479 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4480 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4481 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4482 TyOp->getToken() != ".f64"))
4483 return MatchOperand_NoMatch;
4485 Parser.Lex(); // Eat the '#'.
4487 // Handle negation, as that still comes through as a separate token.
4488 bool isNegative = false;
4489 if (Parser.getTok().is(AsmToken::Minus)) {
4493 const AsmToken &Tok = Parser.getTok();
4494 SMLoc Loc = Tok.getLoc();
4495 if (Tok.is(AsmToken::Real)) {
4496 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4497 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4498 // If we had a '-' in front, toggle the sign bit.
4499 IntVal ^= (uint64_t)isNegative << 31;
4500 Parser.Lex(); // Eat the token.
4501 Operands.push_back(ARMOperand::CreateImm(
4502 MCConstantExpr::Create(IntVal, getContext()),
4503 S, Parser.getTok().getLoc()));
4504 return MatchOperand_Success;
4506 // Also handle plain integers. Instructions which allow floating point
4507 // immediates also allow a raw encoded 8-bit value.
4508 if (Tok.is(AsmToken::Integer)) {
4509 int64_t Val = Tok.getIntVal();
4510 Parser.Lex(); // Eat the token.
4511 if (Val > 255 || Val < 0) {
4512 Error(Loc, "encoded floating point value out of range");
4513 return MatchOperand_ParseFail;
4515 double RealVal = ARM_AM::getFPImmFloat(Val);
4516 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4517 Operands.push_back(ARMOperand::CreateImm(
4518 MCConstantExpr::Create(Val, getContext()), S,
4519 Parser.getTok().getLoc()));
4520 return MatchOperand_Success;
4523 Error(Loc, "invalid floating point immediate");
4524 return MatchOperand_ParseFail;
4527 /// Parse a arm instruction operand. For now this parses the operand regardless
4528 /// of the mnemonic.
4529 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4530 StringRef Mnemonic) {
4533 // Check if the current operand has a custom associated parser, if so, try to
4534 // custom parse the operand, or fallback to the general approach.
4535 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4536 if (ResTy == MatchOperand_Success)
4538 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4539 // there was a match, but an error occurred, in which case, just return that
4540 // the operand parsing failed.
4541 if (ResTy == MatchOperand_ParseFail)
4544 switch (getLexer().getKind()) {
4546 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4548 case AsmToken::Identifier: {
4549 if (!tryParseRegisterWithWriteBack(Operands))
4551 int Res = tryParseShiftRegister(Operands);
4552 if (Res == 0) // success
4554 else if (Res == -1) // irrecoverable error
4556 // If this is VMRS, check for the apsr_nzcv operand.
4557 if (Mnemonic == "vmrs" &&
4558 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4559 S = Parser.getTok().getLoc();
4561 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4565 // Fall though for the Identifier case that is not a register or a
4568 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4569 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4570 case AsmToken::String: // quoted label names.
4571 case AsmToken::Dot: { // . as a branch target
4572 // This was not a register so parse other operands that start with an
4573 // identifier (like labels) as expressions and create them as immediates.
4574 const MCExpr *IdVal;
4575 S = Parser.getTok().getLoc();
4576 if (getParser().ParseExpression(IdVal))
4578 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4579 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4582 case AsmToken::LBrac:
4583 return parseMemory(Operands);
4584 case AsmToken::LCurly:
4585 return parseRegisterList(Operands);
4586 case AsmToken::Dollar:
4587 case AsmToken::Hash: {
4588 // #42 -> immediate.
4589 S = Parser.getTok().getLoc();
4592 if (Parser.getTok().isNot(AsmToken::Colon)) {
4593 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4594 const MCExpr *ImmVal;
4595 if (getParser().ParseExpression(ImmVal))
4597 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4599 int32_t Val = CE->getValue();
4600 if (isNegative && Val == 0)
4601 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4603 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4604 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4607 // w/ a ':' after the '#', it's just like a plain ':'.
4610 case AsmToken::Colon: {
4611 // ":lower16:" and ":upper16:" expression prefixes
4612 // FIXME: Check it's an expression prefix,
4613 // e.g. (FOO - :lower16:BAR) isn't legal.
4614 ARMMCExpr::VariantKind RefKind;
4615 if (parsePrefix(RefKind))
4618 const MCExpr *SubExprVal;
4619 if (getParser().ParseExpression(SubExprVal))
4622 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4624 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4625 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4631 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4632 // :lower16: and :upper16:.
4633 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4634 RefKind = ARMMCExpr::VK_ARM_None;
4636 // :lower16: and :upper16: modifiers
4637 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4638 Parser.Lex(); // Eat ':'
4640 if (getLexer().isNot(AsmToken::Identifier)) {
4641 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4645 StringRef IDVal = Parser.getTok().getIdentifier();
4646 if (IDVal == "lower16") {
4647 RefKind = ARMMCExpr::VK_ARM_LO16;
4648 } else if (IDVal == "upper16") {
4649 RefKind = ARMMCExpr::VK_ARM_HI16;
4651 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4656 if (getLexer().isNot(AsmToken::Colon)) {
4657 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4660 Parser.Lex(); // Eat the last ':'
4664 /// \brief Given a mnemonic, split out possible predication code and carry
4665 /// setting letters to form a canonical mnemonic and flags.
4667 // FIXME: Would be nice to autogen this.
4668 // FIXME: This is a bit of a maze of special cases.
4669 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4670 unsigned &PredicationCode,
4672 unsigned &ProcessorIMod,
4673 StringRef &ITMask) {
4674 PredicationCode = ARMCC::AL;
4675 CarrySetting = false;
4678 // Ignore some mnemonics we know aren't predicated forms.
4680 // FIXME: Would be nice to autogen this.
4681 if ((Mnemonic == "movs" && isThumb()) ||
4682 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4683 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4684 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4685 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4686 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4687 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4688 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4689 Mnemonic == "fmuls")
4692 // First, split out any predication code. Ignore mnemonics we know aren't
4693 // predicated but do have a carry-set and so weren't caught above.
4694 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4695 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4696 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4697 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4698 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4699 .Case("eq", ARMCC::EQ)
4700 .Case("ne", ARMCC::NE)
4701 .Case("hs", ARMCC::HS)
4702 .Case("cs", ARMCC::HS)
4703 .Case("lo", ARMCC::LO)
4704 .Case("cc", ARMCC::LO)
4705 .Case("mi", ARMCC::MI)
4706 .Case("pl", ARMCC::PL)
4707 .Case("vs", ARMCC::VS)
4708 .Case("vc", ARMCC::VC)
4709 .Case("hi", ARMCC::HI)
4710 .Case("ls", ARMCC::LS)
4711 .Case("ge", ARMCC::GE)
4712 .Case("lt", ARMCC::LT)
4713 .Case("gt", ARMCC::GT)
4714 .Case("le", ARMCC::LE)
4715 .Case("al", ARMCC::AL)
4718 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4719 PredicationCode = CC;
4723 // Next, determine if we have a carry setting bit. We explicitly ignore all
4724 // the instructions we know end in 's'.
4725 if (Mnemonic.endswith("s") &&
4726 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4727 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4728 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4729 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4730 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4731 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4732 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4733 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4734 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4735 (Mnemonic == "movs" && isThumb()))) {
4736 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4737 CarrySetting = true;
4740 // The "cps" instruction can have a interrupt mode operand which is glued into
4741 // the mnemonic. Check if this is the case, split it and parse the imod op
4742 if (Mnemonic.startswith("cps")) {
4743 // Split out any imod code.
4745 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4746 .Case("ie", ARM_PROC::IE)
4747 .Case("id", ARM_PROC::ID)
4750 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4751 ProcessorIMod = IMod;
4755 // The "it" instruction has the condition mask on the end of the mnemonic.
4756 if (Mnemonic.startswith("it")) {
4757 ITMask = Mnemonic.slice(2, Mnemonic.size());
4758 Mnemonic = Mnemonic.slice(0, 2);
4764 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4765 /// inclusion of carry set or predication code operands.
4767 // FIXME: It would be nice to autogen this.
4769 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
4770 bool &CanAcceptPredicationCode) {
4771 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4772 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4773 Mnemonic == "add" || Mnemonic == "adc" ||
4774 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4775 Mnemonic == "orr" || Mnemonic == "mvn" ||
4776 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4777 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4778 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4779 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4780 Mnemonic == "mla" || Mnemonic == "smlal" ||
4781 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4782 CanAcceptCarrySet = true;
4784 CanAcceptCarrySet = false;
4786 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4787 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4788 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4789 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
4790 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4791 (Mnemonic == "clrex" && !isThumb()) ||
4792 (Mnemonic == "nop" && isThumbOne()) ||
4793 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4794 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4795 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
4796 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4798 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
4799 CanAcceptPredicationCode = false;
4801 CanAcceptPredicationCode = true;
4804 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
4805 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
4806 CanAcceptPredicationCode = false;
4810 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4811 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4812 // FIXME: This is all horribly hacky. We really need a better way to deal
4813 // with optional operands like this in the matcher table.
4815 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4816 // another does not. Specifically, the MOVW instruction does not. So we
4817 // special case it here and remove the defaulted (non-setting) cc_out
4818 // operand if that's the instruction we're trying to match.
4820 // We do this as post-processing of the explicit operands rather than just
4821 // conditionally adding the cc_out in the first place because we need
4822 // to check the type of the parsed immediate operand.
4823 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4824 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4825 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4826 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4829 // Register-register 'add' for thumb does not have a cc_out operand
4830 // when there are only two register operands.
4831 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4832 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4833 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4834 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4836 // Register-register 'add' for thumb does not have a cc_out operand
4837 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4838 // have to check the immediate range here since Thumb2 has a variant
4839 // that can handle a different range and has a cc_out operand.
4840 if (((isThumb() && Mnemonic == "add") ||
4841 (isThumbTwo() && Mnemonic == "sub")) &&
4842 Operands.size() == 6 &&
4843 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4844 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4845 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4846 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4847 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4848 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4850 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4851 // imm0_4095 variant. That's the least-preferred variant when
4852 // selecting via the generic "add" mnemonic, so to know that we
4853 // should remove the cc_out operand, we have to explicitly check that
4854 // it's not one of the other variants. Ugh.
4855 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4856 Operands.size() == 6 &&
4857 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4858 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4859 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4860 // Nest conditions rather than one big 'if' statement for readability.
4862 // If either register is a high reg, it's either one of the SP
4863 // variants (handled above) or a 32-bit encoding, so we just
4864 // check against T3. If the second register is the PC, this is an
4865 // alternate form of ADR, which uses encoding T4, so check for that too.
4866 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4867 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
4868 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4869 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4871 // If both registers are low, we're in an IT block, and the immediate is
4872 // in range, we should use encoding T1 instead, which has a cc_out.
4874 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4875 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4876 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4879 // Otherwise, we use encoding T4, which does not have a cc_out
4884 // The thumb2 multiply instruction doesn't have a CCOut register, so
4885 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4886 // use the 16-bit encoding or not.
4887 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4888 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4889 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4890 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4891 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4892 // If the registers aren't low regs, the destination reg isn't the
4893 // same as one of the source regs, or the cc_out operand is zero
4894 // outside of an IT block, we have to use the 32-bit encoding, so
4895 // remove the cc_out operand.
4896 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4897 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4898 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4900 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4901 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4902 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4903 static_cast<ARMOperand*>(Operands[4])->getReg())))
4906 // Also check the 'mul' syntax variant that doesn't specify an explicit
4907 // destination register.
4908 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4909 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4910 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4911 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4912 // If the registers aren't low regs or the cc_out operand is zero
4913 // outside of an IT block, we have to use the 32-bit encoding, so
4914 // remove the cc_out operand.
4915 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4916 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4922 // Register-register 'add/sub' for thumb does not have a cc_out operand
4923 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4924 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4925 // right, this will result in better diagnostics (which operand is off)
4927 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4928 (Operands.size() == 5 || Operands.size() == 6) &&
4929 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4930 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4931 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4932 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4933 (Operands.size() == 6 &&
4934 static_cast<ARMOperand*>(Operands[5])->isImm())))
4940 static bool isDataTypeToken(StringRef Tok) {
4941 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4942 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4943 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4944 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4945 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4946 Tok == ".f" || Tok == ".d";
4949 // FIXME: This bit should probably be handled via an explicit match class
4950 // in the .td files that matches the suffix instead of having it be
4951 // a literal string token the way it is now.
4952 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4953 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4956 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
4957 /// Parse an arm instruction mnemonic followed by its operands.
4958 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4960 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4961 // Apply mnemonic aliases before doing anything else, as the destination
4962 // mnemnonic may include suffices and we want to handle them normally.
4963 // The generic tblgen'erated code does this later, at the start of
4964 // MatchInstructionImpl(), but that's too late for aliases that include
4965 // any sort of suffix.
4966 unsigned AvailableFeatures = getAvailableFeatures();
4967 applyMnemonicAliases(Name, AvailableFeatures);
4969 // First check for the ARM-specific .req directive.
4970 if (Parser.getTok().is(AsmToken::Identifier) &&
4971 Parser.getTok().getIdentifier() == ".req") {
4972 parseDirectiveReq(Name, NameLoc);
4973 // We always return 'error' for this, as we're done with this
4974 // statement and don't need to match the 'instruction."
4978 // Create the leading tokens for the mnemonic, split by '.' characters.
4979 size_t Start = 0, Next = Name.find('.');
4980 StringRef Mnemonic = Name.slice(Start, Next);
4982 // Split out the predication code and carry setting flag from the mnemonic.
4983 unsigned PredicationCode;
4984 unsigned ProcessorIMod;
4987 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
4988 ProcessorIMod, ITMask);
4990 // In Thumb1, only the branch (B) instruction can be predicated.
4991 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4992 Parser.EatToEndOfStatement();
4993 return Error(NameLoc, "conditional execution not supported in Thumb1");
4996 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4998 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4999 // is the mask as it will be for the IT encoding if the conditional
5000 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5001 // where the conditional bit0 is zero, the instruction post-processing
5002 // will adjust the mask accordingly.
5003 if (Mnemonic == "it") {
5004 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5005 if (ITMask.size() > 3) {
5006 Parser.EatToEndOfStatement();
5007 return Error(Loc, "too many conditions on IT instruction");
5010 for (unsigned i = ITMask.size(); i != 0; --i) {
5011 char pos = ITMask[i - 1];
5012 if (pos != 't' && pos != 'e') {
5013 Parser.EatToEndOfStatement();
5014 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5017 if (ITMask[i - 1] == 't')
5020 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5023 // FIXME: This is all a pretty gross hack. We should automatically handle
5024 // optional operands like this via tblgen.
5026 // Next, add the CCOut and ConditionCode operands, if needed.
5028 // For mnemonics which can ever incorporate a carry setting bit or predication
5029 // code, our matching model involves us always generating CCOut and
5030 // ConditionCode operands to match the mnemonic "as written" and then we let
5031 // the matcher deal with finding the right instruction or generating an
5032 // appropriate error.
5033 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5034 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
5036 // If we had a carry-set on an instruction that can't do that, issue an
5038 if (!CanAcceptCarrySet && CarrySetting) {
5039 Parser.EatToEndOfStatement();
5040 return Error(NameLoc, "instruction '" + Mnemonic +
5041 "' can not set flags, but 's' suffix specified");
5043 // If we had a predication code on an instruction that can't do that, issue an
5045 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5046 Parser.EatToEndOfStatement();
5047 return Error(NameLoc, "instruction '" + Mnemonic +
5048 "' is not predicable, but condition code specified");
5051 // Add the carry setting operand, if necessary.
5052 if (CanAcceptCarrySet) {
5053 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5054 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5058 // Add the predication code operand, if necessary.
5059 if (CanAcceptPredicationCode) {
5060 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5062 Operands.push_back(ARMOperand::CreateCondCode(
5063 ARMCC::CondCodes(PredicationCode), Loc));
5066 // Add the processor imod operand, if necessary.
5067 if (ProcessorIMod) {
5068 Operands.push_back(ARMOperand::CreateImm(
5069 MCConstantExpr::Create(ProcessorIMod, getContext()),
5073 // Add the remaining tokens in the mnemonic.
5074 while (Next != StringRef::npos) {
5076 Next = Name.find('.', Start + 1);
5077 StringRef ExtraToken = Name.slice(Start, Next);
5079 // Some NEON instructions have an optional datatype suffix that is
5080 // completely ignored. Check for that.
5081 if (isDataTypeToken(ExtraToken) &&
5082 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5085 if (ExtraToken != ".n") {
5086 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5087 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5091 // Read the remaining operands.
5092 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5093 // Read the first operand.
5094 if (parseOperand(Operands, Mnemonic)) {
5095 Parser.EatToEndOfStatement();
5099 while (getLexer().is(AsmToken::Comma)) {
5100 Parser.Lex(); // Eat the comma.
5102 // Parse and remember the operand.
5103 if (parseOperand(Operands, Mnemonic)) {
5104 Parser.EatToEndOfStatement();
5110 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5111 SMLoc Loc = getLexer().getLoc();
5112 Parser.EatToEndOfStatement();
5113 return Error(Loc, "unexpected token in argument list");
5116 Parser.Lex(); // Consume the EndOfStatement
5118 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5119 // do and don't have a cc_out optional-def operand. With some spot-checks
5120 // of the operand list, we can figure out which variant we're trying to
5121 // parse and adjust accordingly before actually matching. We shouldn't ever
5122 // try to remove a cc_out operand that was explicitly set on the the
5123 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5124 // table driven matcher doesn't fit well with the ARM instruction set.
5125 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5126 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5127 Operands.erase(Operands.begin() + 1);
5131 // ARM mode 'blx' need special handling, as the register operand version
5132 // is predicable, but the label operand version is not. So, we can't rely
5133 // on the Mnemonic based checking to correctly figure out when to put
5134 // a k_CondCode operand in the list. If we're trying to match the label
5135 // version, remove the k_CondCode operand here.
5136 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5137 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5138 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5139 Operands.erase(Operands.begin() + 1);
5143 // The vector-compare-to-zero instructions have a literal token "#0" at
5144 // the end that comes to here as an immediate operand. Convert it to a
5145 // token to play nicely with the matcher.
5146 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5147 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5148 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5149 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5150 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5151 if (CE && CE->getValue() == 0) {
5152 Operands.erase(Operands.begin() + 5);
5153 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5157 // VCMP{E} does the same thing, but with a different operand count.
5158 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5159 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5160 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5161 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5162 if (CE && CE->getValue() == 0) {
5163 Operands.erase(Operands.begin() + 4);
5164 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5168 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
5169 // end. Convert it to a token here. Take care not to convert those
5170 // that should hit the Thumb2 encoding.
5171 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
5172 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5173 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5174 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5175 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5177 if (CE && CE->getValue() == 0 &&
5179 // The cc_out operand matches the IT block.
5180 ((inITBlock() != CarrySetting) &&
5181 // Neither register operand is a high register.
5182 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5183 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
5184 Operands.erase(Operands.begin() + 5);
5185 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5193 // Validate context-sensitive operand constraints.
5195 // return 'true' if register list contains non-low GPR registers,
5196 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5197 // 'containsReg' to true.
5198 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5199 unsigned HiReg, bool &containsReg) {
5200 containsReg = false;
5201 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5202 unsigned OpReg = Inst.getOperand(i).getReg();
5205 // Anything other than a low register isn't legal here.
5206 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5212 // Check if the specified regisgter is in the register list of the inst,
5213 // starting at the indicated operand number.
5214 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5215 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5216 unsigned OpReg = Inst.getOperand(i).getReg();
5223 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5224 // the ARMInsts array) instead. Getting that here requires awkward
5225 // API changes, though. Better way?
5227 extern const MCInstrDesc ARMInsts[];
5229 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
5230 return ARMInsts[Opcode];
5233 // FIXME: We would really like to be able to tablegen'erate this.
5235 validateInstruction(MCInst &Inst,
5236 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5237 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
5238 SMLoc Loc = Operands[0]->getStartLoc();
5239 // Check the IT block state first.
5240 // NOTE: BKPT instruction has the interesting property of being
5241 // allowed in IT blocks, but not being predicable. It just always
5243 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5244 Inst.getOpcode() != ARM::BKPT) {
5246 if (ITState.FirstCond)
5247 ITState.FirstCond = false;
5249 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5250 // The instruction must be predicable.
5251 if (!MCID.isPredicable())
5252 return Error(Loc, "instructions in IT block must be predicable");
5253 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5254 unsigned ITCond = bit ? ITState.Cond :
5255 ARMCC::getOppositeCondition(ITState.Cond);
5256 if (Cond != ITCond) {
5257 // Find the condition code Operand to get its SMLoc information.
5259 for (unsigned i = 1; i < Operands.size(); ++i)
5260 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5261 CondLoc = Operands[i]->getStartLoc();
5262 return Error(CondLoc, "incorrect condition in IT block; got '" +
5263 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5264 "', but expected '" +
5265 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5267 // Check for non-'al' condition codes outside of the IT block.
5268 } else if (isThumbTwo() && MCID.isPredicable() &&
5269 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5270 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5271 Inst.getOpcode() != ARM::t2B)
5272 return Error(Loc, "predicated instructions must be in IT block");
5274 switch (Inst.getOpcode()) {
5277 case ARM::LDRD_POST:
5279 // Rt2 must be Rt + 1.
5280 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5281 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5283 return Error(Operands[3]->getStartLoc(),
5284 "destination operands must be sequential");
5288 // Rt2 must be Rt + 1.
5289 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5290 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5292 return Error(Operands[3]->getStartLoc(),
5293 "source operands must be sequential");
5297 case ARM::STRD_POST:
5299 // Rt2 must be Rt + 1.
5300 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5301 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5303 return Error(Operands[3]->getStartLoc(),
5304 "source operands must be sequential");
5309 // width must be in range [1, 32-lsb]
5310 unsigned lsb = Inst.getOperand(2).getImm();
5311 unsigned widthm1 = Inst.getOperand(3).getImm();
5312 if (widthm1 >= 32 - lsb)
5313 return Error(Operands[5]->getStartLoc(),
5314 "bitfield width must be in range [1,32-lsb]");
5318 // If we're parsing Thumb2, the .w variant is available and handles
5319 // most cases that are normally illegal for a Thumb1 LDM
5320 // instruction. We'll make the transformation in processInstruction()
5323 // Thumb LDM instructions are writeback iff the base register is not
5324 // in the register list.
5325 unsigned Rn = Inst.getOperand(0).getReg();
5326 bool hasWritebackToken =
5327 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5328 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5329 bool listContainsBase;
5330 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5331 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5332 "registers must be in range r0-r7");
5333 // If we should have writeback, then there should be a '!' token.
5334 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5335 return Error(Operands[2]->getStartLoc(),
5336 "writeback operator '!' expected");
5337 // If we should not have writeback, there must not be a '!'. This is
5338 // true even for the 32-bit wide encodings.
5339 if (listContainsBase && hasWritebackToken)
5340 return Error(Operands[3]->getStartLoc(),
5341 "writeback operator '!' not allowed when base register "
5342 "in register list");
5346 case ARM::t2LDMIA_UPD: {
5347 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5348 return Error(Operands[4]->getStartLoc(),
5349 "writeback operator '!' not allowed when base register "
5350 "in register list");
5354 // The second source operand must be the same register as the destination
5357 // In this case, we must directly check the parsed operands because the
5358 // cvtThumbMultiply() function is written in such a way that it guarantees
5359 // this first statement is always true for the new Inst. Essentially, the
5360 // destination is unconditionally copied into the second source operand
5361 // without checking to see if it matches what we actually parsed.
5362 if (Operands.size() == 6 &&
5363 (((ARMOperand*)Operands[3])->getReg() !=
5364 ((ARMOperand*)Operands[5])->getReg()) &&
5365 (((ARMOperand*)Operands[3])->getReg() !=
5366 ((ARMOperand*)Operands[4])->getReg())) {
5367 return Error(Operands[3]->getStartLoc(),
5368 "destination register must match source register");
5372 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5373 // so only issue a diagnostic for thumb1. The instructions will be
5374 // switched to the t2 encodings in processInstruction() if necessary.
5376 bool listContainsBase;
5377 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5379 return Error(Operands[2]->getStartLoc(),
5380 "registers must be in range r0-r7 or pc");
5384 bool listContainsBase;
5385 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5387 return Error(Operands[2]->getStartLoc(),
5388 "registers must be in range r0-r7 or lr");
5391 case ARM::tSTMIA_UPD: {
5392 bool listContainsBase;
5393 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5394 return Error(Operands[4]->getStartLoc(),
5395 "registers must be in range r0-r7");
5398 case ARM::tADDrSP: {
5399 // If the non-SP source operand and the destination operand are not the
5400 // same, we need thumb2 (for the wide encoding), or we have an error.
5401 if (!isThumbTwo() &&
5402 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5403 return Error(Operands[4]->getStartLoc(),
5404 "source register must be the same as destination");
5413 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5415 default: llvm_unreachable("unexpected opcode!");
5417 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5418 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5419 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5420 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5421 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5422 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5423 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5424 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5425 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5428 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5429 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5430 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5431 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5432 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5434 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5435 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5436 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5437 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5438 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5440 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5441 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5442 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5443 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5444 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5447 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5448 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5449 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5450 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5451 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5452 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5453 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5454 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5455 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5456 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5457 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5458 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5459 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5460 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5461 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5464 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5465 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5466 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5467 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5468 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5469 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5470 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5471 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5472 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5473 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5474 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5475 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5476 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5477 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5478 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5479 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5480 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5481 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5484 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5485 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5486 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5487 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5488 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5489 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5490 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5491 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5492 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5493 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5494 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5495 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5496 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5497 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5498 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5501 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5502 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5503 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5504 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5505 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5506 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5507 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5508 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5509 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5510 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5511 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5512 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5513 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5514 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5515 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5516 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5517 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5518 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5522 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5524 default: llvm_unreachable("unexpected opcode!");
5526 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5527 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5528 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5529 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5530 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5531 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5532 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5533 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5534 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5537 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5538 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5539 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5540 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5541 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5542 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5543 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5544 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5545 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5546 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5547 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5548 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5549 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5550 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5551 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5554 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5555 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5556 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5557 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5558 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5559 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5560 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5561 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5562 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5563 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5564 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5565 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5566 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5567 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5568 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5569 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5570 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5571 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5574 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5575 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5576 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5577 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5578 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5579 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5580 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5581 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5582 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5583 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5584 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5585 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5586 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5587 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5588 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5591 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5592 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5593 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5594 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5595 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5596 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5597 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5598 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5599 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5600 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5601 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5602 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5603 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5604 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5605 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5606 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5607 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5608 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5611 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5612 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5613 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5614 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5615 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5616 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5617 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5618 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5619 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5620 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5621 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5622 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5623 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5624 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5625 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5628 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5629 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5630 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5631 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5632 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5633 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5634 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5635 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5636 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5637 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5638 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5639 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5640 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5641 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5642 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5643 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5644 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5645 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5648 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5649 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5650 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5651 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5652 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5653 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5654 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5655 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5656 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5657 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5658 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5659 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5660 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5661 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5662 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5663 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5664 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5665 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5670 processInstruction(MCInst &Inst,
5671 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5672 switch (Inst.getOpcode()) {
5673 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5675 if (Inst.getOperand(1).getReg() != ARM::PC ||
5676 Inst.getOperand(5).getReg() != 0)
5679 TmpInst.setOpcode(ARM::ADR);
5680 TmpInst.addOperand(Inst.getOperand(0));
5681 TmpInst.addOperand(Inst.getOperand(2));
5682 TmpInst.addOperand(Inst.getOperand(3));
5683 TmpInst.addOperand(Inst.getOperand(4));
5687 // Aliases for alternate PC+imm syntax of LDR instructions.
5688 case ARM::t2LDRpcrel:
5689 Inst.setOpcode(ARM::t2LDRpci);
5691 case ARM::t2LDRBpcrel:
5692 Inst.setOpcode(ARM::t2LDRBpci);
5694 case ARM::t2LDRHpcrel:
5695 Inst.setOpcode(ARM::t2LDRHpci);
5697 case ARM::t2LDRSBpcrel:
5698 Inst.setOpcode(ARM::t2LDRSBpci);
5700 case ARM::t2LDRSHpcrel:
5701 Inst.setOpcode(ARM::t2LDRSHpci);
5703 // Handle NEON VST complex aliases.
5704 case ARM::VST1LNdWB_register_Asm_8:
5705 case ARM::VST1LNdWB_register_Asm_16:
5706 case ARM::VST1LNdWB_register_Asm_32: {
5708 // Shuffle the operands around so the lane index operand is in the
5711 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5712 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5713 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5714 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5715 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5716 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5717 TmpInst.addOperand(Inst.getOperand(1)); // lane
5718 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5719 TmpInst.addOperand(Inst.getOperand(6));
5724 case ARM::VST2LNdWB_register_Asm_8:
5725 case ARM::VST2LNdWB_register_Asm_16:
5726 case ARM::VST2LNdWB_register_Asm_32:
5727 case ARM::VST2LNqWB_register_Asm_16:
5728 case ARM::VST2LNqWB_register_Asm_32: {
5730 // Shuffle the operands around so the lane index operand is in the
5733 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5734 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5735 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5736 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5737 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5738 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5739 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5741 TmpInst.addOperand(Inst.getOperand(1)); // lane
5742 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5743 TmpInst.addOperand(Inst.getOperand(6));
5748 case ARM::VST3LNdWB_register_Asm_8:
5749 case ARM::VST3LNdWB_register_Asm_16:
5750 case ARM::VST3LNdWB_register_Asm_32:
5751 case ARM::VST3LNqWB_register_Asm_16:
5752 case ARM::VST3LNqWB_register_Asm_32: {
5754 // Shuffle the operands around so the lane index operand is in the
5757 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5758 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5759 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5760 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5761 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5762 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5763 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5765 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5767 TmpInst.addOperand(Inst.getOperand(1)); // lane
5768 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5769 TmpInst.addOperand(Inst.getOperand(6));
5774 case ARM::VST4LNdWB_register_Asm_8:
5775 case ARM::VST4LNdWB_register_Asm_16:
5776 case ARM::VST4LNdWB_register_Asm_32:
5777 case ARM::VST4LNqWB_register_Asm_16:
5778 case ARM::VST4LNqWB_register_Asm_32: {
5780 // Shuffle the operands around so the lane index operand is in the
5783 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5784 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5785 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5786 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5787 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5788 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5789 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5791 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5793 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5795 TmpInst.addOperand(Inst.getOperand(1)); // lane
5796 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5797 TmpInst.addOperand(Inst.getOperand(6));
5802 case ARM::VST1LNdWB_fixed_Asm_8:
5803 case ARM::VST1LNdWB_fixed_Asm_16:
5804 case ARM::VST1LNdWB_fixed_Asm_32: {
5806 // Shuffle the operands around so the lane index operand is in the
5809 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5810 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5811 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5812 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5813 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5814 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5815 TmpInst.addOperand(Inst.getOperand(1)); // lane
5816 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5817 TmpInst.addOperand(Inst.getOperand(5));
5822 case ARM::VST2LNdWB_fixed_Asm_8:
5823 case ARM::VST2LNdWB_fixed_Asm_16:
5824 case ARM::VST2LNdWB_fixed_Asm_32:
5825 case ARM::VST2LNqWB_fixed_Asm_16:
5826 case ARM::VST2LNqWB_fixed_Asm_32: {
5828 // Shuffle the operands around so the lane index operand is in the
5831 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5832 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5833 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5834 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5835 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5836 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5837 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5839 TmpInst.addOperand(Inst.getOperand(1)); // lane
5840 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5841 TmpInst.addOperand(Inst.getOperand(5));
5846 case ARM::VST3LNdWB_fixed_Asm_8:
5847 case ARM::VST3LNdWB_fixed_Asm_16:
5848 case ARM::VST3LNdWB_fixed_Asm_32:
5849 case ARM::VST3LNqWB_fixed_Asm_16:
5850 case ARM::VST3LNqWB_fixed_Asm_32: {
5852 // Shuffle the operands around so the lane index operand is in the
5855 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5856 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5857 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5858 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5859 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5860 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5861 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5863 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5865 TmpInst.addOperand(Inst.getOperand(1)); // lane
5866 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5867 TmpInst.addOperand(Inst.getOperand(5));
5872 case ARM::VST4LNdWB_fixed_Asm_8:
5873 case ARM::VST4LNdWB_fixed_Asm_16:
5874 case ARM::VST4LNdWB_fixed_Asm_32:
5875 case ARM::VST4LNqWB_fixed_Asm_16:
5876 case ARM::VST4LNqWB_fixed_Asm_32: {
5878 // Shuffle the operands around so the lane index operand is in the
5881 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5882 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5883 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5884 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5885 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5886 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5887 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5889 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5891 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5893 TmpInst.addOperand(Inst.getOperand(1)); // lane
5894 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5895 TmpInst.addOperand(Inst.getOperand(5));
5900 case ARM::VST1LNdAsm_8:
5901 case ARM::VST1LNdAsm_16:
5902 case ARM::VST1LNdAsm_32: {
5904 // Shuffle the operands around so the lane index operand is in the
5907 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5908 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5909 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5910 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5911 TmpInst.addOperand(Inst.getOperand(1)); // lane
5912 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5913 TmpInst.addOperand(Inst.getOperand(5));
5918 case ARM::VST2LNdAsm_8:
5919 case ARM::VST2LNdAsm_16:
5920 case ARM::VST2LNdAsm_32:
5921 case ARM::VST2LNqAsm_16:
5922 case ARM::VST2LNqAsm_32: {
5924 // Shuffle the operands around so the lane index operand is in the
5927 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5928 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5929 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5930 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5931 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5933 TmpInst.addOperand(Inst.getOperand(1)); // lane
5934 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5935 TmpInst.addOperand(Inst.getOperand(5));
5940 case ARM::VST3LNdAsm_8:
5941 case ARM::VST3LNdAsm_16:
5942 case ARM::VST3LNdAsm_32:
5943 case ARM::VST3LNqAsm_16:
5944 case ARM::VST3LNqAsm_32: {
5946 // Shuffle the operands around so the lane index operand is in the
5949 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5950 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5951 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5952 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5953 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5955 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5957 TmpInst.addOperand(Inst.getOperand(1)); // lane
5958 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5959 TmpInst.addOperand(Inst.getOperand(5));
5964 case ARM::VST4LNdAsm_8:
5965 case ARM::VST4LNdAsm_16:
5966 case ARM::VST4LNdAsm_32:
5967 case ARM::VST4LNqAsm_16:
5968 case ARM::VST4LNqAsm_32: {
5970 // Shuffle the operands around so the lane index operand is in the
5973 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5974 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5975 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5976 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5977 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5979 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5981 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5983 TmpInst.addOperand(Inst.getOperand(1)); // lane
5984 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5985 TmpInst.addOperand(Inst.getOperand(5));
5990 // Handle NEON VLD complex aliases.
5991 case ARM::VLD1LNdWB_register_Asm_8:
5992 case ARM::VLD1LNdWB_register_Asm_16:
5993 case ARM::VLD1LNdWB_register_Asm_32: {
5995 // Shuffle the operands around so the lane index operand is in the
5998 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5999 TmpInst.addOperand(Inst.getOperand(0)); // Vd
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(Inst.getOperand(1)); // lane
6006 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6007 TmpInst.addOperand(Inst.getOperand(6));
6012 case ARM::VLD2LNdWB_register_Asm_8:
6013 case ARM::VLD2LNdWB_register_Asm_16:
6014 case ARM::VLD2LNdWB_register_Asm_32:
6015 case ARM::VLD2LNqWB_register_Asm_16:
6016 case ARM::VLD2LNqWB_register_Asm_32: {
6018 // Shuffle the operands around so the lane index operand is in the
6021 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6022 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6023 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6025 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6026 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6027 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6028 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6029 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6030 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6032 TmpInst.addOperand(Inst.getOperand(1)); // lane
6033 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6034 TmpInst.addOperand(Inst.getOperand(6));
6039 case ARM::VLD3LNdWB_register_Asm_8:
6040 case ARM::VLD3LNdWB_register_Asm_16:
6041 case ARM::VLD3LNdWB_register_Asm_32:
6042 case ARM::VLD3LNqWB_register_Asm_16:
6043 case ARM::VLD3LNqWB_register_Asm_32: {
6045 // Shuffle the operands around so the lane index operand is in the
6048 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6049 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6050 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6052 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6054 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6055 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6056 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6057 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6058 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6059 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6061 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6063 TmpInst.addOperand(Inst.getOperand(1)); // lane
6064 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6065 TmpInst.addOperand(Inst.getOperand(6));
6070 case ARM::VLD4LNdWB_register_Asm_8:
6071 case ARM::VLD4LNdWB_register_Asm_16:
6072 case ARM::VLD4LNdWB_register_Asm_32:
6073 case ARM::VLD4LNqWB_register_Asm_16:
6074 case ARM::VLD4LNqWB_register_Asm_32: {
6076 // Shuffle the operands around so the lane index operand is in the
6079 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6080 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6081 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6083 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6085 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6087 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6088 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6089 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6090 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6091 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6092 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6094 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6096 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6098 TmpInst.addOperand(Inst.getOperand(1)); // lane
6099 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6100 TmpInst.addOperand(Inst.getOperand(6));
6105 case ARM::VLD1LNdWB_fixed_Asm_8:
6106 case ARM::VLD1LNdWB_fixed_Asm_16:
6107 case ARM::VLD1LNdWB_fixed_Asm_32: {
6109 // Shuffle the operands around so the lane index operand is in the
6112 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6113 TmpInst.addOperand(Inst.getOperand(0)); // Vd
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(Inst.getOperand(1)); // lane
6120 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6121 TmpInst.addOperand(Inst.getOperand(5));
6126 case ARM::VLD2LNdWB_fixed_Asm_8:
6127 case ARM::VLD2LNdWB_fixed_Asm_16:
6128 case ARM::VLD2LNdWB_fixed_Asm_32:
6129 case ARM::VLD2LNqWB_fixed_Asm_16:
6130 case ARM::VLD2LNqWB_fixed_Asm_32: {
6132 // Shuffle the operands around so the lane index operand is in the
6135 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6136 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6137 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6139 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6140 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6141 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6142 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6143 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6144 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6146 TmpInst.addOperand(Inst.getOperand(1)); // lane
6147 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6148 TmpInst.addOperand(Inst.getOperand(5));
6153 case ARM::VLD3LNdWB_fixed_Asm_8:
6154 case ARM::VLD3LNdWB_fixed_Asm_16:
6155 case ARM::VLD3LNdWB_fixed_Asm_32:
6156 case ARM::VLD3LNqWB_fixed_Asm_16:
6157 case ARM::VLD3LNqWB_fixed_Asm_32: {
6159 // Shuffle the operands around so the lane index operand is in the
6162 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6163 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6164 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6166 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6168 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6169 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6170 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6171 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6172 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6173 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6175 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6177 TmpInst.addOperand(Inst.getOperand(1)); // lane
6178 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6179 TmpInst.addOperand(Inst.getOperand(5));
6184 case ARM::VLD4LNdWB_fixed_Asm_8:
6185 case ARM::VLD4LNdWB_fixed_Asm_16:
6186 case ARM::VLD4LNdWB_fixed_Asm_32:
6187 case ARM::VLD4LNqWB_fixed_Asm_16:
6188 case ARM::VLD4LNqWB_fixed_Asm_32: {
6190 // Shuffle the operands around so the lane index operand is in the
6193 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6194 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6195 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6197 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6199 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6201 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6202 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6203 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6204 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6205 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6206 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6208 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6210 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6212 TmpInst.addOperand(Inst.getOperand(1)); // lane
6213 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6214 TmpInst.addOperand(Inst.getOperand(5));
6219 case ARM::VLD1LNdAsm_8:
6220 case ARM::VLD1LNdAsm_16:
6221 case ARM::VLD1LNdAsm_32: {
6223 // Shuffle the operands around so the lane index operand is in the
6226 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6227 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6228 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6229 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6230 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6231 TmpInst.addOperand(Inst.getOperand(1)); // lane
6232 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6233 TmpInst.addOperand(Inst.getOperand(5));
6238 case ARM::VLD2LNdAsm_8:
6239 case ARM::VLD2LNdAsm_16:
6240 case ARM::VLD2LNdAsm_32:
6241 case ARM::VLD2LNqAsm_16:
6242 case ARM::VLD2LNqAsm_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(Inst.getOperand(2)); // Rn
6252 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6253 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6254 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6256 TmpInst.addOperand(Inst.getOperand(1)); // lane
6257 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6258 TmpInst.addOperand(Inst.getOperand(5));
6263 case ARM::VLD3LNdAsm_8:
6264 case ARM::VLD3LNdAsm_16:
6265 case ARM::VLD3LNdAsm_32:
6266 case ARM::VLD3LNqAsm_16:
6267 case ARM::VLD3LNqAsm_32: {
6269 // Shuffle the operands around so the lane index operand is in the
6272 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6273 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6274 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6276 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6278 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6279 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6280 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6281 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6283 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6285 TmpInst.addOperand(Inst.getOperand(1)); // lane
6286 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6287 TmpInst.addOperand(Inst.getOperand(5));
6292 case ARM::VLD4LNdAsm_8:
6293 case ARM::VLD4LNdAsm_16:
6294 case ARM::VLD4LNdAsm_32:
6295 case ARM::VLD4LNqAsm_16:
6296 case ARM::VLD4LNqAsm_32: {
6298 // Shuffle the operands around so the lane index operand is in the
6301 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6302 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6303 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6305 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6307 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6309 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6310 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6311 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6312 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6314 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6316 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6318 TmpInst.addOperand(Inst.getOperand(1)); // lane
6319 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6320 TmpInst.addOperand(Inst.getOperand(5));
6325 // VLD3DUP single 3-element structure to all lanes instructions.
6326 case ARM::VLD3DUPdAsm_8:
6327 case ARM::VLD3DUPdAsm_16:
6328 case ARM::VLD3DUPdAsm_32:
6329 case ARM::VLD3DUPqAsm_8:
6330 case ARM::VLD3DUPqAsm_16:
6331 case ARM::VLD3DUPqAsm_32: {
6334 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6335 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6336 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6338 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6340 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6341 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6342 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6343 TmpInst.addOperand(Inst.getOperand(4));
6348 case ARM::VLD3DUPdWB_fixed_Asm_8:
6349 case ARM::VLD3DUPdWB_fixed_Asm_16:
6350 case ARM::VLD3DUPdWB_fixed_Asm_32:
6351 case ARM::VLD3DUPqWB_fixed_Asm_8:
6352 case ARM::VLD3DUPqWB_fixed_Asm_16:
6353 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6356 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6357 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6360 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6362 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6363 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6364 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6365 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6366 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6367 TmpInst.addOperand(Inst.getOperand(4));
6372 case ARM::VLD3DUPdWB_register_Asm_8:
6373 case ARM::VLD3DUPdWB_register_Asm_16:
6374 case ARM::VLD3DUPdWB_register_Asm_32:
6375 case ARM::VLD3DUPqWB_register_Asm_8:
6376 case ARM::VLD3DUPqWB_register_Asm_16:
6377 case ARM::VLD3DUPqWB_register_Asm_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(1)); // Rn_wb == tied Rn
6388 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6389 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6390 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6391 TmpInst.addOperand(Inst.getOperand(5));
6396 // VLD3 multiple 3-element structure instructions.
6397 case ARM::VLD3dAsm_8:
6398 case ARM::VLD3dAsm_16:
6399 case ARM::VLD3dAsm_32:
6400 case ARM::VLD3qAsm_8:
6401 case ARM::VLD3qAsm_16:
6402 case ARM::VLD3qAsm_32: {
6405 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6406 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6407 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6409 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6411 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6412 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6413 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6414 TmpInst.addOperand(Inst.getOperand(4));
6419 case ARM::VLD3dWB_fixed_Asm_8:
6420 case ARM::VLD3dWB_fixed_Asm_16:
6421 case ARM::VLD3dWB_fixed_Asm_32:
6422 case ARM::VLD3qWB_fixed_Asm_8:
6423 case ARM::VLD3qWB_fixed_Asm_16:
6424 case ARM::VLD3qWB_fixed_Asm_32: {
6427 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6428 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6429 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6431 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6433 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6434 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6435 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6436 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6437 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6438 TmpInst.addOperand(Inst.getOperand(4));
6443 case ARM::VLD3dWB_register_Asm_8:
6444 case ARM::VLD3dWB_register_Asm_16:
6445 case ARM::VLD3dWB_register_Asm_32:
6446 case ARM::VLD3qWB_register_Asm_8:
6447 case ARM::VLD3qWB_register_Asm_16:
6448 case ARM::VLD3qWB_register_Asm_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(Inst.getOperand(1)); // Rn
6458 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6459 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6460 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6461 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6462 TmpInst.addOperand(Inst.getOperand(5));
6467 // VLD4DUP single 3-element structure to all lanes instructions.
6468 case ARM::VLD4DUPdAsm_8:
6469 case ARM::VLD4DUPdAsm_16:
6470 case ARM::VLD4DUPdAsm_32:
6471 case ARM::VLD4DUPqAsm_8:
6472 case ARM::VLD4DUPqAsm_16:
6473 case ARM::VLD4DUPqAsm_32: {
6476 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6477 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6478 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6480 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6482 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6484 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6485 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6486 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6487 TmpInst.addOperand(Inst.getOperand(4));
6492 case ARM::VLD4DUPdWB_fixed_Asm_8:
6493 case ARM::VLD4DUPdWB_fixed_Asm_16:
6494 case ARM::VLD4DUPdWB_fixed_Asm_32:
6495 case ARM::VLD4DUPqWB_fixed_Asm_8:
6496 case ARM::VLD4DUPqWB_fixed_Asm_16:
6497 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6500 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6501 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6502 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6504 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6506 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6508 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6509 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6510 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6511 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6512 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6513 TmpInst.addOperand(Inst.getOperand(4));
6518 case ARM::VLD4DUPdWB_register_Asm_8:
6519 case ARM::VLD4DUPdWB_register_Asm_16:
6520 case ARM::VLD4DUPdWB_register_Asm_32:
6521 case ARM::VLD4DUPqWB_register_Asm_8:
6522 case ARM::VLD4DUPqWB_register_Asm_16:
6523 case ARM::VLD4DUPqWB_register_Asm_32: {
6526 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6527 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6534 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6535 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6536 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6537 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6538 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6539 TmpInst.addOperand(Inst.getOperand(5));
6544 // VLD4 multiple 4-element structure instructions.
6545 case ARM::VLD4dAsm_8:
6546 case ARM::VLD4dAsm_16:
6547 case ARM::VLD4dAsm_32:
6548 case ARM::VLD4qAsm_8:
6549 case ARM::VLD4qAsm_16:
6550 case ARM::VLD4qAsm_32: {
6553 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6554 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6555 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6557 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6559 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6561 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6562 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6563 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6564 TmpInst.addOperand(Inst.getOperand(4));
6569 case ARM::VLD4dWB_fixed_Asm_8:
6570 case ARM::VLD4dWB_fixed_Asm_16:
6571 case ARM::VLD4dWB_fixed_Asm_32:
6572 case ARM::VLD4qWB_fixed_Asm_8:
6573 case ARM::VLD4qWB_fixed_Asm_16:
6574 case ARM::VLD4qWB_fixed_Asm_32: {
6577 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6578 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6579 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6581 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6583 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6585 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6586 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6587 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6588 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6589 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6590 TmpInst.addOperand(Inst.getOperand(4));
6595 case ARM::VLD4dWB_register_Asm_8:
6596 case ARM::VLD4dWB_register_Asm_16:
6597 case ARM::VLD4dWB_register_Asm_32:
6598 case ARM::VLD4qWB_register_Asm_8:
6599 case ARM::VLD4qWB_register_Asm_16:
6600 case ARM::VLD4qWB_register_Asm_32: {
6603 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6604 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6605 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6607 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6609 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6611 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6612 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6613 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6614 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6615 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6616 TmpInst.addOperand(Inst.getOperand(5));
6621 // VST3 multiple 3-element structure instructions.
6622 case ARM::VST3dAsm_8:
6623 case ARM::VST3dAsm_16:
6624 case ARM::VST3dAsm_32:
6625 case ARM::VST3qAsm_8:
6626 case ARM::VST3qAsm_16:
6627 case ARM::VST3qAsm_32: {
6630 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6631 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6632 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6633 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6634 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6636 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6638 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6639 TmpInst.addOperand(Inst.getOperand(4));
6644 case ARM::VST3dWB_fixed_Asm_8:
6645 case ARM::VST3dWB_fixed_Asm_16:
6646 case ARM::VST3dWB_fixed_Asm_32:
6647 case ARM::VST3qWB_fixed_Asm_8:
6648 case ARM::VST3qWB_fixed_Asm_16:
6649 case ARM::VST3qWB_fixed_Asm_32: {
6652 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6653 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6654 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6655 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6656 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6657 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6658 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6660 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6662 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6663 TmpInst.addOperand(Inst.getOperand(4));
6668 case ARM::VST3dWB_register_Asm_8:
6669 case ARM::VST3dWB_register_Asm_16:
6670 case ARM::VST3dWB_register_Asm_32:
6671 case ARM::VST3qWB_register_Asm_8:
6672 case ARM::VST3qWB_register_Asm_16:
6673 case ARM::VST3qWB_register_Asm_32: {
6676 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6677 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6678 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6679 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6680 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6681 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6682 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6684 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6686 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6687 TmpInst.addOperand(Inst.getOperand(5));
6692 // VST4 multiple 3-element structure instructions.
6693 case ARM::VST4dAsm_8:
6694 case ARM::VST4dAsm_16:
6695 case ARM::VST4dAsm_32:
6696 case ARM::VST4qAsm_8:
6697 case ARM::VST4qAsm_16:
6698 case ARM::VST4qAsm_32: {
6701 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6702 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6703 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6704 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6705 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6707 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6709 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6711 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6712 TmpInst.addOperand(Inst.getOperand(4));
6717 case ARM::VST4dWB_fixed_Asm_8:
6718 case ARM::VST4dWB_fixed_Asm_16:
6719 case ARM::VST4dWB_fixed_Asm_32:
6720 case ARM::VST4qWB_fixed_Asm_8:
6721 case ARM::VST4qWB_fixed_Asm_16:
6722 case ARM::VST4qWB_fixed_Asm_32: {
6725 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6726 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6727 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6728 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6729 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6730 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6731 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6733 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6735 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6737 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6738 TmpInst.addOperand(Inst.getOperand(4));
6743 case ARM::VST4dWB_register_Asm_8:
6744 case ARM::VST4dWB_register_Asm_16:
6745 case ARM::VST4dWB_register_Asm_32:
6746 case ARM::VST4qWB_register_Asm_8:
6747 case ARM::VST4qWB_register_Asm_16:
6748 case ARM::VST4qWB_register_Asm_32: {
6751 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6752 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6753 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6754 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6755 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6756 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6759 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6761 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6763 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6764 TmpInst.addOperand(Inst.getOperand(5));
6769 // Handle encoding choice for the shift-immediate instructions.
6772 case ARM::t2ASRri: {
6773 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6774 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6775 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6776 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6777 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6779 switch (Inst.getOpcode()) {
6780 default: llvm_unreachable("unexpected opcode");
6781 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6782 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6783 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6785 // The Thumb1 operands aren't in the same order. Awesome, eh?
6787 TmpInst.setOpcode(NewOpc);
6788 TmpInst.addOperand(Inst.getOperand(0));
6789 TmpInst.addOperand(Inst.getOperand(5));
6790 TmpInst.addOperand(Inst.getOperand(1));
6791 TmpInst.addOperand(Inst.getOperand(2));
6792 TmpInst.addOperand(Inst.getOperand(3));
6793 TmpInst.addOperand(Inst.getOperand(4));
6800 // Handle the Thumb2 mode MOV complex aliases.
6802 case ARM::t2MOVSsr: {
6803 // Which instruction to expand to depends on the CCOut operand and
6804 // whether we're in an IT block if the register operands are low
6806 bool isNarrow = false;
6807 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6808 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6809 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6810 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6811 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6815 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6816 default: llvm_unreachable("unexpected opcode!");
6817 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6818 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6819 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6820 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6822 TmpInst.setOpcode(newOpc);
6823 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6825 TmpInst.addOperand(MCOperand::CreateReg(
6826 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6827 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6828 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6829 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6830 TmpInst.addOperand(Inst.getOperand(5));
6832 TmpInst.addOperand(MCOperand::CreateReg(
6833 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6838 case ARM::t2MOVSsi: {
6839 // Which instruction to expand to depends on the CCOut operand and
6840 // whether we're in an IT block if the register operands are low
6842 bool isNarrow = false;
6843 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6844 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6845 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6849 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6850 default: llvm_unreachable("unexpected opcode!");
6851 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6852 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6853 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6854 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
6855 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
6857 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6858 if (Amount == 32) Amount = 0;
6859 TmpInst.setOpcode(newOpc);
6860 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6862 TmpInst.addOperand(MCOperand::CreateReg(
6863 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6864 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6865 if (newOpc != ARM::t2RRX)
6866 TmpInst.addOperand(MCOperand::CreateImm(Amount));
6867 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6868 TmpInst.addOperand(Inst.getOperand(4));
6870 TmpInst.addOperand(MCOperand::CreateReg(
6871 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6875 // Handle the ARM mode MOV complex aliases.
6880 ARM_AM::ShiftOpc ShiftTy;
6881 switch(Inst.getOpcode()) {
6882 default: llvm_unreachable("unexpected opcode!");
6883 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6884 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6885 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6886 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6888 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6890 TmpInst.setOpcode(ARM::MOVsr);
6891 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6892 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6893 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6894 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6895 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6896 TmpInst.addOperand(Inst.getOperand(4));
6897 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6905 ARM_AM::ShiftOpc ShiftTy;
6906 switch(Inst.getOpcode()) {
6907 default: llvm_unreachable("unexpected opcode!");
6908 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6909 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6910 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6911 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6913 // A shift by zero is a plain MOVr, not a MOVsi.
6914 unsigned Amt = Inst.getOperand(2).getImm();
6915 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
6916 // A shift by 32 should be encoded as 0 when permitted
6917 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6919 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
6921 TmpInst.setOpcode(Opc);
6922 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6923 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6924 if (Opc == ARM::MOVsi)
6925 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6926 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6927 TmpInst.addOperand(Inst.getOperand(4));
6928 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6933 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6935 TmpInst.setOpcode(ARM::MOVsi);
6936 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6937 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6938 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6939 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6940 TmpInst.addOperand(Inst.getOperand(3));
6941 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6945 case ARM::t2LDMIA_UPD: {
6946 // If this is a load of a single register, then we should use
6947 // a post-indexed LDR instruction instead, per the ARM ARM.
6948 if (Inst.getNumOperands() != 5)
6951 TmpInst.setOpcode(ARM::t2LDR_POST);
6952 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6953 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6954 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6955 TmpInst.addOperand(MCOperand::CreateImm(4));
6956 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6957 TmpInst.addOperand(Inst.getOperand(3));
6961 case ARM::t2STMDB_UPD: {
6962 // If this is a store of a single register, then we should use
6963 // a pre-indexed STR instruction instead, per the ARM ARM.
6964 if (Inst.getNumOperands() != 5)
6967 TmpInst.setOpcode(ARM::t2STR_PRE);
6968 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6969 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6970 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6971 TmpInst.addOperand(MCOperand::CreateImm(-4));
6972 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6973 TmpInst.addOperand(Inst.getOperand(3));
6977 case ARM::LDMIA_UPD:
6978 // If this is a load of a single register via a 'pop', then we should use
6979 // a post-indexed LDR instruction instead, per the ARM ARM.
6980 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6981 Inst.getNumOperands() == 5) {
6983 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6984 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6985 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6986 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6987 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6988 TmpInst.addOperand(MCOperand::CreateImm(4));
6989 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6990 TmpInst.addOperand(Inst.getOperand(3));
6995 case ARM::STMDB_UPD:
6996 // If this is a store of a single register via a 'push', then we should use
6997 // a pre-indexed STR instruction instead, per the ARM ARM.
6998 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6999 Inst.getNumOperands() == 5) {
7001 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7002 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7003 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7004 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7005 TmpInst.addOperand(MCOperand::CreateImm(-4));
7006 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7007 TmpInst.addOperand(Inst.getOperand(3));
7011 case ARM::t2ADDri12:
7012 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7013 // mnemonic was used (not "addw"), encoding T3 is preferred.
7014 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7015 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7017 Inst.setOpcode(ARM::t2ADDri);
7018 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7020 case ARM::t2SUBri12:
7021 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7022 // mnemonic was used (not "subw"), encoding T3 is preferred.
7023 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7024 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7026 Inst.setOpcode(ARM::t2SUBri);
7027 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7030 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7031 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7032 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7033 // to encoding T1 if <Rd> is omitted."
7034 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7035 Inst.setOpcode(ARM::tADDi3);
7040 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7041 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7042 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7043 // to encoding T1 if <Rd> is omitted."
7044 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7045 Inst.setOpcode(ARM::tSUBi3);
7050 case ARM::t2SUBri: {
7051 // If the destination and first source operand are the same, and
7052 // the flags are compatible with the current IT status, use encoding T2
7053 // instead of T3. For compatibility with the system 'as'. Make sure the
7054 // wide encoding wasn't explicit.
7055 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7056 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7057 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7058 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7059 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7060 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7061 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7064 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7065 ARM::tADDi8 : ARM::tSUBi8);
7066 TmpInst.addOperand(Inst.getOperand(0));
7067 TmpInst.addOperand(Inst.getOperand(5));
7068 TmpInst.addOperand(Inst.getOperand(0));
7069 TmpInst.addOperand(Inst.getOperand(2));
7070 TmpInst.addOperand(Inst.getOperand(3));
7071 TmpInst.addOperand(Inst.getOperand(4));
7075 case ARM::t2ADDrr: {
7076 // If the destination and first source operand are the same, and
7077 // there's no setting of the flags, use encoding T2 instead of T3.
7078 // Note that this is only for ADD, not SUB. This mirrors the system
7079 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7080 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7081 Inst.getOperand(5).getReg() != 0 ||
7082 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7083 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7086 TmpInst.setOpcode(ARM::tADDhirr);
7087 TmpInst.addOperand(Inst.getOperand(0));
7088 TmpInst.addOperand(Inst.getOperand(0));
7089 TmpInst.addOperand(Inst.getOperand(2));
7090 TmpInst.addOperand(Inst.getOperand(3));
7091 TmpInst.addOperand(Inst.getOperand(4));
7095 case ARM::tADDrSP: {
7096 // If the non-SP source operand and the destination operand are not the
7097 // same, we need to use the 32-bit encoding if it's available.
7098 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7099 Inst.setOpcode(ARM::t2ADDrr);
7100 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7106 // A Thumb conditional branch outside of an IT block is a tBcc.
7107 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7108 Inst.setOpcode(ARM::tBcc);
7113 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7114 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7115 Inst.setOpcode(ARM::t2Bcc);
7120 // If the conditional is AL or we're in an IT block, we really want t2B.
7121 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7122 Inst.setOpcode(ARM::t2B);
7127 // If the conditional is AL, we really want tB.
7128 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7129 Inst.setOpcode(ARM::tB);
7134 // If the register list contains any high registers, or if the writeback
7135 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7136 // instead if we're in Thumb2. Otherwise, this should have generated
7137 // an error in validateInstruction().
7138 unsigned Rn = Inst.getOperand(0).getReg();
7139 bool hasWritebackToken =
7140 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7141 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7142 bool listContainsBase;
7143 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7144 (!listContainsBase && !hasWritebackToken) ||
7145 (listContainsBase && hasWritebackToken)) {
7146 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7147 assert (isThumbTwo());
7148 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7149 // If we're switching to the updating version, we need to insert
7150 // the writeback tied operand.
7151 if (hasWritebackToken)
7152 Inst.insert(Inst.begin(),
7153 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7158 case ARM::tSTMIA_UPD: {
7159 // If the register list contains any high registers, we need to use
7160 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7161 // should have generated an error in validateInstruction().
7162 unsigned Rn = Inst.getOperand(0).getReg();
7163 bool listContainsBase;
7164 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7165 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7166 assert (isThumbTwo());
7167 Inst.setOpcode(ARM::t2STMIA_UPD);
7173 bool listContainsBase;
7174 // If the register list contains any high registers, we need to use
7175 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7176 // should have generated an error in validateInstruction().
7177 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7179 assert (isThumbTwo());
7180 Inst.setOpcode(ARM::t2LDMIA_UPD);
7181 // Add the base register and writeback operands.
7182 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7183 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7187 bool listContainsBase;
7188 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7190 assert (isThumbTwo());
7191 Inst.setOpcode(ARM::t2STMDB_UPD);
7192 // Add the base register and writeback operands.
7193 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7194 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7198 // If we can use the 16-bit encoding and the user didn't explicitly
7199 // request the 32-bit variant, transform it here.
7200 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7201 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7202 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7203 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7204 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7205 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7206 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7207 // The operands aren't in the same order for tMOVi8...
7209 TmpInst.setOpcode(ARM::tMOVi8);
7210 TmpInst.addOperand(Inst.getOperand(0));
7211 TmpInst.addOperand(Inst.getOperand(4));
7212 TmpInst.addOperand(Inst.getOperand(1));
7213 TmpInst.addOperand(Inst.getOperand(2));
7214 TmpInst.addOperand(Inst.getOperand(3));
7221 // If we can use the 16-bit encoding and the user didn't explicitly
7222 // request the 32-bit variant, transform it here.
7223 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7224 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7225 Inst.getOperand(2).getImm() == ARMCC::AL &&
7226 Inst.getOperand(4).getReg() == ARM::CPSR &&
7227 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7228 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7229 // The operands aren't the same for tMOV[S]r... (no cc_out)
7231 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7232 TmpInst.addOperand(Inst.getOperand(0));
7233 TmpInst.addOperand(Inst.getOperand(1));
7234 TmpInst.addOperand(Inst.getOperand(2));
7235 TmpInst.addOperand(Inst.getOperand(3));
7245 // If we can use the 16-bit encoding and the user didn't explicitly
7246 // request the 32-bit variant, transform it here.
7247 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7248 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7249 Inst.getOperand(2).getImm() == 0 &&
7250 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7251 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7253 switch (Inst.getOpcode()) {
7254 default: llvm_unreachable("Illegal opcode!");
7255 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7256 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7257 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7258 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7260 // The operands aren't the same for thumb1 (no rotate operand).
7262 TmpInst.setOpcode(NewOpc);
7263 TmpInst.addOperand(Inst.getOperand(0));
7264 TmpInst.addOperand(Inst.getOperand(1));
7265 TmpInst.addOperand(Inst.getOperand(3));
7266 TmpInst.addOperand(Inst.getOperand(4));
7273 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7274 // rrx shifts and asr/lsr of #32 is encoded as 0
7275 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7277 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7278 // Shifting by zero is accepted as a vanilla 'MOVr'
7280 TmpInst.setOpcode(ARM::MOVr);
7281 TmpInst.addOperand(Inst.getOperand(0));
7282 TmpInst.addOperand(Inst.getOperand(1));
7283 TmpInst.addOperand(Inst.getOperand(3));
7284 TmpInst.addOperand(Inst.getOperand(4));
7285 TmpInst.addOperand(Inst.getOperand(5));
7298 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7299 if (SOpc == ARM_AM::rrx) return false;
7300 switch (Inst.getOpcode()) {
7301 default: llvm_unreachable("unexpected opcode!");
7302 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7303 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7304 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7305 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7306 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7307 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7309 // If the shift is by zero, use the non-shifted instruction definition.
7310 // The exception is for right shifts, where 0 == 32
7311 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7312 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7314 TmpInst.setOpcode(newOpc);
7315 TmpInst.addOperand(Inst.getOperand(0));
7316 TmpInst.addOperand(Inst.getOperand(1));
7317 TmpInst.addOperand(Inst.getOperand(2));
7318 TmpInst.addOperand(Inst.getOperand(4));
7319 TmpInst.addOperand(Inst.getOperand(5));
7320 TmpInst.addOperand(Inst.getOperand(6));
7328 // The mask bits for all but the first condition are represented as
7329 // the low bit of the condition code value implies 't'. We currently
7330 // always have 1 implies 't', so XOR toggle the bits if the low bit
7331 // of the condition code is zero.
7332 MCOperand &MO = Inst.getOperand(1);
7333 unsigned Mask = MO.getImm();
7334 unsigned OrigMask = Mask;
7335 unsigned TZ = CountTrailingZeros_32(Mask);
7336 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7337 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7338 for (unsigned i = 3; i != TZ; --i)
7343 // Set up the IT block state according to the IT instruction we just
7345 assert(!inITBlock() && "nested IT blocks?!");
7346 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7347 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7348 ITState.CurPosition = 0;
7349 ITState.FirstCond = true;
7359 // Assemblers should use the narrow encodings of these instructions when permissible.
7360 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7361 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7362 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7363 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7364 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7365 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7366 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7368 switch (Inst.getOpcode()) {
7369 default: llvm_unreachable("unexpected opcode");
7370 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7371 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7372 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7373 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7374 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7375 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7378 TmpInst.setOpcode(NewOpc);
7379 TmpInst.addOperand(Inst.getOperand(0));
7380 TmpInst.addOperand(Inst.getOperand(5));
7381 TmpInst.addOperand(Inst.getOperand(1));
7382 TmpInst.addOperand(Inst.getOperand(2));
7383 TmpInst.addOperand(Inst.getOperand(3));
7384 TmpInst.addOperand(Inst.getOperand(4));
7395 // Assemblers should use the narrow encodings of these instructions when permissible.
7396 // These instructions are special in that they are commutable, so shorter encodings
7397 // are available more often.
7398 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7399 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7400 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7401 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7402 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7403 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7404 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7405 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7407 switch (Inst.getOpcode()) {
7408 default: llvm_unreachable("unexpected opcode");
7409 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7410 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7411 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7412 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7415 TmpInst.setOpcode(NewOpc);
7416 TmpInst.addOperand(Inst.getOperand(0));
7417 TmpInst.addOperand(Inst.getOperand(5));
7418 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7419 TmpInst.addOperand(Inst.getOperand(1));
7420 TmpInst.addOperand(Inst.getOperand(2));
7422 TmpInst.addOperand(Inst.getOperand(2));
7423 TmpInst.addOperand(Inst.getOperand(1));
7425 TmpInst.addOperand(Inst.getOperand(3));
7426 TmpInst.addOperand(Inst.getOperand(4));
7436 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7437 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7438 // suffix depending on whether they're in an IT block or not.
7439 unsigned Opc = Inst.getOpcode();
7440 const MCInstrDesc &MCID = getInstDesc(Opc);
7441 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7442 assert(MCID.hasOptionalDef() &&
7443 "optionally flag setting instruction missing optional def operand");
7444 assert(MCID.NumOperands == Inst.getNumOperands() &&
7445 "operand count mismatch!");
7446 // Find the optional-def operand (cc_out).
7449 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7452 // If we're parsing Thumb1, reject it completely.
7453 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7454 return Match_MnemonicFail;
7455 // If we're parsing Thumb2, which form is legal depends on whether we're
7457 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7459 return Match_RequiresITBlock;
7460 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7462 return Match_RequiresNotITBlock;
7464 // Some high-register supporting Thumb1 encodings only allow both registers
7465 // to be from r0-r7 when in Thumb2.
7466 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7467 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7468 isARMLowRegister(Inst.getOperand(2).getReg()))
7469 return Match_RequiresThumb2;
7470 // Others only require ARMv6 or later.
7471 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7472 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7473 isARMLowRegister(Inst.getOperand(1).getReg()))
7474 return Match_RequiresV6;
7475 return Match_Success;
7478 static const char *getSubtargetFeatureName(unsigned Val);
7480 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7481 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7482 MCStreamer &Out, unsigned &ErrorInfo,
7483 bool MatchingInlineAsm) {
7485 unsigned MatchResult;
7486 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7488 switch (MatchResult) {
7491 // Context sensitive operand constraints aren't handled by the matcher,
7492 // so check them here.
7493 if (validateInstruction(Inst, Operands)) {
7494 // Still progress the IT block, otherwise one wrong condition causes
7495 // nasty cascading errors.
7496 forwardITPosition();
7500 // Some instructions need post-processing to, for example, tweak which
7501 // encoding is selected. Loop on it while changes happen so the
7502 // individual transformations can chain off each other. E.g.,
7503 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7504 while (processInstruction(Inst, Operands))
7507 // Only move forward at the very end so that everything in validate
7508 // and process gets a consistent answer about whether we're in an IT
7510 forwardITPosition();
7512 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7513 // doesn't actually encode.
7514 if (Inst.getOpcode() == ARM::ITasm)
7518 Out.EmitInstruction(Inst);
7520 case Match_MissingFeature: {
7521 assert(ErrorInfo && "Unknown missing feature!");
7522 // Special case the error message for the very common case where only
7523 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7524 std::string Msg = "instruction requires:";
7526 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7527 if (ErrorInfo & Mask) {
7529 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7533 return Error(IDLoc, Msg);
7535 case Match_InvalidOperand: {
7536 SMLoc ErrorLoc = IDLoc;
7537 if (ErrorInfo != ~0U) {
7538 if (ErrorInfo >= Operands.size())
7539 return Error(IDLoc, "too few operands for instruction");
7541 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7542 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7545 return Error(ErrorLoc, "invalid operand for instruction");
7547 case Match_MnemonicFail:
7548 return Error(IDLoc, "invalid instruction",
7549 ((ARMOperand*)Operands[0])->getLocRange());
7550 case Match_RequiresNotITBlock:
7551 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7552 case Match_RequiresITBlock:
7553 return Error(IDLoc, "instruction only valid inside IT block");
7554 case Match_RequiresV6:
7555 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7556 case Match_RequiresThumb2:
7557 return Error(IDLoc, "instruction variant requires Thumb2");
7558 case Match_ImmRange0_15: {
7559 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7560 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7561 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7565 llvm_unreachable("Implement any new match types added!");
7568 /// parseDirective parses the arm specific directives
7569 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7570 StringRef IDVal = DirectiveID.getIdentifier();
7571 if (IDVal == ".word")
7572 return parseDirectiveWord(4, DirectiveID.getLoc());
7573 else if (IDVal == ".thumb")
7574 return parseDirectiveThumb(DirectiveID.getLoc());
7575 else if (IDVal == ".arm")
7576 return parseDirectiveARM(DirectiveID.getLoc());
7577 else if (IDVal == ".thumb_func")
7578 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7579 else if (IDVal == ".code")
7580 return parseDirectiveCode(DirectiveID.getLoc());
7581 else if (IDVal == ".syntax")
7582 return parseDirectiveSyntax(DirectiveID.getLoc());
7583 else if (IDVal == ".unreq")
7584 return parseDirectiveUnreq(DirectiveID.getLoc());
7585 else if (IDVal == ".arch")
7586 return parseDirectiveArch(DirectiveID.getLoc());
7587 else if (IDVal == ".eabi_attribute")
7588 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7592 /// parseDirectiveWord
7593 /// ::= .word [ expression (, expression)* ]
7594 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7595 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7597 const MCExpr *Value;
7598 if (getParser().ParseExpression(Value))
7601 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
7603 if (getLexer().is(AsmToken::EndOfStatement))
7606 // FIXME: Improve diagnostic.
7607 if (getLexer().isNot(AsmToken::Comma))
7608 return Error(L, "unexpected token in directive");
7617 /// parseDirectiveThumb
7619 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7620 if (getLexer().isNot(AsmToken::EndOfStatement))
7621 return Error(L, "unexpected token in directive");
7626 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7630 /// parseDirectiveARM
7632 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7633 if (getLexer().isNot(AsmToken::EndOfStatement))
7634 return Error(L, "unexpected token in directive");
7639 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7643 /// parseDirectiveThumbFunc
7644 /// ::= .thumbfunc symbol_name
7645 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7646 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7647 bool isMachO = MAI.hasSubsectionsViaSymbols();
7649 bool needFuncName = true;
7651 // Darwin asm has (optionally) function name after .thumb_func direction
7654 const AsmToken &Tok = Parser.getTok();
7655 if (Tok.isNot(AsmToken::EndOfStatement)) {
7656 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7657 return Error(L, "unexpected token in .thumb_func directive");
7658 Name = Tok.getIdentifier();
7659 Parser.Lex(); // Consume the identifier token.
7660 needFuncName = false;
7664 if (getLexer().isNot(AsmToken::EndOfStatement))
7665 return Error(L, "unexpected token in directive");
7667 // Eat the end of statement and any blank lines that follow.
7668 while (getLexer().is(AsmToken::EndOfStatement))
7671 // FIXME: assuming function name will be the line following .thumb_func
7672 // We really should be checking the next symbol definition even if there's
7673 // stuff in between.
7675 Name = Parser.getTok().getIdentifier();
7678 // Mark symbol as a thumb symbol.
7679 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7680 getParser().getStreamer().EmitThumbFunc(Func);
7684 /// parseDirectiveSyntax
7685 /// ::= .syntax unified | divided
7686 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7687 const AsmToken &Tok = Parser.getTok();
7688 if (Tok.isNot(AsmToken::Identifier))
7689 return Error(L, "unexpected token in .syntax directive");
7690 StringRef Mode = Tok.getString();
7691 if (Mode == "unified" || Mode == "UNIFIED")
7693 else if (Mode == "divided" || Mode == "DIVIDED")
7694 return Error(L, "'.syntax divided' arm asssembly not supported");
7696 return Error(L, "unrecognized syntax mode in .syntax directive");
7698 if (getLexer().isNot(AsmToken::EndOfStatement))
7699 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7702 // TODO tell the MC streamer the mode
7703 // getParser().getStreamer().Emit???();
7707 /// parseDirectiveCode
7708 /// ::= .code 16 | 32
7709 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7710 const AsmToken &Tok = Parser.getTok();
7711 if (Tok.isNot(AsmToken::Integer))
7712 return Error(L, "unexpected token in .code directive");
7713 int64_t Val = Parser.getTok().getIntVal();
7719 return Error(L, "invalid operand to .code directive");
7721 if (getLexer().isNot(AsmToken::EndOfStatement))
7722 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7728 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7732 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7738 /// parseDirectiveReq
7739 /// ::= name .req registername
7740 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7741 Parser.Lex(); // Eat the '.req' token.
7743 SMLoc SRegLoc, ERegLoc;
7744 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7745 Parser.EatToEndOfStatement();
7746 return Error(SRegLoc, "register name expected");
7749 // Shouldn't be anything else.
7750 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7751 Parser.EatToEndOfStatement();
7752 return Error(Parser.getTok().getLoc(),
7753 "unexpected input in .req directive.");
7756 Parser.Lex(); // Consume the EndOfStatement
7758 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7759 return Error(SRegLoc, "redefinition of '" + Name +
7760 "' does not match original.");
7765 /// parseDirectiveUneq
7766 /// ::= .unreq registername
7767 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7768 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7769 Parser.EatToEndOfStatement();
7770 return Error(L, "unexpected input in .unreq directive.");
7772 RegisterReqs.erase(Parser.getTok().getIdentifier());
7773 Parser.Lex(); // Eat the identifier.
7777 /// parseDirectiveArch
7779 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7783 /// parseDirectiveEabiAttr
7784 /// ::= .eabi_attribute int, int
7785 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7789 extern "C" void LLVMInitializeARMAsmLexer();
7791 /// Force static initialization.
7792 extern "C" void LLVMInitializeARMAsmParser() {
7793 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7794 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
7795 LLVMInitializeARMAsmLexer();
7798 #define GET_REGISTER_MATCHER
7799 #define GET_SUBTARGET_FEATURE_NAME
7800 #define GET_MATCHER_IMPLEMENTATION
7801 #include "ARMGenAsmMatcher.inc"