1 //===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "MCTargetDesc/ARMBaseInfo.h"
11 #include "MCTargetDesc/ARMAddressingModes.h"
12 #include "MCTargetDesc/ARMMCExpr.h"
13 #include "llvm/MC/MCParser/MCAsmLexer.h"
14 #include "llvm/MC/MCParser/MCAsmParser.h"
15 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCInstrDesc.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/MC/MCTargetAsmParser.h"
25 #include "llvm/Support/MathExtras.h"
26 #include "llvm/Support/SourceMgr.h"
27 #include "llvm/Support/TargetRegistry.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include "llvm/ADT/BitVector.h"
30 #include "llvm/ADT/OwningPtr.h"
31 #include "llvm/ADT/STLExtras.h"
32 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/ADT/StringSwitch.h"
34 #include "llvm/ADT/Twine.h"
42 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
44 class ARMAsmParser : public MCTargetAsmParser {
47 const MCRegisterInfo *MRI;
49 // Map of register aliases registers via the .req directive.
50 StringMap<unsigned> RegisterReqs;
53 ARMCC::CondCodes Cond; // Condition for IT block.
54 unsigned Mask:4; // Condition mask for instructions.
55 // Starting at first 1 (from lsb).
56 // '1' condition as indicated in IT.
57 // '0' inverse of condition (else).
58 // Count of instructions in IT block is
59 // 4 - trailingzeroes(mask)
61 bool FirstCond; // Explicit flag for when we're parsing the
62 // First instruction in the IT block. It's
63 // implied in the mask, so needs special
66 unsigned CurPosition; // Current position in parsing of IT
67 // block. In range [0,3]. Initialized
68 // according to count of instructions in block.
69 // ~0U if no active IT block.
71 bool inITBlock() { return ITState.CurPosition != ~0U;}
72 void forwardITPosition() {
73 if (!inITBlock()) return;
74 // Move to the next instruction in the IT block, if there is one. If not,
75 // mark the block as done.
76 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
77 if (++ITState.CurPosition == 5 - TZ)
78 ITState.CurPosition = ~0U; // Done with the IT block after this.
82 MCAsmParser &getParser() const { return Parser; }
83 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
85 bool Warning(SMLoc L, const Twine &Msg,
86 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
87 return Parser.Warning(L, Msg, Ranges);
89 bool Error(SMLoc L, const Twine &Msg,
90 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
91 return Parser.Error(L, Msg, Ranges);
94 int tryParseRegister();
95 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
96 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
97 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
98 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
99 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
100 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
101 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
102 unsigned &ShiftAmount);
103 bool parseDirectiveWord(unsigned Size, SMLoc L);
104 bool parseDirectiveThumb(SMLoc L);
105 bool parseDirectiveARM(SMLoc L);
106 bool parseDirectiveThumbFunc(SMLoc L);
107 bool parseDirectiveCode(SMLoc L);
108 bool parseDirectiveSyntax(SMLoc L);
109 bool parseDirectiveReq(StringRef Name, SMLoc L);
110 bool parseDirectiveUnreq(SMLoc L);
111 bool parseDirectiveArch(SMLoc L);
112 bool parseDirectiveEabiAttr(SMLoc L);
114 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
115 bool &CarrySetting, unsigned &ProcessorIMod,
117 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
118 bool &CanAcceptPredicationCode);
120 bool isThumb() const {
121 // FIXME: Can tablegen auto-generate this?
122 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
124 bool isThumbOne() const {
125 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
127 bool isThumbTwo() const {
128 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
130 bool hasV6Ops() const {
131 return STI.getFeatureBits() & ARM::HasV6Ops;
133 bool hasV7Ops() const {
134 return STI.getFeatureBits() & ARM::HasV7Ops;
137 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
138 setAvailableFeatures(FB);
140 bool isMClass() const {
141 return STI.getFeatureBits() & ARM::FeatureMClass;
144 /// @name Auto-generated Match Functions
147 #define GET_ASSEMBLER_HEADER
148 #include "ARMGenAsmMatcher.inc"
152 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
153 OperandMatchResultTy parseCoprocNumOperand(
154 SmallVectorImpl<MCParsedAsmOperand*>&);
155 OperandMatchResultTy parseCoprocRegOperand(
156 SmallVectorImpl<MCParsedAsmOperand*>&);
157 OperandMatchResultTy parseCoprocOptionOperand(
158 SmallVectorImpl<MCParsedAsmOperand*>&);
159 OperandMatchResultTy parseMemBarrierOptOperand(
160 SmallVectorImpl<MCParsedAsmOperand*>&);
161 OperandMatchResultTy parseProcIFlagsOperand(
162 SmallVectorImpl<MCParsedAsmOperand*>&);
163 OperandMatchResultTy parseMSRMaskOperand(
164 SmallVectorImpl<MCParsedAsmOperand*>&);
165 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
166 StringRef Op, int Low, int High);
167 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
168 return parsePKHImm(O, "lsl", 0, 31);
170 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
171 return parsePKHImm(O, "asr", 1, 32);
173 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
174 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
175 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
176 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
177 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
178 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
179 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
180 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
181 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
183 // Asm Match Converter Methods
184 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
185 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
186 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
187 const SmallVectorImpl<MCParsedAsmOperand*> &);
188 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
189 const SmallVectorImpl<MCParsedAsmOperand*> &);
190 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
191 const SmallVectorImpl<MCParsedAsmOperand*> &);
192 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
193 const SmallVectorImpl<MCParsedAsmOperand*> &);
194 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
195 const SmallVectorImpl<MCParsedAsmOperand*> &);
196 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
197 const SmallVectorImpl<MCParsedAsmOperand*> &);
198 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
199 const SmallVectorImpl<MCParsedAsmOperand*> &);
200 void cvtLdExtTWriteBackImm(MCInst &Inst,
201 const SmallVectorImpl<MCParsedAsmOperand*> &);
202 void cvtLdExtTWriteBackReg(MCInst &Inst,
203 const SmallVectorImpl<MCParsedAsmOperand*> &);
204 void cvtStExtTWriteBackImm(MCInst &Inst,
205 const SmallVectorImpl<MCParsedAsmOperand*> &);
206 void cvtStExtTWriteBackReg(MCInst &Inst,
207 const SmallVectorImpl<MCParsedAsmOperand*> &);
208 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
209 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
210 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
211 const SmallVectorImpl<MCParsedAsmOperand*> &);
212 void cvtThumbMultiply(MCInst &Inst,
213 const SmallVectorImpl<MCParsedAsmOperand*> &);
214 void cvtVLDwbFixed(MCInst &Inst,
215 const SmallVectorImpl<MCParsedAsmOperand*> &);
216 void cvtVLDwbRegister(MCInst &Inst,
217 const SmallVectorImpl<MCParsedAsmOperand*> &);
218 void cvtVSTwbFixed(MCInst &Inst,
219 const SmallVectorImpl<MCParsedAsmOperand*> &);
220 void cvtVSTwbRegister(MCInst &Inst,
221 const SmallVectorImpl<MCParsedAsmOperand*> &);
222 bool validateInstruction(MCInst &Inst,
223 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
224 bool processInstruction(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
226 bool shouldOmitCCOutOperand(StringRef Mnemonic,
227 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
230 enum ARMMatchResultTy {
231 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
232 Match_RequiresNotITBlock,
234 Match_RequiresThumb2,
235 #define GET_OPERAND_DIAGNOSTIC_TYPES
236 #include "ARMGenAsmMatcher.inc"
240 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
241 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
242 MCAsmParserExtension::Initialize(_Parser);
244 // Cache the MCRegisterInfo.
245 MRI = &getContext().getRegisterInfo();
247 // Initialize the set of available features.
248 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
250 // Not in an ITBlock to start with.
251 ITState.CurPosition = ~0U;
254 // Implementation of the MCTargetAsmParser interface:
255 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
256 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
257 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
258 bool ParseDirective(AsmToken DirectiveID);
260 unsigned checkTargetMatchPredicate(MCInst &Inst);
262 bool MatchAndEmitInstruction(SMLoc IDLoc,
263 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
266 } // end anonymous namespace
270 /// ARMOperand - Instances of this class represent a parsed ARM machine
272 class ARMOperand : public MCParsedAsmOperand {
292 k_VectorListAllLanes,
298 k_BitfieldDescriptor,
302 SMLoc StartLoc, EndLoc;
303 SmallVector<unsigned, 8> Registers;
307 ARMCC::CondCodes Val;
327 ARM_PROC::IFlags Val;
343 // A vector register list is a sequential list of 1 to 4 registers.
359 /// Combined record for all forms of ARM address expressions.
362 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
364 const MCConstantExpr *OffsetImm; // Offset immediate value
365 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
366 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
367 unsigned ShiftImm; // shift for OffsetReg.
368 unsigned Alignment; // 0 = no alignment specified
369 // n = alignment in bytes (2, 4, 8, 16, or 32)
370 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
376 ARM_AM::ShiftOpc ShiftTy;
385 ARM_AM::ShiftOpc ShiftTy;
391 ARM_AM::ShiftOpc ShiftTy;
404 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
406 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
408 StartLoc = o.StartLoc;
425 case k_DPRRegisterList:
426 case k_SPRRegisterList:
427 Registers = o.Registers;
430 case k_VectorListAllLanes:
431 case k_VectorListIndexed:
432 VectorList = o.VectorList;
439 CoprocOption = o.CoprocOption;
444 case k_MemBarrierOpt:
450 case k_PostIndexRegister:
451 PostIdxReg = o.PostIdxReg;
459 case k_ShifterImmediate:
460 ShifterImm = o.ShifterImm;
462 case k_ShiftedRegister:
463 RegShiftedReg = o.RegShiftedReg;
465 case k_ShiftedImmediate:
466 RegShiftedImm = o.RegShiftedImm;
468 case k_RotateImmediate:
471 case k_BitfieldDescriptor:
472 Bitfield = o.Bitfield;
475 VectorIndex = o.VectorIndex;
480 /// getStartLoc - Get the location of the first token of this operand.
481 SMLoc getStartLoc() const { return StartLoc; }
482 /// getEndLoc - Get the location of the last token of this operand.
483 SMLoc getEndLoc() const { return EndLoc; }
484 /// getLocRange - Get the range between the first and last token of this
486 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
488 ARMCC::CondCodes getCondCode() const {
489 assert(Kind == k_CondCode && "Invalid access!");
493 unsigned getCoproc() const {
494 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
498 StringRef getToken() const {
499 assert(Kind == k_Token && "Invalid access!");
500 return StringRef(Tok.Data, Tok.Length);
503 unsigned getReg() const {
504 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
508 const SmallVectorImpl<unsigned> &getRegList() const {
509 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
510 Kind == k_SPRRegisterList) && "Invalid access!");
514 const MCExpr *getImm() const {
515 assert(isImm() && "Invalid access!");
519 unsigned getVectorIndex() const {
520 assert(Kind == k_VectorIndex && "Invalid access!");
521 return VectorIndex.Val;
524 ARM_MB::MemBOpt getMemBarrierOpt() const {
525 assert(Kind == k_MemBarrierOpt && "Invalid access!");
529 ARM_PROC::IFlags getProcIFlags() const {
530 assert(Kind == k_ProcIFlags && "Invalid access!");
534 unsigned getMSRMask() const {
535 assert(Kind == k_MSRMask && "Invalid access!");
539 bool isCoprocNum() const { return Kind == k_CoprocNum; }
540 bool isCoprocReg() const { return Kind == k_CoprocReg; }
541 bool isCoprocOption() const { return Kind == k_CoprocOption; }
542 bool isCondCode() const { return Kind == k_CondCode; }
543 bool isCCOut() const { return Kind == k_CCOut; }
544 bool isITMask() const { return Kind == k_ITCondMask; }
545 bool isITCondCode() const { return Kind == k_CondCode; }
546 bool isImm() const { return Kind == k_Immediate; }
547 bool isFPImm() const {
548 if (!isImm()) return false;
549 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
550 if (!CE) return false;
551 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
554 bool isFBits16() const {
555 if (!isImm()) return false;
556 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
557 if (!CE) return false;
558 int64_t Value = CE->getValue();
559 return Value >= 0 && Value <= 16;
561 bool isFBits32() const {
562 if (!isImm()) return false;
563 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
564 if (!CE) return false;
565 int64_t Value = CE->getValue();
566 return Value >= 1 && Value <= 32;
568 bool isImm8s4() const {
569 if (!isImm()) return false;
570 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
571 if (!CE) return false;
572 int64_t Value = CE->getValue();
573 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
575 bool isImm0_1020s4() const {
576 if (!isImm()) return false;
577 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
578 if (!CE) return false;
579 int64_t Value = CE->getValue();
580 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
582 bool isImm0_508s4() const {
583 if (!isImm()) return false;
584 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
585 if (!CE) return false;
586 int64_t Value = CE->getValue();
587 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
589 bool isImm0_508s4Neg() const {
590 if (!isImm()) return false;
591 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
592 if (!CE) return false;
593 int64_t Value = -CE->getValue();
594 // explicitly exclude zero. we want that to use the normal 0_508 version.
595 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
597 bool isImm0_255() const {
598 if (!isImm()) return false;
599 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
600 if (!CE) return false;
601 int64_t Value = CE->getValue();
602 return Value >= 0 && Value < 256;
604 bool isImm0_4095() const {
605 if (!isImm()) return false;
606 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
607 if (!CE) return false;
608 int64_t Value = CE->getValue();
609 return Value >= 0 && Value < 4096;
611 bool isImm0_4095Neg() const {
612 if (!isImm()) return false;
613 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
614 if (!CE) return false;
615 int64_t Value = -CE->getValue();
616 return Value > 0 && Value < 4096;
618 bool isImm0_1() const {
619 if (!isImm()) return false;
620 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
621 if (!CE) return false;
622 int64_t Value = CE->getValue();
623 return Value >= 0 && Value < 2;
625 bool isImm0_3() const {
626 if (!isImm()) return false;
627 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
628 if (!CE) return false;
629 int64_t Value = CE->getValue();
630 return Value >= 0 && Value < 4;
632 bool isImm0_7() const {
633 if (!isImm()) return false;
634 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
635 if (!CE) return false;
636 int64_t Value = CE->getValue();
637 return Value >= 0 && Value < 8;
639 bool isImm0_15() const {
640 if (!isImm()) return false;
641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
642 if (!CE) return false;
643 int64_t Value = CE->getValue();
644 return Value >= 0 && Value < 16;
646 bool isImm0_31() const {
647 if (!isImm()) return false;
648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
649 if (!CE) return false;
650 int64_t Value = CE->getValue();
651 return Value >= 0 && Value < 32;
653 bool isImm0_63() const {
654 if (!isImm()) return false;
655 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
656 if (!CE) return false;
657 int64_t Value = CE->getValue();
658 return Value >= 0 && Value < 64;
660 bool isImm8() const {
661 if (!isImm()) return false;
662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
663 if (!CE) return false;
664 int64_t Value = CE->getValue();
667 bool isImm16() const {
668 if (!isImm()) return false;
669 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
670 if (!CE) return false;
671 int64_t Value = CE->getValue();
674 bool isImm32() const {
675 if (!isImm()) return false;
676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
677 if (!CE) return false;
678 int64_t Value = CE->getValue();
681 bool isShrImm8() const {
682 if (!isImm()) return false;
683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
684 if (!CE) return false;
685 int64_t Value = CE->getValue();
686 return Value > 0 && Value <= 8;
688 bool isShrImm16() const {
689 if (!isImm()) return false;
690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
691 if (!CE) return false;
692 int64_t Value = CE->getValue();
693 return Value > 0 && Value <= 16;
695 bool isShrImm32() const {
696 if (!isImm()) return false;
697 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
698 if (!CE) return false;
699 int64_t Value = CE->getValue();
700 return Value > 0 && Value <= 32;
702 bool isShrImm64() const {
703 if (!isImm()) return false;
704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
705 if (!CE) return false;
706 int64_t Value = CE->getValue();
707 return Value > 0 && Value <= 64;
709 bool isImm1_7() const {
710 if (!isImm()) return false;
711 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
712 if (!CE) return false;
713 int64_t Value = CE->getValue();
714 return Value > 0 && Value < 8;
716 bool isImm1_15() const {
717 if (!isImm()) return false;
718 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
719 if (!CE) return false;
720 int64_t Value = CE->getValue();
721 return Value > 0 && Value < 16;
723 bool isImm1_31() const {
724 if (!isImm()) return false;
725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
726 if (!CE) return false;
727 int64_t Value = CE->getValue();
728 return Value > 0 && Value < 32;
730 bool isImm1_16() const {
731 if (!isImm()) return false;
732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
733 if (!CE) return false;
734 int64_t Value = CE->getValue();
735 return Value > 0 && Value < 17;
737 bool isImm1_32() const {
738 if (!isImm()) return false;
739 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
740 if (!CE) return false;
741 int64_t Value = CE->getValue();
742 return Value > 0 && Value < 33;
744 bool isImm0_32() const {
745 if (!isImm()) return false;
746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
747 if (!CE) return false;
748 int64_t Value = CE->getValue();
749 return Value >= 0 && Value < 33;
751 bool isImm0_65535() const {
752 if (!isImm()) return false;
753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
754 if (!CE) return false;
755 int64_t Value = CE->getValue();
756 return Value >= 0 && Value < 65536;
758 bool isImm0_65535Expr() const {
759 if (!isImm()) return false;
760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
761 // If it's not a constant expression, it'll generate a fixup and be
763 if (!CE) return true;
764 int64_t Value = CE->getValue();
765 return Value >= 0 && Value < 65536;
767 bool isImm24bit() const {
768 if (!isImm()) return false;
769 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
770 if (!CE) return false;
771 int64_t Value = CE->getValue();
772 return Value >= 0 && Value <= 0xffffff;
774 bool isImmThumbSR() const {
775 if (!isImm()) return false;
776 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
777 if (!CE) return false;
778 int64_t Value = CE->getValue();
779 return Value > 0 && Value < 33;
781 bool isPKHLSLImm() const {
782 if (!isImm()) return false;
783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
784 if (!CE) return false;
785 int64_t Value = CE->getValue();
786 return Value >= 0 && Value < 32;
788 bool isPKHASRImm() const {
789 if (!isImm()) return false;
790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
791 if (!CE) return false;
792 int64_t Value = CE->getValue();
793 return Value > 0 && Value <= 32;
795 bool isAdrLabel() const {
796 // If we have an immediate that's not a constant, treat it as a label
797 // reference needing a fixup. If it is a constant, but it can't fit
798 // into shift immediate encoding, we reject it.
799 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
800 else return (isARMSOImm() || isARMSOImmNeg());
802 bool isARMSOImm() const {
803 if (!isImm()) return false;
804 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
805 if (!CE) return false;
806 int64_t Value = CE->getValue();
807 return ARM_AM::getSOImmVal(Value) != -1;
809 bool isARMSOImmNot() const {
810 if (!isImm()) return false;
811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
812 if (!CE) return false;
813 int64_t Value = CE->getValue();
814 return ARM_AM::getSOImmVal(~Value) != -1;
816 bool isARMSOImmNeg() const {
817 if (!isImm()) return false;
818 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
819 if (!CE) return false;
820 int64_t Value = CE->getValue();
821 // Only use this when not representable as a plain so_imm.
822 return ARM_AM::getSOImmVal(Value) == -1 &&
823 ARM_AM::getSOImmVal(-Value) != -1;
825 bool isT2SOImm() const {
826 if (!isImm()) return false;
827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
828 if (!CE) return false;
829 int64_t Value = CE->getValue();
830 return ARM_AM::getT2SOImmVal(Value) != -1;
832 bool isT2SOImmNot() const {
833 if (!isImm()) return false;
834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
835 if (!CE) return false;
836 int64_t Value = CE->getValue();
837 return ARM_AM::getT2SOImmVal(~Value) != -1;
839 bool isT2SOImmNeg() const {
840 if (!isImm()) return false;
841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = CE->getValue();
844 // Only use this when not representable as a plain so_imm.
845 return ARM_AM::getT2SOImmVal(Value) == -1 &&
846 ARM_AM::getT2SOImmVal(-Value) != -1;
848 bool isSetEndImm() const {
849 if (!isImm()) return false;
850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
851 if (!CE) return false;
852 int64_t Value = CE->getValue();
853 return Value == 1 || Value == 0;
855 bool isReg() const { return Kind == k_Register; }
856 bool isRegList() const { return Kind == k_RegisterList; }
857 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
858 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
859 bool isToken() const { return Kind == k_Token; }
860 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
861 bool isMem() const { return Kind == k_Memory; }
862 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
863 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
864 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
865 bool isRotImm() const { return Kind == k_RotateImmediate; }
866 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
867 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
868 bool isPostIdxReg() const {
869 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
871 bool isMemNoOffset(bool alignOK = false) const {
874 // No offset of any kind.
875 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
876 (alignOK || Memory.Alignment == 0);
878 bool isMemPCRelImm12() const {
879 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
881 // Base register must be PC.
882 if (Memory.BaseRegNum != ARM::PC)
884 // Immediate offset in range [-4095, 4095].
885 if (!Memory.OffsetImm) return true;
886 int64_t Val = Memory.OffsetImm->getValue();
887 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
889 bool isAlignedMemory() const {
890 return isMemNoOffset(true);
892 bool isAddrMode2() const {
893 if (!isMem() || Memory.Alignment != 0) return false;
894 // Check for register offset.
895 if (Memory.OffsetRegNum) return true;
896 // Immediate offset in range [-4095, 4095].
897 if (!Memory.OffsetImm) return true;
898 int64_t Val = Memory.OffsetImm->getValue();
899 return Val > -4096 && Val < 4096;
901 bool isAM2OffsetImm() const {
902 if (!isImm()) return false;
903 // Immediate offset in range [-4095, 4095].
904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
905 if (!CE) return false;
906 int64_t Val = CE->getValue();
907 return Val > -4096 && Val < 4096;
909 bool isAddrMode3() const {
910 // If we have an immediate that's not a constant, treat it as a label
911 // reference needing a fixup. If it is a constant, it's something else
913 if (isImm() && !isa<MCConstantExpr>(getImm()))
915 if (!isMem() || Memory.Alignment != 0) return false;
916 // No shifts are legal for AM3.
917 if (Memory.ShiftType != ARM_AM::no_shift) return false;
918 // Check for register offset.
919 if (Memory.OffsetRegNum) return true;
920 // Immediate offset in range [-255, 255].
921 if (!Memory.OffsetImm) return true;
922 int64_t Val = Memory.OffsetImm->getValue();
923 // The #-0 offset is encoded as INT32_MIN, and we have to check
925 return (Val > -256 && Val < 256) || Val == INT32_MIN;
927 bool isAM3Offset() const {
928 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
930 if (Kind == k_PostIndexRegister)
931 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
932 // Immediate offset in range [-255, 255].
933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
934 if (!CE) return false;
935 int64_t Val = CE->getValue();
936 // Special case, #-0 is INT32_MIN.
937 return (Val > -256 && Val < 256) || Val == INT32_MIN;
939 bool isAddrMode5() const {
940 // If we have an immediate that's not a constant, treat it as a label
941 // reference needing a fixup. If it is a constant, it's something else
943 if (isImm() && !isa<MCConstantExpr>(getImm()))
945 if (!isMem() || Memory.Alignment != 0) return false;
946 // Check for register offset.
947 if (Memory.OffsetRegNum) return false;
948 // Immediate offset in range [-1020, 1020] and a multiple of 4.
949 if (!Memory.OffsetImm) return true;
950 int64_t Val = Memory.OffsetImm->getValue();
951 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
954 bool isMemTBB() const {
955 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
956 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
960 bool isMemTBH() const {
961 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
962 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
963 Memory.Alignment != 0 )
967 bool isMemRegOffset() const {
968 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
972 bool isT2MemRegOffset() const {
973 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
974 Memory.Alignment != 0)
976 // Only lsl #{0, 1, 2, 3} allowed.
977 if (Memory.ShiftType == ARM_AM::no_shift)
979 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
983 bool isMemThumbRR() const {
984 // Thumb reg+reg addressing is simple. Just two registers, a base and
985 // an offset. No shifts, negations or any other complicating factors.
986 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
987 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
989 return isARMLowRegister(Memory.BaseRegNum) &&
990 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
992 bool isMemThumbRIs4() const {
993 if (!isMem() || Memory.OffsetRegNum != 0 ||
994 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
996 // Immediate offset, multiple of 4 in range [0, 124].
997 if (!Memory.OffsetImm) return true;
998 int64_t Val = Memory.OffsetImm->getValue();
999 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1001 bool isMemThumbRIs2() const {
1002 if (!isMem() || Memory.OffsetRegNum != 0 ||
1003 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1005 // Immediate offset, multiple of 4 in range [0, 62].
1006 if (!Memory.OffsetImm) return true;
1007 int64_t Val = Memory.OffsetImm->getValue();
1008 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1010 bool isMemThumbRIs1() const {
1011 if (!isMem() || Memory.OffsetRegNum != 0 ||
1012 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1014 // Immediate offset in range [0, 31].
1015 if (!Memory.OffsetImm) return true;
1016 int64_t Val = Memory.OffsetImm->getValue();
1017 return Val >= 0 && Val <= 31;
1019 bool isMemThumbSPI() const {
1020 if (!isMem() || Memory.OffsetRegNum != 0 ||
1021 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1023 // Immediate offset, multiple of 4 in range [0, 1020].
1024 if (!Memory.OffsetImm) return true;
1025 int64_t Val = Memory.OffsetImm->getValue();
1026 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1028 bool isMemImm8s4Offset() const {
1029 // If we have an immediate that's not a constant, treat it as a label
1030 // reference needing a fixup. If it is a constant, it's something else
1031 // and we reject it.
1032 if (isImm() && !isa<MCConstantExpr>(getImm()))
1034 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1036 // Immediate offset a multiple of 4 in range [-1020, 1020].
1037 if (!Memory.OffsetImm) return true;
1038 int64_t Val = Memory.OffsetImm->getValue();
1039 // Special case, #-0 is INT32_MIN.
1040 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1042 bool isMemImm0_1020s4Offset() const {
1043 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1045 // Immediate offset a multiple of 4 in range [0, 1020].
1046 if (!Memory.OffsetImm) return true;
1047 int64_t Val = Memory.OffsetImm->getValue();
1048 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1050 bool isMemImm8Offset() const {
1051 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1053 // Base reg of PC isn't allowed for these encodings.
1054 if (Memory.BaseRegNum == ARM::PC) return false;
1055 // Immediate offset in range [-255, 255].
1056 if (!Memory.OffsetImm) return true;
1057 int64_t Val = Memory.OffsetImm->getValue();
1058 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1060 bool isMemPosImm8Offset() const {
1061 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1063 // Immediate offset in range [0, 255].
1064 if (!Memory.OffsetImm) return true;
1065 int64_t Val = Memory.OffsetImm->getValue();
1066 return Val >= 0 && Val < 256;
1068 bool isMemNegImm8Offset() const {
1069 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1071 // Base reg of PC isn't allowed for these encodings.
1072 if (Memory.BaseRegNum == ARM::PC) return false;
1073 // Immediate offset in range [-255, -1].
1074 if (!Memory.OffsetImm) return false;
1075 int64_t Val = Memory.OffsetImm->getValue();
1076 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1078 bool isMemUImm12Offset() const {
1079 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1081 // Immediate offset in range [0, 4095].
1082 if (!Memory.OffsetImm) return true;
1083 int64_t Val = Memory.OffsetImm->getValue();
1084 return (Val >= 0 && Val < 4096);
1086 bool isMemImm12Offset() const {
1087 // If we have an immediate that's not a constant, treat it as a label
1088 // reference needing a fixup. If it is a constant, it's something else
1089 // and we reject it.
1090 if (isImm() && !isa<MCConstantExpr>(getImm()))
1093 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1095 // Immediate offset in range [-4095, 4095].
1096 if (!Memory.OffsetImm) return true;
1097 int64_t Val = Memory.OffsetImm->getValue();
1098 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1100 bool isPostIdxImm8() const {
1101 if (!isImm()) return false;
1102 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1103 if (!CE) return false;
1104 int64_t Val = CE->getValue();
1105 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1107 bool isPostIdxImm8s4() const {
1108 if (!isImm()) return false;
1109 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1110 if (!CE) return false;
1111 int64_t Val = CE->getValue();
1112 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1116 bool isMSRMask() const { return Kind == k_MSRMask; }
1117 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1120 bool isSingleSpacedVectorList() const {
1121 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1123 bool isDoubleSpacedVectorList() const {
1124 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1126 bool isVecListOneD() const {
1127 if (!isSingleSpacedVectorList()) return false;
1128 return VectorList.Count == 1;
1131 bool isVecListDPair() const {
1132 if (!isSingleSpacedVectorList()) return false;
1133 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1134 .contains(VectorList.RegNum));
1137 bool isVecListThreeD() const {
1138 if (!isSingleSpacedVectorList()) return false;
1139 return VectorList.Count == 3;
1142 bool isVecListFourD() const {
1143 if (!isSingleSpacedVectorList()) return false;
1144 return VectorList.Count == 4;
1147 bool isVecListDPairSpaced() const {
1148 if (isSingleSpacedVectorList()) return false;
1149 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1150 .contains(VectorList.RegNum));
1153 bool isVecListThreeQ() const {
1154 if (!isDoubleSpacedVectorList()) return false;
1155 return VectorList.Count == 3;
1158 bool isVecListFourQ() const {
1159 if (!isDoubleSpacedVectorList()) return false;
1160 return VectorList.Count == 4;
1163 bool isSingleSpacedVectorAllLanes() const {
1164 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1166 bool isDoubleSpacedVectorAllLanes() const {
1167 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1169 bool isVecListOneDAllLanes() const {
1170 if (!isSingleSpacedVectorAllLanes()) return false;
1171 return VectorList.Count == 1;
1174 bool isVecListDPairAllLanes() const {
1175 if (!isSingleSpacedVectorAllLanes()) return false;
1176 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1177 .contains(VectorList.RegNum));
1180 bool isVecListDPairSpacedAllLanes() const {
1181 if (!isDoubleSpacedVectorAllLanes()) return false;
1182 return VectorList.Count == 2;
1185 bool isVecListThreeDAllLanes() const {
1186 if (!isSingleSpacedVectorAllLanes()) return false;
1187 return VectorList.Count == 3;
1190 bool isVecListThreeQAllLanes() const {
1191 if (!isDoubleSpacedVectorAllLanes()) return false;
1192 return VectorList.Count == 3;
1195 bool isVecListFourDAllLanes() const {
1196 if (!isSingleSpacedVectorAllLanes()) return false;
1197 return VectorList.Count == 4;
1200 bool isVecListFourQAllLanes() const {
1201 if (!isDoubleSpacedVectorAllLanes()) return false;
1202 return VectorList.Count == 4;
1205 bool isSingleSpacedVectorIndexed() const {
1206 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1208 bool isDoubleSpacedVectorIndexed() const {
1209 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1211 bool isVecListOneDByteIndexed() const {
1212 if (!isSingleSpacedVectorIndexed()) return false;
1213 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1216 bool isVecListOneDHWordIndexed() const {
1217 if (!isSingleSpacedVectorIndexed()) return false;
1218 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1221 bool isVecListOneDWordIndexed() const {
1222 if (!isSingleSpacedVectorIndexed()) return false;
1223 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1226 bool isVecListTwoDByteIndexed() const {
1227 if (!isSingleSpacedVectorIndexed()) return false;
1228 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1231 bool isVecListTwoDHWordIndexed() const {
1232 if (!isSingleSpacedVectorIndexed()) return false;
1233 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1236 bool isVecListTwoQWordIndexed() const {
1237 if (!isDoubleSpacedVectorIndexed()) return false;
1238 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1241 bool isVecListTwoQHWordIndexed() const {
1242 if (!isDoubleSpacedVectorIndexed()) return false;
1243 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1246 bool isVecListTwoDWordIndexed() const {
1247 if (!isSingleSpacedVectorIndexed()) return false;
1248 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1251 bool isVecListThreeDByteIndexed() const {
1252 if (!isSingleSpacedVectorIndexed()) return false;
1253 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1256 bool isVecListThreeDHWordIndexed() const {
1257 if (!isSingleSpacedVectorIndexed()) return false;
1258 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1261 bool isVecListThreeQWordIndexed() const {
1262 if (!isDoubleSpacedVectorIndexed()) return false;
1263 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1266 bool isVecListThreeQHWordIndexed() const {
1267 if (!isDoubleSpacedVectorIndexed()) return false;
1268 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1271 bool isVecListThreeDWordIndexed() const {
1272 if (!isSingleSpacedVectorIndexed()) return false;
1273 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1276 bool isVecListFourDByteIndexed() const {
1277 if (!isSingleSpacedVectorIndexed()) return false;
1278 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1281 bool isVecListFourDHWordIndexed() const {
1282 if (!isSingleSpacedVectorIndexed()) return false;
1283 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1286 bool isVecListFourQWordIndexed() const {
1287 if (!isDoubleSpacedVectorIndexed()) return false;
1288 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1291 bool isVecListFourQHWordIndexed() const {
1292 if (!isDoubleSpacedVectorIndexed()) return false;
1293 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1296 bool isVecListFourDWordIndexed() const {
1297 if (!isSingleSpacedVectorIndexed()) return false;
1298 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1301 bool isVectorIndex8() const {
1302 if (Kind != k_VectorIndex) return false;
1303 return VectorIndex.Val < 8;
1305 bool isVectorIndex16() const {
1306 if (Kind != k_VectorIndex) return false;
1307 return VectorIndex.Val < 4;
1309 bool isVectorIndex32() const {
1310 if (Kind != k_VectorIndex) return false;
1311 return VectorIndex.Val < 2;
1314 bool isNEONi8splat() const {
1315 if (!isImm()) return false;
1316 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1317 // Must be a constant.
1318 if (!CE) return false;
1319 int64_t Value = CE->getValue();
1320 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1322 return Value >= 0 && Value < 256;
1325 bool isNEONi16splat() const {
1326 if (!isImm()) return false;
1327 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1328 // Must be a constant.
1329 if (!CE) return false;
1330 int64_t Value = CE->getValue();
1331 // i16 value in the range [0,255] or [0x0100, 0xff00]
1332 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1335 bool isNEONi32splat() const {
1336 if (!isImm()) return false;
1337 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1338 // Must be a constant.
1339 if (!CE) return false;
1340 int64_t Value = CE->getValue();
1341 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1342 return (Value >= 0 && Value < 256) ||
1343 (Value >= 0x0100 && Value <= 0xff00) ||
1344 (Value >= 0x010000 && Value <= 0xff0000) ||
1345 (Value >= 0x01000000 && Value <= 0xff000000);
1348 bool isNEONi32vmov() const {
1349 if (!isImm()) return false;
1350 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1351 // Must be a constant.
1352 if (!CE) return false;
1353 int64_t Value = CE->getValue();
1354 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1355 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1356 return (Value >= 0 && Value < 256) ||
1357 (Value >= 0x0100 && Value <= 0xff00) ||
1358 (Value >= 0x010000 && Value <= 0xff0000) ||
1359 (Value >= 0x01000000 && Value <= 0xff000000) ||
1360 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1361 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1363 bool isNEONi32vmovNeg() const {
1364 if (!isImm()) return false;
1365 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1366 // Must be a constant.
1367 if (!CE) return false;
1368 int64_t Value = ~CE->getValue();
1369 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1370 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1371 return (Value >= 0 && Value < 256) ||
1372 (Value >= 0x0100 && Value <= 0xff00) ||
1373 (Value >= 0x010000 && Value <= 0xff0000) ||
1374 (Value >= 0x01000000 && Value <= 0xff000000) ||
1375 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1376 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1379 bool isNEONi64splat() const {
1380 if (!isImm()) return false;
1381 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1382 // Must be a constant.
1383 if (!CE) return false;
1384 uint64_t Value = CE->getValue();
1385 // i64 value with each byte being either 0 or 0xff.
1386 for (unsigned i = 0; i < 8; ++i)
1387 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1391 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1392 // Add as immediates when possible. Null MCExpr = 0.
1394 Inst.addOperand(MCOperand::CreateImm(0));
1395 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1396 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1398 Inst.addOperand(MCOperand::CreateExpr(Expr));
1401 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1402 assert(N == 2 && "Invalid number of operands!");
1403 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1404 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1405 Inst.addOperand(MCOperand::CreateReg(RegNum));
1408 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1409 assert(N == 1 && "Invalid number of operands!");
1410 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1413 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1414 assert(N == 1 && "Invalid number of operands!");
1415 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1418 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1419 assert(N == 1 && "Invalid number of operands!");
1420 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1423 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1424 assert(N == 1 && "Invalid number of operands!");
1425 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1428 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1429 assert(N == 1 && "Invalid number of operands!");
1430 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1433 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1434 assert(N == 1 && "Invalid number of operands!");
1435 Inst.addOperand(MCOperand::CreateReg(getReg()));
1438 void addRegOperands(MCInst &Inst, unsigned N) const {
1439 assert(N == 1 && "Invalid number of operands!");
1440 Inst.addOperand(MCOperand::CreateReg(getReg()));
1443 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1444 assert(N == 3 && "Invalid number of operands!");
1445 assert(isRegShiftedReg() &&
1446 "addRegShiftedRegOperands() on non RegShiftedReg!");
1447 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1448 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1449 Inst.addOperand(MCOperand::CreateImm(
1450 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1453 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1454 assert(N == 2 && "Invalid number of operands!");
1455 assert(isRegShiftedImm() &&
1456 "addRegShiftedImmOperands() on non RegShiftedImm!");
1457 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1458 // Shift of #32 is encoded as 0 where permitted
1459 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1460 Inst.addOperand(MCOperand::CreateImm(
1461 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1464 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1465 assert(N == 1 && "Invalid number of operands!");
1466 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1470 void addRegListOperands(MCInst &Inst, unsigned N) const {
1471 assert(N == 1 && "Invalid number of operands!");
1472 const SmallVectorImpl<unsigned> &RegList = getRegList();
1473 for (SmallVectorImpl<unsigned>::const_iterator
1474 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1475 Inst.addOperand(MCOperand::CreateReg(*I));
1478 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1479 addRegListOperands(Inst, N);
1482 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1483 addRegListOperands(Inst, N);
1486 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1487 assert(N == 1 && "Invalid number of operands!");
1488 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1489 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1492 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1493 assert(N == 1 && "Invalid number of operands!");
1494 // Munge the lsb/width into a bitfield mask.
1495 unsigned lsb = Bitfield.LSB;
1496 unsigned width = Bitfield.Width;
1497 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1498 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1499 (32 - (lsb + width)));
1500 Inst.addOperand(MCOperand::CreateImm(Mask));
1503 void addImmOperands(MCInst &Inst, unsigned N) const {
1504 assert(N == 1 && "Invalid number of operands!");
1505 addExpr(Inst, getImm());
1508 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1509 assert(N == 1 && "Invalid number of operands!");
1510 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1511 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1514 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1515 assert(N == 1 && "Invalid number of operands!");
1516 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1517 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1520 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1521 assert(N == 1 && "Invalid number of operands!");
1522 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1523 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1524 Inst.addOperand(MCOperand::CreateImm(Val));
1527 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1528 assert(N == 1 && "Invalid number of operands!");
1529 // FIXME: We really want to scale the value here, but the LDRD/STRD
1530 // instruction don't encode operands that way yet.
1531 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1532 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1535 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1536 assert(N == 1 && "Invalid number of operands!");
1537 // The immediate is scaled by four in the encoding and is stored
1538 // in the MCInst as such. Lop off the low two bits here.
1539 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1540 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1543 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1544 assert(N == 1 && "Invalid number of operands!");
1545 // The immediate is scaled by four in the encoding and is stored
1546 // in the MCInst as such. Lop off the low two bits here.
1547 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1548 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1551 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1552 assert(N == 1 && "Invalid number of operands!");
1553 // The immediate is scaled by four in the encoding and is stored
1554 // in the MCInst as such. Lop off the low two bits here.
1555 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1556 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1559 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1560 assert(N == 1 && "Invalid number of operands!");
1561 // The constant encodes as the immediate-1, and we store in the instruction
1562 // the bits as encoded, so subtract off one here.
1563 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1564 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1567 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1568 assert(N == 1 && "Invalid number of operands!");
1569 // The constant encodes as the immediate-1, and we store in the instruction
1570 // the bits as encoded, so subtract off one here.
1571 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1572 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1575 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1576 assert(N == 1 && "Invalid number of operands!");
1577 // The constant encodes as the immediate, except for 32, which encodes as
1579 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1580 unsigned Imm = CE->getValue();
1581 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1584 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1585 assert(N == 1 && "Invalid number of operands!");
1586 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1587 // the instruction as well.
1588 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1589 int Val = CE->getValue();
1590 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1593 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1594 assert(N == 1 && "Invalid number of operands!");
1595 // The operand is actually a t2_so_imm, but we have its bitwise
1596 // negation in the assembly source, so twiddle it here.
1597 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1598 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1601 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1602 assert(N == 1 && "Invalid number of operands!");
1603 // The operand is actually a t2_so_imm, but we have its
1604 // negation in the assembly source, so twiddle it here.
1605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1606 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1609 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1610 assert(N == 1 && "Invalid number of operands!");
1611 // The operand is actually an imm0_4095, but we have its
1612 // negation in the assembly source, so twiddle it here.
1613 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1614 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1617 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1618 assert(N == 1 && "Invalid number of operands!");
1619 // The operand is actually a so_imm, but we have its bitwise
1620 // negation in the assembly source, so twiddle it here.
1621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1622 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1625 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1626 assert(N == 1 && "Invalid number of operands!");
1627 // The operand is actually a so_imm, but we have its
1628 // negation in the assembly source, so twiddle it here.
1629 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1630 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1633 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1634 assert(N == 1 && "Invalid number of operands!");
1635 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1638 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1639 assert(N == 1 && "Invalid number of operands!");
1640 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1643 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1644 assert(N == 1 && "Invalid number of operands!");
1645 int32_t Imm = Memory.OffsetImm->getValue();
1646 // FIXME: Handle #-0
1647 if (Imm == INT32_MIN) Imm = 0;
1648 Inst.addOperand(MCOperand::CreateImm(Imm));
1651 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1652 assert(N == 1 && "Invalid number of operands!");
1653 assert(isImm() && "Not an immediate!");
1655 // If we have an immediate that's not a constant, treat it as a label
1656 // reference needing a fixup.
1657 if (!isa<MCConstantExpr>(getImm())) {
1658 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1663 int Val = CE->getValue();
1664 Inst.addOperand(MCOperand::CreateImm(Val));
1667 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1668 assert(N == 2 && "Invalid number of operands!");
1669 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1670 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1673 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1674 assert(N == 3 && "Invalid number of operands!");
1675 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1676 if (!Memory.OffsetRegNum) {
1677 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1678 // Special case for #-0
1679 if (Val == INT32_MIN) Val = 0;
1680 if (Val < 0) Val = -Val;
1681 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1683 // For register offset, we encode the shift type and negation flag
1685 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1686 Memory.ShiftImm, Memory.ShiftType);
1688 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1689 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1690 Inst.addOperand(MCOperand::CreateImm(Val));
1693 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1694 assert(N == 2 && "Invalid number of operands!");
1695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1696 assert(CE && "non-constant AM2OffsetImm operand!");
1697 int32_t Val = CE->getValue();
1698 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1699 // Special case for #-0
1700 if (Val == INT32_MIN) Val = 0;
1701 if (Val < 0) Val = -Val;
1702 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1703 Inst.addOperand(MCOperand::CreateReg(0));
1704 Inst.addOperand(MCOperand::CreateImm(Val));
1707 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1708 assert(N == 3 && "Invalid number of operands!");
1709 // If we have an immediate that's not a constant, treat it as a label
1710 // reference needing a fixup. If it is a constant, it's something else
1711 // and we reject it.
1713 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1714 Inst.addOperand(MCOperand::CreateReg(0));
1715 Inst.addOperand(MCOperand::CreateImm(0));
1719 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1720 if (!Memory.OffsetRegNum) {
1721 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1722 // Special case for #-0
1723 if (Val == INT32_MIN) Val = 0;
1724 if (Val < 0) Val = -Val;
1725 Val = ARM_AM::getAM3Opc(AddSub, Val);
1727 // For register offset, we encode the shift type and negation flag
1729 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1731 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1732 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1733 Inst.addOperand(MCOperand::CreateImm(Val));
1736 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1737 assert(N == 2 && "Invalid number of operands!");
1738 if (Kind == k_PostIndexRegister) {
1740 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1741 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1742 Inst.addOperand(MCOperand::CreateImm(Val));
1747 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1748 int32_t Val = CE->getValue();
1749 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1750 // Special case for #-0
1751 if (Val == INT32_MIN) Val = 0;
1752 if (Val < 0) Val = -Val;
1753 Val = ARM_AM::getAM3Opc(AddSub, Val);
1754 Inst.addOperand(MCOperand::CreateReg(0));
1755 Inst.addOperand(MCOperand::CreateImm(Val));
1758 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1759 assert(N == 2 && "Invalid number of operands!");
1760 // If we have an immediate that's not a constant, treat it as a label
1761 // reference needing a fixup. If it is a constant, it's something else
1762 // and we reject it.
1764 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1765 Inst.addOperand(MCOperand::CreateImm(0));
1769 // The lower two bits are always zero and as such are not encoded.
1770 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1771 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1772 // Special case for #-0
1773 if (Val == INT32_MIN) Val = 0;
1774 if (Val < 0) Val = -Val;
1775 Val = ARM_AM::getAM5Opc(AddSub, Val);
1776 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1777 Inst.addOperand(MCOperand::CreateImm(Val));
1780 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1781 assert(N == 2 && "Invalid number of operands!");
1782 // If we have an immediate that's not a constant, treat it as a label
1783 // reference needing a fixup. If it is a constant, it's something else
1784 // and we reject it.
1786 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1787 Inst.addOperand(MCOperand::CreateImm(0));
1791 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1792 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1793 Inst.addOperand(MCOperand::CreateImm(Val));
1796 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1797 assert(N == 2 && "Invalid number of operands!");
1798 // The lower two bits are always zero and as such are not encoded.
1799 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1800 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1801 Inst.addOperand(MCOperand::CreateImm(Val));
1804 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1805 assert(N == 2 && "Invalid number of operands!");
1806 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1807 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1808 Inst.addOperand(MCOperand::CreateImm(Val));
1811 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1812 addMemImm8OffsetOperands(Inst, N);
1815 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1816 addMemImm8OffsetOperands(Inst, N);
1819 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1820 assert(N == 2 && "Invalid number of operands!");
1821 // If this is an immediate, it's a label reference.
1823 addExpr(Inst, getImm());
1824 Inst.addOperand(MCOperand::CreateImm(0));
1828 // Otherwise, it's a normal memory reg+offset.
1829 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1830 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1831 Inst.addOperand(MCOperand::CreateImm(Val));
1834 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1835 assert(N == 2 && "Invalid number of operands!");
1836 // If this is an immediate, it's a label reference.
1838 addExpr(Inst, getImm());
1839 Inst.addOperand(MCOperand::CreateImm(0));
1843 // Otherwise, it's a normal memory reg+offset.
1844 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1845 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1846 Inst.addOperand(MCOperand::CreateImm(Val));
1849 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1850 assert(N == 2 && "Invalid number of operands!");
1851 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1852 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1855 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1856 assert(N == 2 && "Invalid number of operands!");
1857 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1858 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1861 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1862 assert(N == 3 && "Invalid number of operands!");
1864 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1865 Memory.ShiftImm, Memory.ShiftType);
1866 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1867 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1868 Inst.addOperand(MCOperand::CreateImm(Val));
1871 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1872 assert(N == 3 && "Invalid number of operands!");
1873 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1874 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1875 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
1878 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1879 assert(N == 2 && "Invalid number of operands!");
1880 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1881 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1884 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1885 assert(N == 2 && "Invalid number of operands!");
1886 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1887 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1888 Inst.addOperand(MCOperand::CreateImm(Val));
1891 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1892 assert(N == 2 && "Invalid number of operands!");
1893 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1894 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1895 Inst.addOperand(MCOperand::CreateImm(Val));
1898 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1899 assert(N == 2 && "Invalid number of operands!");
1900 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1901 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1902 Inst.addOperand(MCOperand::CreateImm(Val));
1905 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1906 assert(N == 2 && "Invalid number of operands!");
1907 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1908 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1909 Inst.addOperand(MCOperand::CreateImm(Val));
1912 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1913 assert(N == 1 && "Invalid number of operands!");
1914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1915 assert(CE && "non-constant post-idx-imm8 operand!");
1916 int Imm = CE->getValue();
1917 bool isAdd = Imm >= 0;
1918 if (Imm == INT32_MIN) Imm = 0;
1919 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1920 Inst.addOperand(MCOperand::CreateImm(Imm));
1923 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1924 assert(N == 1 && "Invalid number of operands!");
1925 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1926 assert(CE && "non-constant post-idx-imm8s4 operand!");
1927 int Imm = CE->getValue();
1928 bool isAdd = Imm >= 0;
1929 if (Imm == INT32_MIN) Imm = 0;
1930 // Immediate is scaled by 4.
1931 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1932 Inst.addOperand(MCOperand::CreateImm(Imm));
1935 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1936 assert(N == 2 && "Invalid number of operands!");
1937 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1938 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1941 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1942 assert(N == 2 && "Invalid number of operands!");
1943 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1944 // The sign, shift type, and shift amount are encoded in a single operand
1945 // using the AM2 encoding helpers.
1946 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1947 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1948 PostIdxReg.ShiftTy);
1949 Inst.addOperand(MCOperand::CreateImm(Imm));
1952 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1953 assert(N == 1 && "Invalid number of operands!");
1954 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1957 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1958 assert(N == 1 && "Invalid number of operands!");
1959 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1962 void addVecListOperands(MCInst &Inst, unsigned N) const {
1963 assert(N == 1 && "Invalid number of operands!");
1964 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1967 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1968 assert(N == 2 && "Invalid number of operands!");
1969 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1970 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1973 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1974 assert(N == 1 && "Invalid number of operands!");
1975 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1978 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1979 assert(N == 1 && "Invalid number of operands!");
1980 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1983 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1984 assert(N == 1 && "Invalid number of operands!");
1985 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1988 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1989 assert(N == 1 && "Invalid number of operands!");
1990 // The immediate encodes the type of constant as well as the value.
1991 // Mask in that this is an i8 splat.
1992 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1993 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1996 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1997 assert(N == 1 && "Invalid number of operands!");
1998 // The immediate encodes the type of constant as well as the value.
1999 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2000 unsigned Value = CE->getValue();
2002 Value = (Value >> 8) | 0xa00;
2005 Inst.addOperand(MCOperand::CreateImm(Value));
2008 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2009 assert(N == 1 && "Invalid number of operands!");
2010 // The immediate encodes the type of constant as well as the value.
2011 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2012 unsigned Value = CE->getValue();
2013 if (Value >= 256 && Value <= 0xff00)
2014 Value = (Value >> 8) | 0x200;
2015 else if (Value > 0xffff && Value <= 0xff0000)
2016 Value = (Value >> 16) | 0x400;
2017 else if (Value > 0xffffff)
2018 Value = (Value >> 24) | 0x600;
2019 Inst.addOperand(MCOperand::CreateImm(Value));
2022 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2023 assert(N == 1 && "Invalid number of operands!");
2024 // The immediate encodes the type of constant as well as the value.
2025 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2026 unsigned Value = CE->getValue();
2027 if (Value >= 256 && Value <= 0xffff)
2028 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2029 else if (Value > 0xffff && Value <= 0xffffff)
2030 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2031 else if (Value > 0xffffff)
2032 Value = (Value >> 24) | 0x600;
2033 Inst.addOperand(MCOperand::CreateImm(Value));
2036 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2037 assert(N == 1 && "Invalid number of operands!");
2038 // The immediate encodes the type of constant as well as the value.
2039 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2040 unsigned Value = ~CE->getValue();
2041 if (Value >= 256 && Value <= 0xffff)
2042 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2043 else if (Value > 0xffff && Value <= 0xffffff)
2044 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2045 else if (Value > 0xffffff)
2046 Value = (Value >> 24) | 0x600;
2047 Inst.addOperand(MCOperand::CreateImm(Value));
2050 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2051 assert(N == 1 && "Invalid number of operands!");
2052 // The immediate encodes the type of constant as well as the value.
2053 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2054 uint64_t Value = CE->getValue();
2056 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2057 Imm |= (Value & 1) << i;
2059 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2062 virtual void print(raw_ostream &OS) const;
2064 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2065 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2066 Op->ITMask.Mask = Mask;
2072 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2073 ARMOperand *Op = new ARMOperand(k_CondCode);
2080 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2081 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2082 Op->Cop.Val = CopVal;
2088 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2089 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2090 Op->Cop.Val = CopVal;
2096 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2097 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2104 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2105 ARMOperand *Op = new ARMOperand(k_CCOut);
2106 Op->Reg.RegNum = RegNum;
2112 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2113 ARMOperand *Op = new ARMOperand(k_Token);
2114 Op->Tok.Data = Str.data();
2115 Op->Tok.Length = Str.size();
2121 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2122 ARMOperand *Op = new ARMOperand(k_Register);
2123 Op->Reg.RegNum = RegNum;
2129 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2134 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2135 Op->RegShiftedReg.ShiftTy = ShTy;
2136 Op->RegShiftedReg.SrcReg = SrcReg;
2137 Op->RegShiftedReg.ShiftReg = ShiftReg;
2138 Op->RegShiftedReg.ShiftImm = ShiftImm;
2144 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2148 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2149 Op->RegShiftedImm.ShiftTy = ShTy;
2150 Op->RegShiftedImm.SrcReg = SrcReg;
2151 Op->RegShiftedImm.ShiftImm = ShiftImm;
2157 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2159 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2160 Op->ShifterImm.isASR = isASR;
2161 Op->ShifterImm.Imm = Imm;
2167 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2168 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2169 Op->RotImm.Imm = Imm;
2175 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2177 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2178 Op->Bitfield.LSB = LSB;
2179 Op->Bitfield.Width = Width;
2186 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
2187 SMLoc StartLoc, SMLoc EndLoc) {
2188 KindTy Kind = k_RegisterList;
2190 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
2191 Kind = k_DPRRegisterList;
2192 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2193 contains(Regs.front().first))
2194 Kind = k_SPRRegisterList;
2196 ARMOperand *Op = new ARMOperand(Kind);
2197 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
2198 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2199 Op->Registers.push_back(I->first);
2200 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
2201 Op->StartLoc = StartLoc;
2202 Op->EndLoc = EndLoc;
2206 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2207 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2208 ARMOperand *Op = new ARMOperand(k_VectorList);
2209 Op->VectorList.RegNum = RegNum;
2210 Op->VectorList.Count = Count;
2211 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2217 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2218 bool isDoubleSpaced,
2220 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2221 Op->VectorList.RegNum = RegNum;
2222 Op->VectorList.Count = Count;
2223 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2229 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2231 bool isDoubleSpaced,
2233 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2234 Op->VectorList.RegNum = RegNum;
2235 Op->VectorList.Count = Count;
2236 Op->VectorList.LaneIndex = Index;
2237 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2243 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2245 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2246 Op->VectorIndex.Val = Idx;
2252 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2253 ARMOperand *Op = new ARMOperand(k_Immediate);
2260 static ARMOperand *CreateMem(unsigned BaseRegNum,
2261 const MCConstantExpr *OffsetImm,
2262 unsigned OffsetRegNum,
2263 ARM_AM::ShiftOpc ShiftType,
2268 ARMOperand *Op = new ARMOperand(k_Memory);
2269 Op->Memory.BaseRegNum = BaseRegNum;
2270 Op->Memory.OffsetImm = OffsetImm;
2271 Op->Memory.OffsetRegNum = OffsetRegNum;
2272 Op->Memory.ShiftType = ShiftType;
2273 Op->Memory.ShiftImm = ShiftImm;
2274 Op->Memory.Alignment = Alignment;
2275 Op->Memory.isNegative = isNegative;
2281 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2282 ARM_AM::ShiftOpc ShiftTy,
2285 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2286 Op->PostIdxReg.RegNum = RegNum;
2287 Op->PostIdxReg.isAdd = isAdd;
2288 Op->PostIdxReg.ShiftTy = ShiftTy;
2289 Op->PostIdxReg.ShiftImm = ShiftImm;
2295 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2296 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2297 Op->MBOpt.Val = Opt;
2303 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2304 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2305 Op->IFlags.Val = IFlags;
2311 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2312 ARMOperand *Op = new ARMOperand(k_MSRMask);
2313 Op->MMask.Val = MMask;
2320 } // end anonymous namespace.
2322 void ARMOperand::print(raw_ostream &OS) const {
2325 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2328 OS << "<ccout " << getReg() << ">";
2330 case k_ITCondMask: {
2331 static const char *const MaskStr[] = {
2332 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2333 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2335 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2336 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2340 OS << "<coprocessor number: " << getCoproc() << ">";
2343 OS << "<coprocessor register: " << getCoproc() << ">";
2345 case k_CoprocOption:
2346 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2349 OS << "<mask: " << getMSRMask() << ">";
2352 getImm()->print(OS);
2354 case k_MemBarrierOpt:
2355 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2359 << " base:" << Memory.BaseRegNum;
2362 case k_PostIndexRegister:
2363 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2364 << PostIdxReg.RegNum;
2365 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2366 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2367 << PostIdxReg.ShiftImm;
2370 case k_ProcIFlags: {
2371 OS << "<ARM_PROC::";
2372 unsigned IFlags = getProcIFlags();
2373 for (int i=2; i >= 0; --i)
2374 if (IFlags & (1 << i))
2375 OS << ARM_PROC::IFlagsToString(1 << i);
2380 OS << "<register " << getReg() << ">";
2382 case k_ShifterImmediate:
2383 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2384 << " #" << ShifterImm.Imm << ">";
2386 case k_ShiftedRegister:
2387 OS << "<so_reg_reg "
2388 << RegShiftedReg.SrcReg << " "
2389 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2390 << " " << RegShiftedReg.ShiftReg << ">";
2392 case k_ShiftedImmediate:
2393 OS << "<so_reg_imm "
2394 << RegShiftedImm.SrcReg << " "
2395 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2396 << " #" << RegShiftedImm.ShiftImm << ">";
2398 case k_RotateImmediate:
2399 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2401 case k_BitfieldDescriptor:
2402 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2403 << ", width: " << Bitfield.Width << ">";
2405 case k_RegisterList:
2406 case k_DPRRegisterList:
2407 case k_SPRRegisterList: {
2408 OS << "<register_list ";
2410 const SmallVectorImpl<unsigned> &RegList = getRegList();
2411 for (SmallVectorImpl<unsigned>::const_iterator
2412 I = RegList.begin(), E = RegList.end(); I != E; ) {
2414 if (++I < E) OS << ", ";
2421 OS << "<vector_list " << VectorList.Count << " * "
2422 << VectorList.RegNum << ">";
2424 case k_VectorListAllLanes:
2425 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2426 << VectorList.RegNum << ">";
2428 case k_VectorListIndexed:
2429 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2430 << VectorList.Count << " * " << VectorList.RegNum << ">";
2433 OS << "'" << getToken() << "'";
2436 OS << "<vectorindex " << getVectorIndex() << ">";
2441 /// @name Auto-generated Match Functions
2444 static unsigned MatchRegisterName(StringRef Name);
2448 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2449 SMLoc &StartLoc, SMLoc &EndLoc) {
2450 StartLoc = Parser.getTok().getLoc();
2451 RegNo = tryParseRegister();
2452 EndLoc = Parser.getTok().getLoc();
2454 return (RegNo == (unsigned)-1);
2457 /// Try to parse a register name. The token must be an Identifier when called,
2458 /// and if it is a register name the token is eaten and the register number is
2459 /// returned. Otherwise return -1.
2461 int ARMAsmParser::tryParseRegister() {
2462 const AsmToken &Tok = Parser.getTok();
2463 if (Tok.isNot(AsmToken::Identifier)) return -1;
2465 std::string lowerCase = Tok.getString().lower();
2466 unsigned RegNum = MatchRegisterName(lowerCase);
2468 RegNum = StringSwitch<unsigned>(lowerCase)
2469 .Case("r13", ARM::SP)
2470 .Case("r14", ARM::LR)
2471 .Case("r15", ARM::PC)
2472 .Case("ip", ARM::R12)
2473 // Additional register name aliases for 'gas' compatibility.
2474 .Case("a1", ARM::R0)
2475 .Case("a2", ARM::R1)
2476 .Case("a3", ARM::R2)
2477 .Case("a4", ARM::R3)
2478 .Case("v1", ARM::R4)
2479 .Case("v2", ARM::R5)
2480 .Case("v3", ARM::R6)
2481 .Case("v4", ARM::R7)
2482 .Case("v5", ARM::R8)
2483 .Case("v6", ARM::R9)
2484 .Case("v7", ARM::R10)
2485 .Case("v8", ARM::R11)
2486 .Case("sb", ARM::R9)
2487 .Case("sl", ARM::R10)
2488 .Case("fp", ARM::R11)
2492 // Check for aliases registered via .req. Canonicalize to lower case.
2493 // That's more consistent since register names are case insensitive, and
2494 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2495 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2496 // If no match, return failure.
2497 if (Entry == RegisterReqs.end())
2499 Parser.Lex(); // Eat identifier token.
2500 return Entry->getValue();
2503 Parser.Lex(); // Eat identifier token.
2508 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2509 // If a recoverable error occurs, return 1. If an irrecoverable error
2510 // occurs, return -1. An irrecoverable error is one where tokens have been
2511 // consumed in the process of trying to parse the shifter (i.e., when it is
2512 // indeed a shifter operand, but malformed).
2513 int ARMAsmParser::tryParseShiftRegister(
2514 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2515 SMLoc S = Parser.getTok().getLoc();
2516 const AsmToken &Tok = Parser.getTok();
2517 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2519 std::string lowerCase = Tok.getString().lower();
2520 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2521 .Case("asl", ARM_AM::lsl)
2522 .Case("lsl", ARM_AM::lsl)
2523 .Case("lsr", ARM_AM::lsr)
2524 .Case("asr", ARM_AM::asr)
2525 .Case("ror", ARM_AM::ror)
2526 .Case("rrx", ARM_AM::rrx)
2527 .Default(ARM_AM::no_shift);
2529 if (ShiftTy == ARM_AM::no_shift)
2532 Parser.Lex(); // Eat the operator.
2534 // The source register for the shift has already been added to the
2535 // operand list, so we need to pop it off and combine it into the shifted
2536 // register operand instead.
2537 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2538 if (!PrevOp->isReg())
2539 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2540 int SrcReg = PrevOp->getReg();
2543 if (ShiftTy == ARM_AM::rrx) {
2544 // RRX Doesn't have an explicit shift amount. The encoder expects
2545 // the shift register to be the same as the source register. Seems odd,
2549 // Figure out if this is shifted by a constant or a register (for non-RRX).
2550 if (Parser.getTok().is(AsmToken::Hash) ||
2551 Parser.getTok().is(AsmToken::Dollar)) {
2552 Parser.Lex(); // Eat hash.
2553 SMLoc ImmLoc = Parser.getTok().getLoc();
2554 const MCExpr *ShiftExpr = 0;
2555 if (getParser().ParseExpression(ShiftExpr)) {
2556 Error(ImmLoc, "invalid immediate shift value");
2559 // The expression must be evaluatable as an immediate.
2560 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2562 Error(ImmLoc, "invalid immediate shift value");
2565 // Range check the immediate.
2566 // lsl, ror: 0 <= imm <= 31
2567 // lsr, asr: 0 <= imm <= 32
2568 Imm = CE->getValue();
2570 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2571 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2572 Error(ImmLoc, "immediate shift value out of range");
2575 // shift by zero is a nop. Always send it through as lsl.
2576 // ('as' compatibility)
2578 ShiftTy = ARM_AM::lsl;
2579 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2580 ShiftReg = tryParseRegister();
2581 SMLoc L = Parser.getTok().getLoc();
2582 if (ShiftReg == -1) {
2583 Error (L, "expected immediate or register in shift operand");
2587 Error (Parser.getTok().getLoc(),
2588 "expected immediate or register in shift operand");
2593 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2594 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2596 S, Parser.getTok().getLoc()));
2598 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2599 S, Parser.getTok().getLoc()));
2605 /// Try to parse a register name. The token must be an Identifier when called.
2606 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2607 /// if there is a "writeback". 'true' if it's not a register.
2609 /// TODO this is likely to change to allow different register types and or to
2610 /// parse for a specific register type.
2612 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2613 SMLoc S = Parser.getTok().getLoc();
2614 int RegNo = tryParseRegister();
2618 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
2620 const AsmToken &ExclaimTok = Parser.getTok();
2621 if (ExclaimTok.is(AsmToken::Exclaim)) {
2622 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2623 ExclaimTok.getLoc()));
2624 Parser.Lex(); // Eat exclaim token
2628 // Also check for an index operand. This is only legal for vector registers,
2629 // but that'll get caught OK in operand matching, so we don't need to
2630 // explicitly filter everything else out here.
2631 if (Parser.getTok().is(AsmToken::LBrac)) {
2632 SMLoc SIdx = Parser.getTok().getLoc();
2633 Parser.Lex(); // Eat left bracket token.
2635 const MCExpr *ImmVal;
2636 if (getParser().ParseExpression(ImmVal))
2638 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2640 return TokError("immediate value expected for vector index");
2642 SMLoc E = Parser.getTok().getLoc();
2643 if (Parser.getTok().isNot(AsmToken::RBrac))
2644 return Error(E, "']' expected");
2646 Parser.Lex(); // Eat right bracket token.
2648 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2656 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2657 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2659 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2660 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2662 switch (Name.size()) {
2665 if (Name[0] != CoprocOp)
2681 if (Name[0] != CoprocOp || Name[1] != '1')
2685 case '0': return 10;
2686 case '1': return 11;
2687 case '2': return 12;
2688 case '3': return 13;
2689 case '4': return 14;
2690 case '5': return 15;
2695 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2696 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2697 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2698 SMLoc S = Parser.getTok().getLoc();
2699 const AsmToken &Tok = Parser.getTok();
2700 if (!Tok.is(AsmToken::Identifier))
2701 return MatchOperand_NoMatch;
2702 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2703 .Case("eq", ARMCC::EQ)
2704 .Case("ne", ARMCC::NE)
2705 .Case("hs", ARMCC::HS)
2706 .Case("cs", ARMCC::HS)
2707 .Case("lo", ARMCC::LO)
2708 .Case("cc", ARMCC::LO)
2709 .Case("mi", ARMCC::MI)
2710 .Case("pl", ARMCC::PL)
2711 .Case("vs", ARMCC::VS)
2712 .Case("vc", ARMCC::VC)
2713 .Case("hi", ARMCC::HI)
2714 .Case("ls", ARMCC::LS)
2715 .Case("ge", ARMCC::GE)
2716 .Case("lt", ARMCC::LT)
2717 .Case("gt", ARMCC::GT)
2718 .Case("le", ARMCC::LE)
2719 .Case("al", ARMCC::AL)
2722 return MatchOperand_NoMatch;
2723 Parser.Lex(); // Eat the token.
2725 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2727 return MatchOperand_Success;
2730 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2731 /// token must be an Identifier when called, and if it is a coprocessor
2732 /// number, the token is eaten and the operand is added to the operand list.
2733 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2734 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2735 SMLoc S = Parser.getTok().getLoc();
2736 const AsmToken &Tok = Parser.getTok();
2737 if (Tok.isNot(AsmToken::Identifier))
2738 return MatchOperand_NoMatch;
2740 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2742 return MatchOperand_NoMatch;
2744 Parser.Lex(); // Eat identifier token.
2745 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2746 return MatchOperand_Success;
2749 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2750 /// token must be an Identifier when called, and if it is a coprocessor
2751 /// number, the token is eaten and the operand is added to the operand list.
2752 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2753 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2754 SMLoc S = Parser.getTok().getLoc();
2755 const AsmToken &Tok = Parser.getTok();
2756 if (Tok.isNot(AsmToken::Identifier))
2757 return MatchOperand_NoMatch;
2759 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2761 return MatchOperand_NoMatch;
2763 Parser.Lex(); // Eat identifier token.
2764 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2765 return MatchOperand_Success;
2768 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2769 /// coproc_option : '{' imm0_255 '}'
2770 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2771 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2772 SMLoc S = Parser.getTok().getLoc();
2774 // If this isn't a '{', this isn't a coprocessor immediate operand.
2775 if (Parser.getTok().isNot(AsmToken::LCurly))
2776 return MatchOperand_NoMatch;
2777 Parser.Lex(); // Eat the '{'
2780 SMLoc Loc = Parser.getTok().getLoc();
2781 if (getParser().ParseExpression(Expr)) {
2782 Error(Loc, "illegal expression");
2783 return MatchOperand_ParseFail;
2785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2786 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2787 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2788 return MatchOperand_ParseFail;
2790 int Val = CE->getValue();
2792 // Check for and consume the closing '}'
2793 if (Parser.getTok().isNot(AsmToken::RCurly))
2794 return MatchOperand_ParseFail;
2795 SMLoc E = Parser.getTok().getLoc();
2796 Parser.Lex(); // Eat the '}'
2798 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2799 return MatchOperand_Success;
2802 // For register list parsing, we need to map from raw GPR register numbering
2803 // to the enumeration values. The enumeration values aren't sorted by
2804 // register number due to our using "sp", "lr" and "pc" as canonical names.
2805 static unsigned getNextRegister(unsigned Reg) {
2806 // If this is a GPR, we need to do it manually, otherwise we can rely
2807 // on the sort ordering of the enumeration since the other reg-classes
2809 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2812 default: llvm_unreachable("Invalid GPR number!");
2813 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2814 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2815 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2816 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2817 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2818 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2819 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2820 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2824 // Return the low-subreg of a given Q register.
2825 static unsigned getDRegFromQReg(unsigned QReg) {
2827 default: llvm_unreachable("expected a Q register!");
2828 case ARM::Q0: return ARM::D0;
2829 case ARM::Q1: return ARM::D2;
2830 case ARM::Q2: return ARM::D4;
2831 case ARM::Q3: return ARM::D6;
2832 case ARM::Q4: return ARM::D8;
2833 case ARM::Q5: return ARM::D10;
2834 case ARM::Q6: return ARM::D12;
2835 case ARM::Q7: return ARM::D14;
2836 case ARM::Q8: return ARM::D16;
2837 case ARM::Q9: return ARM::D18;
2838 case ARM::Q10: return ARM::D20;
2839 case ARM::Q11: return ARM::D22;
2840 case ARM::Q12: return ARM::D24;
2841 case ARM::Q13: return ARM::D26;
2842 case ARM::Q14: return ARM::D28;
2843 case ARM::Q15: return ARM::D30;
2847 /// Parse a register list.
2849 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2850 assert(Parser.getTok().is(AsmToken::LCurly) &&
2851 "Token is not a Left Curly Brace");
2852 SMLoc S = Parser.getTok().getLoc();
2853 Parser.Lex(); // Eat '{' token.
2854 SMLoc RegLoc = Parser.getTok().getLoc();
2856 // Check the first register in the list to see what register class
2857 // this is a list of.
2858 int Reg = tryParseRegister();
2860 return Error(RegLoc, "register expected");
2862 // The reglist instructions have at most 16 registers, so reserve
2863 // space for that many.
2864 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2866 // Allow Q regs and just interpret them as the two D sub-registers.
2867 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2868 Reg = getDRegFromQReg(Reg);
2869 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2872 const MCRegisterClass *RC;
2873 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2874 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2875 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2876 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2877 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2878 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2880 return Error(RegLoc, "invalid register in register list");
2882 // Store the register.
2883 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2885 // This starts immediately after the first register token in the list,
2886 // so we can see either a comma or a minus (range separator) as a legal
2888 while (Parser.getTok().is(AsmToken::Comma) ||
2889 Parser.getTok().is(AsmToken::Minus)) {
2890 if (Parser.getTok().is(AsmToken::Minus)) {
2891 Parser.Lex(); // Eat the minus.
2892 SMLoc EndLoc = Parser.getTok().getLoc();
2893 int EndReg = tryParseRegister();
2895 return Error(EndLoc, "register expected");
2896 // Allow Q regs and just interpret them as the two D sub-registers.
2897 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2898 EndReg = getDRegFromQReg(EndReg) + 1;
2899 // If the register is the same as the start reg, there's nothing
2903 // The register must be in the same register class as the first.
2904 if (!RC->contains(EndReg))
2905 return Error(EndLoc, "invalid register in register list");
2906 // Ranges must go from low to high.
2907 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
2908 return Error(EndLoc, "bad range in register list");
2910 // Add all the registers in the range to the register list.
2911 while (Reg != EndReg) {
2912 Reg = getNextRegister(Reg);
2913 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2917 Parser.Lex(); // Eat the comma.
2918 RegLoc = Parser.getTok().getLoc();
2920 const AsmToken RegTok = Parser.getTok();
2921 Reg = tryParseRegister();
2923 return Error(RegLoc, "register expected");
2924 // Allow Q regs and just interpret them as the two D sub-registers.
2925 bool isQReg = false;
2926 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2927 Reg = getDRegFromQReg(Reg);
2930 // The register must be in the same register class as the first.
2931 if (!RC->contains(Reg))
2932 return Error(RegLoc, "invalid register in register list");
2933 // List must be monotonically increasing.
2934 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
2935 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2936 Warning(RegLoc, "register list not in ascending order");
2938 return Error(RegLoc, "register list not in ascending order");
2940 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
2941 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2942 ") in register list");
2945 // VFP register lists must also be contiguous.
2946 // It's OK to use the enumeration values directly here rather, as the
2947 // VFP register classes have the enum sorted properly.
2948 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2950 return Error(RegLoc, "non-contiguous register range");
2951 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2953 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
2956 SMLoc E = Parser.getTok().getLoc();
2957 if (Parser.getTok().isNot(AsmToken::RCurly))
2958 return Error(E, "'}' expected");
2959 Parser.Lex(); // Eat '}' token.
2961 // Push the register list operand.
2962 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
2964 // The ARM system instruction variants for LDM/STM have a '^' token here.
2965 if (Parser.getTok().is(AsmToken::Caret)) {
2966 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2967 Parser.Lex(); // Eat '^' token.
2973 // Helper function to parse the lane index for vector lists.
2974 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2975 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2976 Index = 0; // Always return a defined index value.
2977 if (Parser.getTok().is(AsmToken::LBrac)) {
2978 Parser.Lex(); // Eat the '['.
2979 if (Parser.getTok().is(AsmToken::RBrac)) {
2980 // "Dn[]" is the 'all lanes' syntax.
2981 LaneKind = AllLanes;
2982 Parser.Lex(); // Eat the ']'.
2983 return MatchOperand_Success;
2986 // There's an optional '#' token here. Normally there wouldn't be, but
2987 // inline assemble puts one in, and it's friendly to accept that.
2988 if (Parser.getTok().is(AsmToken::Hash))
2989 Parser.Lex(); // Eat the '#'
2991 const MCExpr *LaneIndex;
2992 SMLoc Loc = Parser.getTok().getLoc();
2993 if (getParser().ParseExpression(LaneIndex)) {
2994 Error(Loc, "illegal expression");
2995 return MatchOperand_ParseFail;
2997 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
2999 Error(Loc, "lane index must be empty or an integer");
3000 return MatchOperand_ParseFail;
3002 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3003 Error(Parser.getTok().getLoc(), "']' expected");
3004 return MatchOperand_ParseFail;
3006 Parser.Lex(); // Eat the ']'.
3007 int64_t Val = CE->getValue();
3009 // FIXME: Make this range check context sensitive for .8, .16, .32.
3010 if (Val < 0 || Val > 7) {
3011 Error(Parser.getTok().getLoc(), "lane index out of range");
3012 return MatchOperand_ParseFail;
3015 LaneKind = IndexedLane;
3016 return MatchOperand_Success;
3019 return MatchOperand_Success;
3022 // parse a vector register list
3023 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3024 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3025 VectorLaneTy LaneKind;
3027 SMLoc S = Parser.getTok().getLoc();
3028 // As an extension (to match gas), support a plain D register or Q register
3029 // (without encosing curly braces) as a single or double entry list,
3031 if (Parser.getTok().is(AsmToken::Identifier)) {
3032 int Reg = tryParseRegister();
3034 return MatchOperand_NoMatch;
3035 SMLoc E = Parser.getTok().getLoc();
3036 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3037 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
3038 if (Res != MatchOperand_Success)
3042 E = Parser.getTok().getLoc();
3043 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3046 E = Parser.getTok().getLoc();
3047 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3051 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3056 return MatchOperand_Success;
3058 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3059 Reg = getDRegFromQReg(Reg);
3060 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
3061 if (Res != MatchOperand_Success)
3065 E = Parser.getTok().getLoc();
3066 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3067 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3068 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3071 E = Parser.getTok().getLoc();
3072 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3073 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3074 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3078 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3083 return MatchOperand_Success;
3085 Error(S, "vector register expected");
3086 return MatchOperand_ParseFail;
3089 if (Parser.getTok().isNot(AsmToken::LCurly))
3090 return MatchOperand_NoMatch;
3092 Parser.Lex(); // Eat '{' token.
3093 SMLoc RegLoc = Parser.getTok().getLoc();
3095 int Reg = tryParseRegister();
3097 Error(RegLoc, "register expected");
3098 return MatchOperand_ParseFail;
3102 unsigned FirstReg = Reg;
3103 // The list is of D registers, but we also allow Q regs and just interpret
3104 // them as the two D sub-registers.
3105 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3106 FirstReg = Reg = getDRegFromQReg(Reg);
3107 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3108 // it's ambiguous with four-register single spaced.
3112 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
3113 return MatchOperand_ParseFail;
3115 while (Parser.getTok().is(AsmToken::Comma) ||
3116 Parser.getTok().is(AsmToken::Minus)) {
3117 if (Parser.getTok().is(AsmToken::Minus)) {
3119 Spacing = 1; // Register range implies a single spaced list.
3120 else if (Spacing == 2) {
3121 Error(Parser.getTok().getLoc(),
3122 "sequential registers in double spaced list");
3123 return MatchOperand_ParseFail;
3125 Parser.Lex(); // Eat the minus.
3126 SMLoc EndLoc = Parser.getTok().getLoc();
3127 int EndReg = tryParseRegister();
3129 Error(EndLoc, "register expected");
3130 return MatchOperand_ParseFail;
3132 // Allow Q regs and just interpret them as the two D sub-registers.
3133 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3134 EndReg = getDRegFromQReg(EndReg) + 1;
3135 // If the register is the same as the start reg, there's nothing
3139 // The register must be in the same register class as the first.
3140 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3141 Error(EndLoc, "invalid register in register list");
3142 return MatchOperand_ParseFail;
3144 // Ranges must go from low to high.
3146 Error(EndLoc, "bad range in register list");
3147 return MatchOperand_ParseFail;
3149 // Parse the lane specifier if present.
3150 VectorLaneTy NextLaneKind;
3151 unsigned NextLaneIndex;
3152 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3153 return MatchOperand_ParseFail;
3154 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3155 Error(EndLoc, "mismatched lane index in register list");
3156 return MatchOperand_ParseFail;
3158 EndLoc = Parser.getTok().getLoc();
3160 // Add all the registers in the range to the register list.
3161 Count += EndReg - Reg;
3165 Parser.Lex(); // Eat the comma.
3166 RegLoc = Parser.getTok().getLoc();
3168 Reg = tryParseRegister();
3170 Error(RegLoc, "register expected");
3171 return MatchOperand_ParseFail;
3173 // vector register lists must be contiguous.
3174 // It's OK to use the enumeration values directly here rather, as the
3175 // VFP register classes have the enum sorted properly.
3177 // The list is of D registers, but we also allow Q regs and just interpret
3178 // them as the two D sub-registers.
3179 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3181 Spacing = 1; // Register range implies a single spaced list.
3182 else if (Spacing == 2) {
3184 "invalid register in double-spaced list (must be 'D' register')");
3185 return MatchOperand_ParseFail;
3187 Reg = getDRegFromQReg(Reg);
3188 if (Reg != OldReg + 1) {
3189 Error(RegLoc, "non-contiguous register range");
3190 return MatchOperand_ParseFail;
3194 // Parse the lane specifier if present.
3195 VectorLaneTy NextLaneKind;
3196 unsigned NextLaneIndex;
3197 SMLoc EndLoc = Parser.getTok().getLoc();
3198 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3199 return MatchOperand_ParseFail;
3200 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3201 Error(EndLoc, "mismatched lane index in register list");
3202 return MatchOperand_ParseFail;
3206 // Normal D register.
3207 // Figure out the register spacing (single or double) of the list if
3208 // we don't know it already.
3210 Spacing = 1 + (Reg == OldReg + 2);
3212 // Just check that it's contiguous and keep going.
3213 if (Reg != OldReg + Spacing) {
3214 Error(RegLoc, "non-contiguous register range");
3215 return MatchOperand_ParseFail;
3218 // Parse the lane specifier if present.
3219 VectorLaneTy NextLaneKind;
3220 unsigned NextLaneIndex;
3221 SMLoc EndLoc = Parser.getTok().getLoc();
3222 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
3223 return MatchOperand_ParseFail;
3224 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3225 Error(EndLoc, "mismatched lane index in register list");
3226 return MatchOperand_ParseFail;
3230 SMLoc E = Parser.getTok().getLoc();
3231 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3232 Error(E, "'}' expected");
3233 return MatchOperand_ParseFail;
3235 Parser.Lex(); // Eat '}' token.
3239 // Two-register operands have been converted to the
3240 // composite register classes.
3242 const MCRegisterClass *RC = (Spacing == 1) ?
3243 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3244 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3245 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3248 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3249 (Spacing == 2), S, E));
3252 // Two-register operands have been converted to the
3253 // composite register classes.
3255 const MCRegisterClass *RC = (Spacing == 1) ?
3256 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3257 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3258 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3260 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3265 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3271 return MatchOperand_Success;
3274 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3275 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3276 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3277 SMLoc S = Parser.getTok().getLoc();
3278 const AsmToken &Tok = Parser.getTok();
3281 if (Tok.is(AsmToken::Identifier)) {
3282 StringRef OptStr = Tok.getString();
3284 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3285 .Case("sy", ARM_MB::SY)
3286 .Case("st", ARM_MB::ST)
3287 .Case("sh", ARM_MB::ISH)
3288 .Case("ish", ARM_MB::ISH)
3289 .Case("shst", ARM_MB::ISHST)
3290 .Case("ishst", ARM_MB::ISHST)
3291 .Case("nsh", ARM_MB::NSH)
3292 .Case("un", ARM_MB::NSH)
3293 .Case("nshst", ARM_MB::NSHST)
3294 .Case("unst", ARM_MB::NSHST)
3295 .Case("osh", ARM_MB::OSH)
3296 .Case("oshst", ARM_MB::OSHST)
3300 return MatchOperand_NoMatch;
3302 Parser.Lex(); // Eat identifier token.
3303 } else if (Tok.is(AsmToken::Hash) ||
3304 Tok.is(AsmToken::Dollar) ||
3305 Tok.is(AsmToken::Integer)) {
3306 if (Parser.getTok().isNot(AsmToken::Integer))
3307 Parser.Lex(); // Eat the '#'.
3308 SMLoc Loc = Parser.getTok().getLoc();
3310 const MCExpr *MemBarrierID;
3311 if (getParser().ParseExpression(MemBarrierID)) {
3312 Error(Loc, "illegal expression");
3313 return MatchOperand_ParseFail;
3316 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3318 Error(Loc, "constant expression expected");
3319 return MatchOperand_ParseFail;
3322 int Val = CE->getValue();
3324 Error(Loc, "immediate value out of range");
3325 return MatchOperand_ParseFail;
3328 Opt = ARM_MB::RESERVED_0 + Val;
3330 return MatchOperand_ParseFail;
3332 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3333 return MatchOperand_Success;
3336 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3337 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3338 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3339 SMLoc S = Parser.getTok().getLoc();
3340 const AsmToken &Tok = Parser.getTok();
3341 if (!Tok.is(AsmToken::Identifier))
3342 return MatchOperand_NoMatch;
3343 StringRef IFlagsStr = Tok.getString();
3345 // An iflags string of "none" is interpreted to mean that none of the AIF
3346 // bits are set. Not a terribly useful instruction, but a valid encoding.
3347 unsigned IFlags = 0;
3348 if (IFlagsStr != "none") {
3349 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3350 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3351 .Case("a", ARM_PROC::A)
3352 .Case("i", ARM_PROC::I)
3353 .Case("f", ARM_PROC::F)
3356 // If some specific iflag is already set, it means that some letter is
3357 // present more than once, this is not acceptable.
3358 if (Flag == ~0U || (IFlags & Flag))
3359 return MatchOperand_NoMatch;
3365 Parser.Lex(); // Eat identifier token.
3366 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3367 return MatchOperand_Success;
3370 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3371 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3372 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3373 SMLoc S = Parser.getTok().getLoc();
3374 const AsmToken &Tok = Parser.getTok();
3375 if (!Tok.is(AsmToken::Identifier))
3376 return MatchOperand_NoMatch;
3377 StringRef Mask = Tok.getString();
3380 // See ARMv6-M 10.1.1
3381 std::string Name = Mask.lower();
3382 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3383 // Note: in the documentation:
3384 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3385 // for MSR APSR_nzcvq.
3386 // but we do make it an alias here. This is so to get the "mask encoding"
3387 // bits correct on MSR APSR writes.
3389 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3390 // should really only be allowed when writing a special register. Note
3391 // they get dropped in the MRS instruction reading a special register as
3392 // the SYSm field is only 8 bits.
3394 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3395 // includes the DSP extension but that is not checked.
3396 .Case("apsr", 0x800)
3397 .Case("apsr_nzcvq", 0x800)
3398 .Case("apsr_g", 0x400)
3399 .Case("apsr_nzcvqg", 0xc00)
3400 .Case("iapsr", 0x801)
3401 .Case("iapsr_nzcvq", 0x801)
3402 .Case("iapsr_g", 0x401)
3403 .Case("iapsr_nzcvqg", 0xc01)
3404 .Case("eapsr", 0x802)
3405 .Case("eapsr_nzcvq", 0x802)
3406 .Case("eapsr_g", 0x402)
3407 .Case("eapsr_nzcvqg", 0xc02)
3408 .Case("xpsr", 0x803)
3409 .Case("xpsr_nzcvq", 0x803)
3410 .Case("xpsr_g", 0x403)
3411 .Case("xpsr_nzcvqg", 0xc03)
3412 .Case("ipsr", 0x805)
3413 .Case("epsr", 0x806)
3414 .Case("iepsr", 0x807)
3417 .Case("primask", 0x810)
3418 .Case("basepri", 0x811)
3419 .Case("basepri_max", 0x812)
3420 .Case("faultmask", 0x813)
3421 .Case("control", 0x814)
3424 if (FlagsVal == ~0U)
3425 return MatchOperand_NoMatch;
3427 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3428 // basepri, basepri_max and faultmask only valid for V7m.
3429 return MatchOperand_NoMatch;
3431 Parser.Lex(); // Eat identifier token.
3432 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3433 return MatchOperand_Success;
3436 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3437 size_t Start = 0, Next = Mask.find('_');
3438 StringRef Flags = "";
3439 std::string SpecReg = Mask.slice(Start, Next).lower();
3440 if (Next != StringRef::npos)
3441 Flags = Mask.slice(Next+1, Mask.size());
3443 // FlagsVal contains the complete mask:
3445 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3446 unsigned FlagsVal = 0;
3448 if (SpecReg == "apsr") {
3449 FlagsVal = StringSwitch<unsigned>(Flags)
3450 .Case("nzcvq", 0x8) // same as CPSR_f
3451 .Case("g", 0x4) // same as CPSR_s
3452 .Case("nzcvqg", 0xc) // same as CPSR_fs
3455 if (FlagsVal == ~0U) {
3457 return MatchOperand_NoMatch;
3459 FlagsVal = 8; // No flag
3461 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3462 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3463 if (Flags == "all" || Flags == "")
3465 for (int i = 0, e = Flags.size(); i != e; ++i) {
3466 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3473 // If some specific flag is already set, it means that some letter is
3474 // present more than once, this is not acceptable.
3475 if (FlagsVal == ~0U || (FlagsVal & Flag))
3476 return MatchOperand_NoMatch;
3479 } else // No match for special register.
3480 return MatchOperand_NoMatch;
3482 // Special register without flags is NOT equivalent to "fc" flags.
3483 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3484 // two lines would enable gas compatibility at the expense of breaking
3490 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3491 if (SpecReg == "spsr")
3494 Parser.Lex(); // Eat identifier token.
3495 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3496 return MatchOperand_Success;
3499 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3500 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3501 int Low, int High) {
3502 const AsmToken &Tok = Parser.getTok();
3503 if (Tok.isNot(AsmToken::Identifier)) {
3504 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3505 return MatchOperand_ParseFail;
3507 StringRef ShiftName = Tok.getString();
3508 std::string LowerOp = Op.lower();
3509 std::string UpperOp = Op.upper();
3510 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3511 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3512 return MatchOperand_ParseFail;
3514 Parser.Lex(); // Eat shift type token.
3516 // There must be a '#' and a shift amount.
3517 if (Parser.getTok().isNot(AsmToken::Hash) &&
3518 Parser.getTok().isNot(AsmToken::Dollar)) {
3519 Error(Parser.getTok().getLoc(), "'#' expected");
3520 return MatchOperand_ParseFail;
3522 Parser.Lex(); // Eat hash token.
3524 const MCExpr *ShiftAmount;
3525 SMLoc Loc = Parser.getTok().getLoc();
3526 if (getParser().ParseExpression(ShiftAmount)) {
3527 Error(Loc, "illegal expression");
3528 return MatchOperand_ParseFail;
3530 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3532 Error(Loc, "constant expression expected");
3533 return MatchOperand_ParseFail;
3535 int Val = CE->getValue();
3536 if (Val < Low || Val > High) {
3537 Error(Loc, "immediate value out of range");
3538 return MatchOperand_ParseFail;
3541 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3543 return MatchOperand_Success;
3546 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3547 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3548 const AsmToken &Tok = Parser.getTok();
3549 SMLoc S = Tok.getLoc();
3550 if (Tok.isNot(AsmToken::Identifier)) {
3551 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3552 return MatchOperand_ParseFail;
3554 int Val = StringSwitch<int>(Tok.getString())
3558 Parser.Lex(); // Eat the token.
3561 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3562 return MatchOperand_ParseFail;
3564 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3566 S, Parser.getTok().getLoc()));
3567 return MatchOperand_Success;
3570 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3571 /// instructions. Legal values are:
3572 /// lsl #n 'n' in [0,31]
3573 /// asr #n 'n' in [1,32]
3574 /// n == 32 encoded as n == 0.
3575 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3576 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3577 const AsmToken &Tok = Parser.getTok();
3578 SMLoc S = Tok.getLoc();
3579 if (Tok.isNot(AsmToken::Identifier)) {
3580 Error(S, "shift operator 'asr' or 'lsl' expected");
3581 return MatchOperand_ParseFail;
3583 StringRef ShiftName = Tok.getString();
3585 if (ShiftName == "lsl" || ShiftName == "LSL")
3587 else if (ShiftName == "asr" || ShiftName == "ASR")
3590 Error(S, "shift operator 'asr' or 'lsl' expected");
3591 return MatchOperand_ParseFail;
3593 Parser.Lex(); // Eat the operator.
3595 // A '#' and a shift amount.
3596 if (Parser.getTok().isNot(AsmToken::Hash) &&
3597 Parser.getTok().isNot(AsmToken::Dollar)) {
3598 Error(Parser.getTok().getLoc(), "'#' expected");
3599 return MatchOperand_ParseFail;
3601 Parser.Lex(); // Eat hash token.
3603 const MCExpr *ShiftAmount;
3604 SMLoc E = Parser.getTok().getLoc();
3605 if (getParser().ParseExpression(ShiftAmount)) {
3606 Error(E, "malformed shift expression");
3607 return MatchOperand_ParseFail;
3609 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3611 Error(E, "shift amount must be an immediate");
3612 return MatchOperand_ParseFail;
3615 int64_t Val = CE->getValue();
3617 // Shift amount must be in [1,32]
3618 if (Val < 1 || Val > 32) {
3619 Error(E, "'asr' shift amount must be in range [1,32]");
3620 return MatchOperand_ParseFail;
3622 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3623 if (isThumb() && Val == 32) {
3624 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3625 return MatchOperand_ParseFail;
3627 if (Val == 32) Val = 0;
3629 // Shift amount must be in [1,32]
3630 if (Val < 0 || Val > 31) {
3631 Error(E, "'lsr' shift amount must be in range [0,31]");
3632 return MatchOperand_ParseFail;
3636 E = Parser.getTok().getLoc();
3637 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3639 return MatchOperand_Success;
3642 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3643 /// of instructions. Legal values are:
3644 /// ror #n 'n' in {0, 8, 16, 24}
3645 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3646 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3647 const AsmToken &Tok = Parser.getTok();
3648 SMLoc S = Tok.getLoc();
3649 if (Tok.isNot(AsmToken::Identifier))
3650 return MatchOperand_NoMatch;
3651 StringRef ShiftName = Tok.getString();
3652 if (ShiftName != "ror" && ShiftName != "ROR")
3653 return MatchOperand_NoMatch;
3654 Parser.Lex(); // Eat the operator.
3656 // A '#' and a rotate amount.
3657 if (Parser.getTok().isNot(AsmToken::Hash) &&
3658 Parser.getTok().isNot(AsmToken::Dollar)) {
3659 Error(Parser.getTok().getLoc(), "'#' expected");
3660 return MatchOperand_ParseFail;
3662 Parser.Lex(); // Eat hash token.
3664 const MCExpr *ShiftAmount;
3665 SMLoc E = Parser.getTok().getLoc();
3666 if (getParser().ParseExpression(ShiftAmount)) {
3667 Error(E, "malformed rotate expression");
3668 return MatchOperand_ParseFail;
3670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3672 Error(E, "rotate amount must be an immediate");
3673 return MatchOperand_ParseFail;
3676 int64_t Val = CE->getValue();
3677 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3678 // normally, zero is represented in asm by omitting the rotate operand
3680 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3681 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3682 return MatchOperand_ParseFail;
3685 E = Parser.getTok().getLoc();
3686 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3688 return MatchOperand_Success;
3691 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3692 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3693 SMLoc S = Parser.getTok().getLoc();
3694 // The bitfield descriptor is really two operands, the LSB and the width.
3695 if (Parser.getTok().isNot(AsmToken::Hash) &&
3696 Parser.getTok().isNot(AsmToken::Dollar)) {
3697 Error(Parser.getTok().getLoc(), "'#' expected");
3698 return MatchOperand_ParseFail;
3700 Parser.Lex(); // Eat hash token.
3702 const MCExpr *LSBExpr;
3703 SMLoc E = Parser.getTok().getLoc();
3704 if (getParser().ParseExpression(LSBExpr)) {
3705 Error(E, "malformed immediate expression");
3706 return MatchOperand_ParseFail;
3708 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3710 Error(E, "'lsb' operand must be an immediate");
3711 return MatchOperand_ParseFail;
3714 int64_t LSB = CE->getValue();
3715 // The LSB must be in the range [0,31]
3716 if (LSB < 0 || LSB > 31) {
3717 Error(E, "'lsb' operand must be in the range [0,31]");
3718 return MatchOperand_ParseFail;
3720 E = Parser.getTok().getLoc();
3722 // Expect another immediate operand.
3723 if (Parser.getTok().isNot(AsmToken::Comma)) {
3724 Error(Parser.getTok().getLoc(), "too few operands");
3725 return MatchOperand_ParseFail;
3727 Parser.Lex(); // Eat hash token.
3728 if (Parser.getTok().isNot(AsmToken::Hash) &&
3729 Parser.getTok().isNot(AsmToken::Dollar)) {
3730 Error(Parser.getTok().getLoc(), "'#' expected");
3731 return MatchOperand_ParseFail;
3733 Parser.Lex(); // Eat hash token.
3735 const MCExpr *WidthExpr;
3736 if (getParser().ParseExpression(WidthExpr)) {
3737 Error(E, "malformed immediate expression");
3738 return MatchOperand_ParseFail;
3740 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3742 Error(E, "'width' operand must be an immediate");
3743 return MatchOperand_ParseFail;
3746 int64_t Width = CE->getValue();
3747 // The LSB must be in the range [1,32-lsb]
3748 if (Width < 1 || Width > 32 - LSB) {
3749 Error(E, "'width' operand must be in the range [1,32-lsb]");
3750 return MatchOperand_ParseFail;
3752 E = Parser.getTok().getLoc();
3754 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3756 return MatchOperand_Success;
3759 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3760 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3761 // Check for a post-index addressing register operand. Specifically:
3762 // postidx_reg := '+' register {, shift}
3763 // | '-' register {, shift}
3764 // | register {, shift}
3766 // This method must return MatchOperand_NoMatch without consuming any tokens
3767 // in the case where there is no match, as other alternatives take other
3769 AsmToken Tok = Parser.getTok();
3770 SMLoc S = Tok.getLoc();
3771 bool haveEaten = false;
3774 if (Tok.is(AsmToken::Plus)) {
3775 Parser.Lex(); // Eat the '+' token.
3777 } else if (Tok.is(AsmToken::Minus)) {
3778 Parser.Lex(); // Eat the '-' token.
3782 if (Parser.getTok().is(AsmToken::Identifier))
3783 Reg = tryParseRegister();
3786 return MatchOperand_NoMatch;
3787 Error(Parser.getTok().getLoc(), "register expected");
3788 return MatchOperand_ParseFail;
3790 SMLoc E = Parser.getTok().getLoc();
3792 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3793 unsigned ShiftImm = 0;
3794 if (Parser.getTok().is(AsmToken::Comma)) {
3795 Parser.Lex(); // Eat the ','.
3796 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3797 return MatchOperand_ParseFail;
3800 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3803 return MatchOperand_Success;
3806 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3807 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3808 // Check for a post-index addressing register operand. Specifically:
3809 // am3offset := '+' register
3816 // This method must return MatchOperand_NoMatch without consuming any tokens
3817 // in the case where there is no match, as other alternatives take other
3819 AsmToken Tok = Parser.getTok();
3820 SMLoc S = Tok.getLoc();
3822 // Do immediates first, as we always parse those if we have a '#'.
3823 if (Parser.getTok().is(AsmToken::Hash) ||
3824 Parser.getTok().is(AsmToken::Dollar)) {
3825 Parser.Lex(); // Eat the '#'.
3826 // Explicitly look for a '-', as we need to encode negative zero
3828 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3829 const MCExpr *Offset;
3830 if (getParser().ParseExpression(Offset))
3831 return MatchOperand_ParseFail;
3832 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3834 Error(S, "constant expression expected");
3835 return MatchOperand_ParseFail;
3837 SMLoc E = Tok.getLoc();
3838 // Negative zero is encoded as the flag value INT32_MIN.
3839 int32_t Val = CE->getValue();
3840 if (isNegative && Val == 0)
3844 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3846 return MatchOperand_Success;
3850 bool haveEaten = false;
3853 if (Tok.is(AsmToken::Plus)) {
3854 Parser.Lex(); // Eat the '+' token.
3856 } else if (Tok.is(AsmToken::Minus)) {
3857 Parser.Lex(); // Eat the '-' token.
3861 if (Parser.getTok().is(AsmToken::Identifier))
3862 Reg = tryParseRegister();
3865 return MatchOperand_NoMatch;
3866 Error(Parser.getTok().getLoc(), "register expected");
3867 return MatchOperand_ParseFail;
3869 SMLoc E = Parser.getTok().getLoc();
3871 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3874 return MatchOperand_Success;
3877 /// cvtT2LdrdPre - Convert parsed operands to MCInst.
3878 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3879 /// when they refer multiple MIOperands inside a single one.
3881 cvtT2LdrdPre(MCInst &Inst,
3882 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3884 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3885 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3886 // Create a writeback register dummy placeholder.
3887 Inst.addOperand(MCOperand::CreateReg(0));
3889 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3891 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3894 /// cvtT2StrdPre - Convert parsed operands to MCInst.
3895 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3896 /// when they refer multiple MIOperands inside a single one.
3898 cvtT2StrdPre(MCInst &Inst,
3899 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3900 // Create a writeback register dummy placeholder.
3901 Inst.addOperand(MCOperand::CreateReg(0));
3903 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3904 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3906 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3908 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3911 /// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3912 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3913 /// when they refer multiple MIOperands inside a single one.
3915 cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
3916 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3917 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3919 // Create a writeback register dummy placeholder.
3920 Inst.addOperand(MCOperand::CreateImm(0));
3922 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3923 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3926 /// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3927 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3928 /// when they refer multiple MIOperands inside a single one.
3930 cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
3931 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3932 // Create a writeback register dummy placeholder.
3933 Inst.addOperand(MCOperand::CreateImm(0));
3934 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3935 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3936 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3939 /// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3940 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3941 /// when they refer multiple MIOperands inside a single one.
3943 cvtLdWriteBackRegAddrMode2(MCInst &Inst,
3944 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3945 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3947 // Create a writeback register dummy placeholder.
3948 Inst.addOperand(MCOperand::CreateImm(0));
3950 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3951 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3954 /// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3955 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3956 /// when they refer multiple MIOperands inside a single one.
3958 cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
3959 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3960 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3962 // Create a writeback register dummy placeholder.
3963 Inst.addOperand(MCOperand::CreateImm(0));
3965 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3966 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3970 /// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3971 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3972 /// when they refer multiple MIOperands inside a single one.
3974 cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
3975 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3976 // Create a writeback register dummy placeholder.
3977 Inst.addOperand(MCOperand::CreateImm(0));
3978 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3979 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3980 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3983 /// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
3984 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3985 /// when they refer multiple MIOperands inside a single one.
3987 cvtStWriteBackRegAddrMode2(MCInst &Inst,
3988 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3989 // Create a writeback register dummy placeholder.
3990 Inst.addOperand(MCOperand::CreateImm(0));
3991 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3992 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3993 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3996 /// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3997 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
3998 /// when they refer multiple MIOperands inside a single one.
4000 cvtStWriteBackRegAddrMode3(MCInst &Inst,
4001 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4002 // Create a writeback register dummy placeholder.
4003 Inst.addOperand(MCOperand::CreateImm(0));
4004 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4005 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4006 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4009 /// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4010 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4011 /// when they refer multiple MIOperands inside a single one.
4013 cvtLdExtTWriteBackImm(MCInst &Inst,
4014 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4016 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4017 // Create a writeback register dummy placeholder.
4018 Inst.addOperand(MCOperand::CreateImm(0));
4020 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4022 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4024 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4027 /// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
4028 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4029 /// when they refer multiple MIOperands inside a single one.
4031 cvtLdExtTWriteBackReg(MCInst &Inst,
4032 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4034 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4035 // Create a writeback register dummy placeholder.
4036 Inst.addOperand(MCOperand::CreateImm(0));
4038 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4040 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4042 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4045 /// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
4046 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4047 /// when they refer multiple MIOperands inside a single one.
4049 cvtStExtTWriteBackImm(MCInst &Inst,
4050 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4051 // Create a writeback register dummy placeholder.
4052 Inst.addOperand(MCOperand::CreateImm(0));
4054 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4056 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4058 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4060 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4063 /// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4064 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4065 /// when they refer multiple MIOperands inside a single one.
4067 cvtStExtTWriteBackReg(MCInst &Inst,
4068 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4069 // Create a writeback register dummy placeholder.
4070 Inst.addOperand(MCOperand::CreateImm(0));
4072 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4074 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4076 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4078 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4081 /// cvtLdrdPre - Convert parsed operands to MCInst.
4082 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4083 /// when they refer multiple MIOperands inside a single one.
4085 cvtLdrdPre(MCInst &Inst,
4086 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4088 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4089 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4090 // Create a writeback register dummy placeholder.
4091 Inst.addOperand(MCOperand::CreateImm(0));
4093 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4095 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4098 /// cvtStrdPre - Convert parsed operands to MCInst.
4099 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4100 /// when they refer multiple MIOperands inside a single one.
4102 cvtStrdPre(MCInst &Inst,
4103 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4104 // Create a writeback register dummy placeholder.
4105 Inst.addOperand(MCOperand::CreateImm(0));
4107 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4108 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4110 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4112 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4115 /// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4116 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4117 /// when they refer multiple MIOperands inside a single one.
4119 cvtLdWriteBackRegAddrMode3(MCInst &Inst,
4120 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4121 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4122 // Create a writeback register dummy placeholder.
4123 Inst.addOperand(MCOperand::CreateImm(0));
4124 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4125 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4128 /// cvtThumbMultiply - Convert parsed operands to MCInst.
4129 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4130 /// when they refer multiple MIOperands inside a single one.
4132 cvtThumbMultiply(MCInst &Inst,
4133 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4134 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4135 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4136 // If we have a three-operand form, make sure to set Rn to be the operand
4137 // that isn't the same as Rd.
4139 if (Operands.size() == 6 &&
4140 ((ARMOperand*)Operands[4])->getReg() ==
4141 ((ARMOperand*)Operands[3])->getReg())
4143 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4144 Inst.addOperand(Inst.getOperand(0));
4145 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4149 cvtVLDwbFixed(MCInst &Inst,
4150 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4152 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4153 // Create a writeback register dummy placeholder.
4154 Inst.addOperand(MCOperand::CreateImm(0));
4156 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4158 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4162 cvtVLDwbRegister(MCInst &Inst,
4163 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4165 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4166 // Create a writeback register dummy placeholder.
4167 Inst.addOperand(MCOperand::CreateImm(0));
4169 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4171 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4173 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4177 cvtVSTwbFixed(MCInst &Inst,
4178 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4179 // Create a writeback register dummy placeholder.
4180 Inst.addOperand(MCOperand::CreateImm(0));
4182 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4184 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4186 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4190 cvtVSTwbRegister(MCInst &Inst,
4191 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4192 // Create a writeback register dummy placeholder.
4193 Inst.addOperand(MCOperand::CreateImm(0));
4195 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4197 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4199 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4201 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4204 /// Parse an ARM memory expression, return false if successful else return true
4205 /// or an error. The first token must be a '[' when called.
4207 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4209 assert(Parser.getTok().is(AsmToken::LBrac) &&
4210 "Token is not a Left Bracket");
4211 S = Parser.getTok().getLoc();
4212 Parser.Lex(); // Eat left bracket token.
4214 const AsmToken &BaseRegTok = Parser.getTok();
4215 int BaseRegNum = tryParseRegister();
4216 if (BaseRegNum == -1)
4217 return Error(BaseRegTok.getLoc(), "register expected");
4219 // The next token must either be a comma or a closing bracket.
4220 const AsmToken &Tok = Parser.getTok();
4221 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
4222 return Error(Tok.getLoc(), "malformed memory operand");
4224 if (Tok.is(AsmToken::RBrac)) {
4226 Parser.Lex(); // Eat right bracket token.
4228 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4229 0, 0, false, S, E));
4231 // If there's a pre-indexing writeback marker, '!', just add it as a token
4232 // operand. It's rather odd, but syntactically valid.
4233 if (Parser.getTok().is(AsmToken::Exclaim)) {
4234 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4235 Parser.Lex(); // Eat the '!'.
4241 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4242 Parser.Lex(); // Eat the comma.
4244 // If we have a ':', it's an alignment specifier.
4245 if (Parser.getTok().is(AsmToken::Colon)) {
4246 Parser.Lex(); // Eat the ':'.
4247 E = Parser.getTok().getLoc();
4250 if (getParser().ParseExpression(Expr))
4253 // The expression has to be a constant. Memory references with relocations
4254 // don't come through here, as they use the <label> forms of the relevant
4256 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4258 return Error (E, "constant expression expected");
4261 switch (CE->getValue()) {
4264 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4265 case 16: Align = 2; break;
4266 case 32: Align = 4; break;
4267 case 64: Align = 8; break;
4268 case 128: Align = 16; break;
4269 case 256: Align = 32; break;
4272 // Now we should have the closing ']'
4273 E = Parser.getTok().getLoc();
4274 if (Parser.getTok().isNot(AsmToken::RBrac))
4275 return Error(E, "']' expected");
4276 Parser.Lex(); // Eat right bracket token.
4278 // Don't worry about range checking the value here. That's handled by
4279 // the is*() predicates.
4280 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4281 ARM_AM::no_shift, 0, Align,
4284 // If there's a pre-indexing writeback marker, '!', just add it as a token
4286 if (Parser.getTok().is(AsmToken::Exclaim)) {
4287 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4288 Parser.Lex(); // Eat the '!'.
4294 // If we have a '#', it's an immediate offset, else assume it's a register
4295 // offset. Be friendly and also accept a plain integer (without a leading
4296 // hash) for gas compatibility.
4297 if (Parser.getTok().is(AsmToken::Hash) ||
4298 Parser.getTok().is(AsmToken::Dollar) ||
4299 Parser.getTok().is(AsmToken::Integer)) {
4300 if (Parser.getTok().isNot(AsmToken::Integer))
4301 Parser.Lex(); // Eat the '#'.
4302 E = Parser.getTok().getLoc();
4304 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4305 const MCExpr *Offset;
4306 if (getParser().ParseExpression(Offset))
4309 // The expression has to be a constant. Memory references with relocations
4310 // don't come through here, as they use the <label> forms of the relevant
4312 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4314 return Error (E, "constant expression expected");
4316 // If the constant was #-0, represent it as INT32_MIN.
4317 int32_t Val = CE->getValue();
4318 if (isNegative && Val == 0)
4319 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4321 // Now we should have the closing ']'
4322 E = Parser.getTok().getLoc();
4323 if (Parser.getTok().isNot(AsmToken::RBrac))
4324 return Error(E, "']' expected");
4325 Parser.Lex(); // Eat right bracket token.
4327 // Don't worry about range checking the value here. That's handled by
4328 // the is*() predicates.
4329 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4330 ARM_AM::no_shift, 0, 0,
4333 // If there's a pre-indexing writeback marker, '!', just add it as a token
4335 if (Parser.getTok().is(AsmToken::Exclaim)) {
4336 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4337 Parser.Lex(); // Eat the '!'.
4343 // The register offset is optionally preceded by a '+' or '-'
4344 bool isNegative = false;
4345 if (Parser.getTok().is(AsmToken::Minus)) {
4347 Parser.Lex(); // Eat the '-'.
4348 } else if (Parser.getTok().is(AsmToken::Plus)) {
4350 Parser.Lex(); // Eat the '+'.
4353 E = Parser.getTok().getLoc();
4354 int OffsetRegNum = tryParseRegister();
4355 if (OffsetRegNum == -1)
4356 return Error(E, "register expected");
4358 // If there's a shift operator, handle it.
4359 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4360 unsigned ShiftImm = 0;
4361 if (Parser.getTok().is(AsmToken::Comma)) {
4362 Parser.Lex(); // Eat the ','.
4363 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4367 // Now we should have the closing ']'
4368 E = Parser.getTok().getLoc();
4369 if (Parser.getTok().isNot(AsmToken::RBrac))
4370 return Error(E, "']' expected");
4371 Parser.Lex(); // Eat right bracket token.
4373 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4374 ShiftType, ShiftImm, 0, isNegative,
4377 // If there's a pre-indexing writeback marker, '!', just add it as a token
4379 if (Parser.getTok().is(AsmToken::Exclaim)) {
4380 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4381 Parser.Lex(); // Eat the '!'.
4387 /// parseMemRegOffsetShift - one of these two:
4388 /// ( lsl | lsr | asr | ror ) , # shift_amount
4390 /// return true if it parses a shift otherwise it returns false.
4391 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4393 SMLoc Loc = Parser.getTok().getLoc();
4394 const AsmToken &Tok = Parser.getTok();
4395 if (Tok.isNot(AsmToken::Identifier))
4397 StringRef ShiftName = Tok.getString();
4398 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4399 ShiftName == "asl" || ShiftName == "ASL")
4401 else if (ShiftName == "lsr" || ShiftName == "LSR")
4403 else if (ShiftName == "asr" || ShiftName == "ASR")
4405 else if (ShiftName == "ror" || ShiftName == "ROR")
4407 else if (ShiftName == "rrx" || ShiftName == "RRX")
4410 return Error(Loc, "illegal shift operator");
4411 Parser.Lex(); // Eat shift type token.
4413 // rrx stands alone.
4415 if (St != ARM_AM::rrx) {
4416 Loc = Parser.getTok().getLoc();
4417 // A '#' and a shift amount.
4418 const AsmToken &HashTok = Parser.getTok();
4419 if (HashTok.isNot(AsmToken::Hash) &&
4420 HashTok.isNot(AsmToken::Dollar))
4421 return Error(HashTok.getLoc(), "'#' expected");
4422 Parser.Lex(); // Eat hash token.
4425 if (getParser().ParseExpression(Expr))
4427 // Range check the immediate.
4428 // lsl, ror: 0 <= imm <= 31
4429 // lsr, asr: 0 <= imm <= 32
4430 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4432 return Error(Loc, "shift amount must be an immediate");
4433 int64_t Imm = CE->getValue();
4435 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4436 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4437 return Error(Loc, "immediate shift value out of range");
4438 // If <ShiftTy> #0, turn it into a no_shift.
4441 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4450 /// parseFPImm - A floating point immediate expression operand.
4451 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4452 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4453 // Anything that can accept a floating point constant as an operand
4454 // needs to go through here, as the regular ParseExpression is
4457 // This routine still creates a generic Immediate operand, containing
4458 // a bitcast of the 64-bit floating point value. The various operands
4459 // that accept floats can check whether the value is valid for them
4460 // via the standard is*() predicates.
4462 SMLoc S = Parser.getTok().getLoc();
4464 if (Parser.getTok().isNot(AsmToken::Hash) &&
4465 Parser.getTok().isNot(AsmToken::Dollar))
4466 return MatchOperand_NoMatch;
4468 // Disambiguate the VMOV forms that can accept an FP immediate.
4469 // vmov.f32 <sreg>, #imm
4470 // vmov.f64 <dreg>, #imm
4471 // vmov.f32 <dreg>, #imm @ vector f32x2
4472 // vmov.f32 <qreg>, #imm @ vector f32x4
4474 // There are also the NEON VMOV instructions which expect an
4475 // integer constant. Make sure we don't try to parse an FPImm
4477 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4478 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4479 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4480 TyOp->getToken() != ".f64"))
4481 return MatchOperand_NoMatch;
4483 Parser.Lex(); // Eat the '#'.
4485 // Handle negation, as that still comes through as a separate token.
4486 bool isNegative = false;
4487 if (Parser.getTok().is(AsmToken::Minus)) {
4491 const AsmToken &Tok = Parser.getTok();
4492 SMLoc Loc = Tok.getLoc();
4493 if (Tok.is(AsmToken::Real)) {
4494 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4495 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4496 // If we had a '-' in front, toggle the sign bit.
4497 IntVal ^= (uint64_t)isNegative << 31;
4498 Parser.Lex(); // Eat the token.
4499 Operands.push_back(ARMOperand::CreateImm(
4500 MCConstantExpr::Create(IntVal, getContext()),
4501 S, Parser.getTok().getLoc()));
4502 return MatchOperand_Success;
4504 // Also handle plain integers. Instructions which allow floating point
4505 // immediates also allow a raw encoded 8-bit value.
4506 if (Tok.is(AsmToken::Integer)) {
4507 int64_t Val = Tok.getIntVal();
4508 Parser.Lex(); // Eat the token.
4509 if (Val > 255 || Val < 0) {
4510 Error(Loc, "encoded floating point value out of range");
4511 return MatchOperand_ParseFail;
4513 double RealVal = ARM_AM::getFPImmFloat(Val);
4514 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4515 Operands.push_back(ARMOperand::CreateImm(
4516 MCConstantExpr::Create(Val, getContext()), S,
4517 Parser.getTok().getLoc()));
4518 return MatchOperand_Success;
4521 Error(Loc, "invalid floating point immediate");
4522 return MatchOperand_ParseFail;
4525 /// Parse a arm instruction operand. For now this parses the operand regardless
4526 /// of the mnemonic.
4527 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4528 StringRef Mnemonic) {
4531 // Check if the current operand has a custom associated parser, if so, try to
4532 // custom parse the operand, or fallback to the general approach.
4533 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4534 if (ResTy == MatchOperand_Success)
4536 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4537 // there was a match, but an error occurred, in which case, just return that
4538 // the operand parsing failed.
4539 if (ResTy == MatchOperand_ParseFail)
4542 switch (getLexer().getKind()) {
4544 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4546 case AsmToken::Identifier: {
4547 if (!tryParseRegisterWithWriteBack(Operands))
4549 int Res = tryParseShiftRegister(Operands);
4550 if (Res == 0) // success
4552 else if (Res == -1) // irrecoverable error
4554 // If this is VMRS, check for the apsr_nzcv operand.
4555 if (Mnemonic == "vmrs" &&
4556 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4557 S = Parser.getTok().getLoc();
4559 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4563 // Fall though for the Identifier case that is not a register or a
4566 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4567 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4568 case AsmToken::String: // quoted label names.
4569 case AsmToken::Dot: { // . as a branch target
4570 // This was not a register so parse other operands that start with an
4571 // identifier (like labels) as expressions and create them as immediates.
4572 const MCExpr *IdVal;
4573 S = Parser.getTok().getLoc();
4574 if (getParser().ParseExpression(IdVal))
4576 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4577 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4580 case AsmToken::LBrac:
4581 return parseMemory(Operands);
4582 case AsmToken::LCurly:
4583 return parseRegisterList(Operands);
4584 case AsmToken::Dollar:
4585 case AsmToken::Hash: {
4586 // #42 -> immediate.
4587 S = Parser.getTok().getLoc();
4590 if (Parser.getTok().isNot(AsmToken::Colon)) {
4591 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4592 const MCExpr *ImmVal;
4593 if (getParser().ParseExpression(ImmVal))
4595 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4597 int32_t Val = CE->getValue();
4598 if (isNegative && Val == 0)
4599 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4601 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4602 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4605 // w/ a ':' after the '#', it's just like a plain ':'.
4608 case AsmToken::Colon: {
4609 // ":lower16:" and ":upper16:" expression prefixes
4610 // FIXME: Check it's an expression prefix,
4611 // e.g. (FOO - :lower16:BAR) isn't legal.
4612 ARMMCExpr::VariantKind RefKind;
4613 if (parsePrefix(RefKind))
4616 const MCExpr *SubExprVal;
4617 if (getParser().ParseExpression(SubExprVal))
4620 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4622 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4623 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4629 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4630 // :lower16: and :upper16:.
4631 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4632 RefKind = ARMMCExpr::VK_ARM_None;
4634 // :lower16: and :upper16: modifiers
4635 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4636 Parser.Lex(); // Eat ':'
4638 if (getLexer().isNot(AsmToken::Identifier)) {
4639 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4643 StringRef IDVal = Parser.getTok().getIdentifier();
4644 if (IDVal == "lower16") {
4645 RefKind = ARMMCExpr::VK_ARM_LO16;
4646 } else if (IDVal == "upper16") {
4647 RefKind = ARMMCExpr::VK_ARM_HI16;
4649 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4654 if (getLexer().isNot(AsmToken::Colon)) {
4655 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4658 Parser.Lex(); // Eat the last ':'
4662 /// \brief Given a mnemonic, split out possible predication code and carry
4663 /// setting letters to form a canonical mnemonic and flags.
4665 // FIXME: Would be nice to autogen this.
4666 // FIXME: This is a bit of a maze of special cases.
4667 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4668 unsigned &PredicationCode,
4670 unsigned &ProcessorIMod,
4671 StringRef &ITMask) {
4672 PredicationCode = ARMCC::AL;
4673 CarrySetting = false;
4676 // Ignore some mnemonics we know aren't predicated forms.
4678 // FIXME: Would be nice to autogen this.
4679 if ((Mnemonic == "movs" && isThumb()) ||
4680 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4681 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4682 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4683 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4684 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4685 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4686 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4687 Mnemonic == "fmuls")
4690 // First, split out any predication code. Ignore mnemonics we know aren't
4691 // predicated but do have a carry-set and so weren't caught above.
4692 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4693 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4694 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4695 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4696 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4697 .Case("eq", ARMCC::EQ)
4698 .Case("ne", ARMCC::NE)
4699 .Case("hs", ARMCC::HS)
4700 .Case("cs", ARMCC::HS)
4701 .Case("lo", ARMCC::LO)
4702 .Case("cc", ARMCC::LO)
4703 .Case("mi", ARMCC::MI)
4704 .Case("pl", ARMCC::PL)
4705 .Case("vs", ARMCC::VS)
4706 .Case("vc", ARMCC::VC)
4707 .Case("hi", ARMCC::HI)
4708 .Case("ls", ARMCC::LS)
4709 .Case("ge", ARMCC::GE)
4710 .Case("lt", ARMCC::LT)
4711 .Case("gt", ARMCC::GT)
4712 .Case("le", ARMCC::LE)
4713 .Case("al", ARMCC::AL)
4716 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4717 PredicationCode = CC;
4721 // Next, determine if we have a carry setting bit. We explicitly ignore all
4722 // the instructions we know end in 's'.
4723 if (Mnemonic.endswith("s") &&
4724 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4725 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4726 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4727 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4728 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4729 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4730 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4731 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4732 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4733 (Mnemonic == "movs" && isThumb()))) {
4734 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4735 CarrySetting = true;
4738 // The "cps" instruction can have a interrupt mode operand which is glued into
4739 // the mnemonic. Check if this is the case, split it and parse the imod op
4740 if (Mnemonic.startswith("cps")) {
4741 // Split out any imod code.
4743 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4744 .Case("ie", ARM_PROC::IE)
4745 .Case("id", ARM_PROC::ID)
4748 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4749 ProcessorIMod = IMod;
4753 // The "it" instruction has the condition mask on the end of the mnemonic.
4754 if (Mnemonic.startswith("it")) {
4755 ITMask = Mnemonic.slice(2, Mnemonic.size());
4756 Mnemonic = Mnemonic.slice(0, 2);
4762 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4763 /// inclusion of carry set or predication code operands.
4765 // FIXME: It would be nice to autogen this.
4767 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
4768 bool &CanAcceptPredicationCode) {
4769 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4770 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4771 Mnemonic == "add" || Mnemonic == "adc" ||
4772 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4773 Mnemonic == "orr" || Mnemonic == "mvn" ||
4774 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4775 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4776 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4777 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4778 Mnemonic == "mla" || Mnemonic == "smlal" ||
4779 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4780 CanAcceptCarrySet = true;
4782 CanAcceptCarrySet = false;
4784 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4785 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4786 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4787 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
4788 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4789 (Mnemonic == "clrex" && !isThumb()) ||
4790 (Mnemonic == "nop" && isThumbOne()) ||
4791 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4792 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4793 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
4794 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4796 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
4797 CanAcceptPredicationCode = false;
4799 CanAcceptPredicationCode = true;
4802 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
4803 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
4804 CanAcceptPredicationCode = false;
4808 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4809 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4810 // FIXME: This is all horribly hacky. We really need a better way to deal
4811 // with optional operands like this in the matcher table.
4813 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4814 // another does not. Specifically, the MOVW instruction does not. So we
4815 // special case it here and remove the defaulted (non-setting) cc_out
4816 // operand if that's the instruction we're trying to match.
4818 // We do this as post-processing of the explicit operands rather than just
4819 // conditionally adding the cc_out in the first place because we need
4820 // to check the type of the parsed immediate operand.
4821 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4822 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4823 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4824 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4827 // Register-register 'add' for thumb does not have a cc_out operand
4828 // when there are only two register operands.
4829 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4830 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4831 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4832 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4834 // Register-register 'add' for thumb does not have a cc_out operand
4835 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4836 // have to check the immediate range here since Thumb2 has a variant
4837 // that can handle a different range and has a cc_out operand.
4838 if (((isThumb() && Mnemonic == "add") ||
4839 (isThumbTwo() && Mnemonic == "sub")) &&
4840 Operands.size() == 6 &&
4841 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4842 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4843 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4844 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4845 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4846 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4848 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4849 // imm0_4095 variant. That's the least-preferred variant when
4850 // selecting via the generic "add" mnemonic, so to know that we
4851 // should remove the cc_out operand, we have to explicitly check that
4852 // it's not one of the other variants. Ugh.
4853 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4854 Operands.size() == 6 &&
4855 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4856 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4857 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4858 // Nest conditions rather than one big 'if' statement for readability.
4860 // If either register is a high reg, it's either one of the SP
4861 // variants (handled above) or a 32-bit encoding, so we just
4862 // check against T3. If the second register is the PC, this is an
4863 // alternate form of ADR, which uses encoding T4, so check for that too.
4864 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4865 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
4866 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4867 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4869 // If both registers are low, we're in an IT block, and the immediate is
4870 // in range, we should use encoding T1 instead, which has a cc_out.
4872 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4873 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4874 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4877 // Otherwise, we use encoding T4, which does not have a cc_out
4882 // The thumb2 multiply instruction doesn't have a CCOut register, so
4883 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4884 // use the 16-bit encoding or not.
4885 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4886 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4887 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4888 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4889 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4890 // If the registers aren't low regs, the destination reg isn't the
4891 // same as one of the source regs, or the cc_out operand is zero
4892 // outside of an IT block, we have to use the 32-bit encoding, so
4893 // remove the cc_out operand.
4894 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4895 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4896 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
4898 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4899 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4900 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4901 static_cast<ARMOperand*>(Operands[4])->getReg())))
4904 // Also check the 'mul' syntax variant that doesn't specify an explicit
4905 // destination register.
4906 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4907 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4908 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4909 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4910 // If the registers aren't low regs or the cc_out operand is zero
4911 // outside of an IT block, we have to use the 32-bit encoding, so
4912 // remove the cc_out operand.
4913 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4914 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4920 // Register-register 'add/sub' for thumb does not have a cc_out operand
4921 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4922 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4923 // right, this will result in better diagnostics (which operand is off)
4925 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4926 (Operands.size() == 5 || Operands.size() == 6) &&
4927 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4928 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4929 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4930 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4931 (Operands.size() == 6 &&
4932 static_cast<ARMOperand*>(Operands[5])->isImm())))
4938 static bool isDataTypeToken(StringRef Tok) {
4939 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4940 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4941 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4942 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4943 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4944 Tok == ".f" || Tok == ".d";
4947 // FIXME: This bit should probably be handled via an explicit match class
4948 // in the .td files that matches the suffix instead of having it be
4949 // a literal string token the way it is now.
4950 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4951 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4954 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
4955 /// Parse an arm instruction mnemonic followed by its operands.
4956 bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4957 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4958 // Apply mnemonic aliases before doing anything else, as the destination
4959 // mnemnonic may include suffices and we want to handle them normally.
4960 // The generic tblgen'erated code does this later, at the start of
4961 // MatchInstructionImpl(), but that's too late for aliases that include
4962 // any sort of suffix.
4963 unsigned AvailableFeatures = getAvailableFeatures();
4964 applyMnemonicAliases(Name, AvailableFeatures);
4966 // First check for the ARM-specific .req directive.
4967 if (Parser.getTok().is(AsmToken::Identifier) &&
4968 Parser.getTok().getIdentifier() == ".req") {
4969 parseDirectiveReq(Name, NameLoc);
4970 // We always return 'error' for this, as we're done with this
4971 // statement and don't need to match the 'instruction."
4975 // Create the leading tokens for the mnemonic, split by '.' characters.
4976 size_t Start = 0, Next = Name.find('.');
4977 StringRef Mnemonic = Name.slice(Start, Next);
4979 // Split out the predication code and carry setting flag from the mnemonic.
4980 unsigned PredicationCode;
4981 unsigned ProcessorIMod;
4984 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
4985 ProcessorIMod, ITMask);
4987 // In Thumb1, only the branch (B) instruction can be predicated.
4988 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4989 Parser.EatToEndOfStatement();
4990 return Error(NameLoc, "conditional execution not supported in Thumb1");
4993 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4995 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4996 // is the mask as it will be for the IT encoding if the conditional
4997 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4998 // where the conditional bit0 is zero, the instruction post-processing
4999 // will adjust the mask accordingly.
5000 if (Mnemonic == "it") {
5001 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5002 if (ITMask.size() > 3) {
5003 Parser.EatToEndOfStatement();
5004 return Error(Loc, "too many conditions on IT instruction");
5007 for (unsigned i = ITMask.size(); i != 0; --i) {
5008 char pos = ITMask[i - 1];
5009 if (pos != 't' && pos != 'e') {
5010 Parser.EatToEndOfStatement();
5011 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5014 if (ITMask[i - 1] == 't')
5017 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5020 // FIXME: This is all a pretty gross hack. We should automatically handle
5021 // optional operands like this via tblgen.
5023 // Next, add the CCOut and ConditionCode operands, if needed.
5025 // For mnemonics which can ever incorporate a carry setting bit or predication
5026 // code, our matching model involves us always generating CCOut and
5027 // ConditionCode operands to match the mnemonic "as written" and then we let
5028 // the matcher deal with finding the right instruction or generating an
5029 // appropriate error.
5030 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5031 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
5033 // If we had a carry-set on an instruction that can't do that, issue an
5035 if (!CanAcceptCarrySet && CarrySetting) {
5036 Parser.EatToEndOfStatement();
5037 return Error(NameLoc, "instruction '" + Mnemonic +
5038 "' can not set flags, but 's' suffix specified");
5040 // If we had a predication code on an instruction that can't do that, issue an
5042 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5043 Parser.EatToEndOfStatement();
5044 return Error(NameLoc, "instruction '" + Mnemonic +
5045 "' is not predicable, but condition code specified");
5048 // Add the carry setting operand, if necessary.
5049 if (CanAcceptCarrySet) {
5050 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5051 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5055 // Add the predication code operand, if necessary.
5056 if (CanAcceptPredicationCode) {
5057 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5059 Operands.push_back(ARMOperand::CreateCondCode(
5060 ARMCC::CondCodes(PredicationCode), Loc));
5063 // Add the processor imod operand, if necessary.
5064 if (ProcessorIMod) {
5065 Operands.push_back(ARMOperand::CreateImm(
5066 MCConstantExpr::Create(ProcessorIMod, getContext()),
5070 // Add the remaining tokens in the mnemonic.
5071 while (Next != StringRef::npos) {
5073 Next = Name.find('.', Start + 1);
5074 StringRef ExtraToken = Name.slice(Start, Next);
5076 // Some NEON instructions have an optional datatype suffix that is
5077 // completely ignored. Check for that.
5078 if (isDataTypeToken(ExtraToken) &&
5079 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5082 if (ExtraToken != ".n") {
5083 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5084 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5088 // Read the remaining operands.
5089 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5090 // Read the first operand.
5091 if (parseOperand(Operands, Mnemonic)) {
5092 Parser.EatToEndOfStatement();
5096 while (getLexer().is(AsmToken::Comma)) {
5097 Parser.Lex(); // Eat the comma.
5099 // Parse and remember the operand.
5100 if (parseOperand(Operands, Mnemonic)) {
5101 Parser.EatToEndOfStatement();
5107 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5108 SMLoc Loc = getLexer().getLoc();
5109 Parser.EatToEndOfStatement();
5110 return Error(Loc, "unexpected token in argument list");
5113 Parser.Lex(); // Consume the EndOfStatement
5115 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5116 // do and don't have a cc_out optional-def operand. With some spot-checks
5117 // of the operand list, we can figure out which variant we're trying to
5118 // parse and adjust accordingly before actually matching. We shouldn't ever
5119 // try to remove a cc_out operand that was explicitly set on the the
5120 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5121 // table driven matcher doesn't fit well with the ARM instruction set.
5122 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5123 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5124 Operands.erase(Operands.begin() + 1);
5128 // ARM mode 'blx' need special handling, as the register operand version
5129 // is predicable, but the label operand version is not. So, we can't rely
5130 // on the Mnemonic based checking to correctly figure out when to put
5131 // a k_CondCode operand in the list. If we're trying to match the label
5132 // version, remove the k_CondCode operand here.
5133 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5134 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5135 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5136 Operands.erase(Operands.begin() + 1);
5140 // The vector-compare-to-zero instructions have a literal token "#0" at
5141 // the end that comes to here as an immediate operand. Convert it to a
5142 // token to play nicely with the matcher.
5143 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5144 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5145 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5146 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5147 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5148 if (CE && CE->getValue() == 0) {
5149 Operands.erase(Operands.begin() + 5);
5150 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5154 // VCMP{E} does the same thing, but with a different operand count.
5155 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5156 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5157 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5158 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5159 if (CE && CE->getValue() == 0) {
5160 Operands.erase(Operands.begin() + 4);
5161 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5165 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
5166 // end. Convert it to a token here. Take care not to convert those
5167 // that should hit the Thumb2 encoding.
5168 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
5169 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5170 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5171 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5172 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5173 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5174 if (CE && CE->getValue() == 0 &&
5176 // The cc_out operand matches the IT block.
5177 ((inITBlock() != CarrySetting) &&
5178 // Neither register operand is a high register.
5179 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5180 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
5181 Operands.erase(Operands.begin() + 5);
5182 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5190 // Validate context-sensitive operand constraints.
5192 // return 'true' if register list contains non-low GPR registers,
5193 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5194 // 'containsReg' to true.
5195 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5196 unsigned HiReg, bool &containsReg) {
5197 containsReg = false;
5198 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5199 unsigned OpReg = Inst.getOperand(i).getReg();
5202 // Anything other than a low register isn't legal here.
5203 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5209 // Check if the specified regisgter is in the register list of the inst,
5210 // starting at the indicated operand number.
5211 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5212 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5213 unsigned OpReg = Inst.getOperand(i).getReg();
5220 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5221 // the ARMInsts array) instead. Getting that here requires awkward
5222 // API changes, though. Better way?
5224 extern const MCInstrDesc ARMInsts[];
5226 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
5227 return ARMInsts[Opcode];
5230 // FIXME: We would really like to be able to tablegen'erate this.
5232 validateInstruction(MCInst &Inst,
5233 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5234 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
5235 SMLoc Loc = Operands[0]->getStartLoc();
5236 // Check the IT block state first.
5237 // NOTE: BKPT instruction has the interesting property of being
5238 // allowed in IT blocks, but not being predicable. It just always
5240 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5241 Inst.getOpcode() != ARM::BKPT) {
5243 if (ITState.FirstCond)
5244 ITState.FirstCond = false;
5246 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5247 // The instruction must be predicable.
5248 if (!MCID.isPredicable())
5249 return Error(Loc, "instructions in IT block must be predicable");
5250 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5251 unsigned ITCond = bit ? ITState.Cond :
5252 ARMCC::getOppositeCondition(ITState.Cond);
5253 if (Cond != ITCond) {
5254 // Find the condition code Operand to get its SMLoc information.
5256 for (unsigned i = 1; i < Operands.size(); ++i)
5257 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5258 CondLoc = Operands[i]->getStartLoc();
5259 return Error(CondLoc, "incorrect condition in IT block; got '" +
5260 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5261 "', but expected '" +
5262 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5264 // Check for non-'al' condition codes outside of the IT block.
5265 } else if (isThumbTwo() && MCID.isPredicable() &&
5266 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5267 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5268 Inst.getOpcode() != ARM::t2B)
5269 return Error(Loc, "predicated instructions must be in IT block");
5271 switch (Inst.getOpcode()) {
5274 case ARM::LDRD_POST:
5276 // Rt2 must be Rt + 1.
5277 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5278 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5280 return Error(Operands[3]->getStartLoc(),
5281 "destination operands must be sequential");
5285 // Rt2 must be Rt + 1.
5286 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5287 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5289 return Error(Operands[3]->getStartLoc(),
5290 "source operands must be sequential");
5294 case ARM::STRD_POST:
5296 // Rt2 must be Rt + 1.
5297 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5298 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5300 return Error(Operands[3]->getStartLoc(),
5301 "source operands must be sequential");
5306 // width must be in range [1, 32-lsb]
5307 unsigned lsb = Inst.getOperand(2).getImm();
5308 unsigned widthm1 = Inst.getOperand(3).getImm();
5309 if (widthm1 >= 32 - lsb)
5310 return Error(Operands[5]->getStartLoc(),
5311 "bitfield width must be in range [1,32-lsb]");
5315 // If we're parsing Thumb2, the .w variant is available and handles
5316 // most cases that are normally illegal for a Thumb1 LDM
5317 // instruction. We'll make the transformation in processInstruction()
5320 // Thumb LDM instructions are writeback iff the base register is not
5321 // in the register list.
5322 unsigned Rn = Inst.getOperand(0).getReg();
5323 bool hasWritebackToken =
5324 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5325 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5326 bool listContainsBase;
5327 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5328 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5329 "registers must be in range r0-r7");
5330 // If we should have writeback, then there should be a '!' token.
5331 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5332 return Error(Operands[2]->getStartLoc(),
5333 "writeback operator '!' expected");
5334 // If we should not have writeback, there must not be a '!'. This is
5335 // true even for the 32-bit wide encodings.
5336 if (listContainsBase && hasWritebackToken)
5337 return Error(Operands[3]->getStartLoc(),
5338 "writeback operator '!' not allowed when base register "
5339 "in register list");
5343 case ARM::t2LDMIA_UPD: {
5344 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5345 return Error(Operands[4]->getStartLoc(),
5346 "writeback operator '!' not allowed when base register "
5347 "in register list");
5351 // The second source operand must be the same register as the destination
5354 // In this case, we must directly check the parsed operands because the
5355 // cvtThumbMultiply() function is written in such a way that it guarantees
5356 // this first statement is always true for the new Inst. Essentially, the
5357 // destination is unconditionally copied into the second source operand
5358 // without checking to see if it matches what we actually parsed.
5359 if (Operands.size() == 6 &&
5360 (((ARMOperand*)Operands[3])->getReg() !=
5361 ((ARMOperand*)Operands[5])->getReg()) &&
5362 (((ARMOperand*)Operands[3])->getReg() !=
5363 ((ARMOperand*)Operands[4])->getReg())) {
5364 return Error(Operands[3]->getStartLoc(),
5365 "destination register must match source register");
5369 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5370 // so only issue a diagnostic for thumb1. The instructions will be
5371 // switched to the t2 encodings in processInstruction() if necessary.
5373 bool listContainsBase;
5374 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5376 return Error(Operands[2]->getStartLoc(),
5377 "registers must be in range r0-r7 or pc");
5381 bool listContainsBase;
5382 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5384 return Error(Operands[2]->getStartLoc(),
5385 "registers must be in range r0-r7 or lr");
5388 case ARM::tSTMIA_UPD: {
5389 bool listContainsBase;
5390 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5391 return Error(Operands[4]->getStartLoc(),
5392 "registers must be in range r0-r7");
5395 case ARM::tADDrSP: {
5396 // If the non-SP source operand and the destination operand are not the
5397 // same, we need thumb2 (for the wide encoding), or we have an error.
5398 if (!isThumbTwo() &&
5399 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5400 return Error(Operands[4]->getStartLoc(),
5401 "source register must be the same as destination");
5410 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5412 default: llvm_unreachable("unexpected opcode!");
5414 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5415 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5416 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5417 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5418 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5419 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5420 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5421 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5422 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5425 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5426 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5427 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5428 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5429 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5431 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5432 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5433 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5434 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5435 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5437 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5438 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5439 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5440 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5441 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5444 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5445 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5446 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5447 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5448 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5449 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5450 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5451 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5452 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5453 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5454 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5455 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5456 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5457 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5458 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5461 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5462 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5463 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5464 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5465 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5466 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5467 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5468 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5469 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5470 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5471 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5472 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5473 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5474 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5475 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5476 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5477 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5478 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5481 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5482 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5483 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5484 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5485 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5486 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5487 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5488 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5489 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5490 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5491 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5492 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5493 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5494 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5495 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5498 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5499 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5500 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5501 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5502 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5503 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5504 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5505 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5506 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5507 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5508 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5509 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5510 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5511 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5512 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5513 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5514 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5515 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5519 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5521 default: llvm_unreachable("unexpected opcode!");
5523 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5524 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5525 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5526 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5527 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5528 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5529 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5530 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5531 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5534 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5535 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5536 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5537 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5538 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5539 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5540 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5541 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5542 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5543 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5544 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5545 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5546 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5547 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5548 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5551 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5552 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5553 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5554 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5555 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5556 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5557 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5558 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5559 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5560 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5561 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5562 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5563 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5564 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5565 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5566 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5567 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5568 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5571 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5572 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5573 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5574 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5575 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5576 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5577 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5578 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5579 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5580 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5581 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5582 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5583 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5584 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5585 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5588 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5589 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5590 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5591 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5592 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5593 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5594 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5595 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5596 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5597 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5598 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5599 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5600 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5601 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5602 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5603 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5604 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5605 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5608 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5609 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5610 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5611 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5612 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5613 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5614 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5615 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5616 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5617 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5618 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5619 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5620 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5621 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5622 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5625 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5626 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5627 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5628 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5629 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5630 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5631 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5632 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5633 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5634 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5635 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5636 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5637 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5638 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5639 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5640 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5641 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5642 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5645 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5646 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5647 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5648 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5649 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5650 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5651 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5652 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5653 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5654 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5655 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5656 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5657 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5658 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5659 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5660 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5661 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5662 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5667 processInstruction(MCInst &Inst,
5668 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5669 switch (Inst.getOpcode()) {
5670 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5672 if (Inst.getOperand(1).getReg() != ARM::PC ||
5673 Inst.getOperand(5).getReg() != 0)
5676 TmpInst.setOpcode(ARM::ADR);
5677 TmpInst.addOperand(Inst.getOperand(0));
5678 TmpInst.addOperand(Inst.getOperand(2));
5679 TmpInst.addOperand(Inst.getOperand(3));
5680 TmpInst.addOperand(Inst.getOperand(4));
5684 // Aliases for alternate PC+imm syntax of LDR instructions.
5685 case ARM::t2LDRpcrel:
5686 Inst.setOpcode(ARM::t2LDRpci);
5688 case ARM::t2LDRBpcrel:
5689 Inst.setOpcode(ARM::t2LDRBpci);
5691 case ARM::t2LDRHpcrel:
5692 Inst.setOpcode(ARM::t2LDRHpci);
5694 case ARM::t2LDRSBpcrel:
5695 Inst.setOpcode(ARM::t2LDRSBpci);
5697 case ARM::t2LDRSHpcrel:
5698 Inst.setOpcode(ARM::t2LDRSHpci);
5700 // Handle NEON VST complex aliases.
5701 case ARM::VST1LNdWB_register_Asm_8:
5702 case ARM::VST1LNdWB_register_Asm_16:
5703 case ARM::VST1LNdWB_register_Asm_32: {
5705 // Shuffle the operands around so the lane index operand is in the
5708 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5709 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5710 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5711 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5712 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5713 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5714 TmpInst.addOperand(Inst.getOperand(1)); // lane
5715 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5716 TmpInst.addOperand(Inst.getOperand(6));
5721 case ARM::VST2LNdWB_register_Asm_8:
5722 case ARM::VST2LNdWB_register_Asm_16:
5723 case ARM::VST2LNdWB_register_Asm_32:
5724 case ARM::VST2LNqWB_register_Asm_16:
5725 case ARM::VST2LNqWB_register_Asm_32: {
5727 // Shuffle the operands around so the lane index operand is in the
5730 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5731 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5732 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5733 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5734 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5735 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5736 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5738 TmpInst.addOperand(Inst.getOperand(1)); // lane
5739 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5740 TmpInst.addOperand(Inst.getOperand(6));
5745 case ARM::VST3LNdWB_register_Asm_8:
5746 case ARM::VST3LNdWB_register_Asm_16:
5747 case ARM::VST3LNdWB_register_Asm_32:
5748 case ARM::VST3LNqWB_register_Asm_16:
5749 case ARM::VST3LNqWB_register_Asm_32: {
5751 // Shuffle the operands around so the lane index operand is in the
5754 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5755 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5756 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5757 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5758 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5759 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5760 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5762 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5764 TmpInst.addOperand(Inst.getOperand(1)); // lane
5765 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5766 TmpInst.addOperand(Inst.getOperand(6));
5771 case ARM::VST4LNdWB_register_Asm_8:
5772 case ARM::VST4LNdWB_register_Asm_16:
5773 case ARM::VST4LNdWB_register_Asm_32:
5774 case ARM::VST4LNqWB_register_Asm_16:
5775 case ARM::VST4LNqWB_register_Asm_32: {
5777 // Shuffle the operands around so the lane index operand is in the
5780 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5781 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5782 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5783 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5784 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5785 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5786 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5788 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5790 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5792 TmpInst.addOperand(Inst.getOperand(1)); // lane
5793 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5794 TmpInst.addOperand(Inst.getOperand(6));
5799 case ARM::VST1LNdWB_fixed_Asm_8:
5800 case ARM::VST1LNdWB_fixed_Asm_16:
5801 case ARM::VST1LNdWB_fixed_Asm_32: {
5803 // Shuffle the operands around so the lane index operand is in the
5806 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5807 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5808 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5809 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5810 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5811 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5812 TmpInst.addOperand(Inst.getOperand(1)); // lane
5813 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5814 TmpInst.addOperand(Inst.getOperand(5));
5819 case ARM::VST2LNdWB_fixed_Asm_8:
5820 case ARM::VST2LNdWB_fixed_Asm_16:
5821 case ARM::VST2LNdWB_fixed_Asm_32:
5822 case ARM::VST2LNqWB_fixed_Asm_16:
5823 case ARM::VST2LNqWB_fixed_Asm_32: {
5825 // Shuffle the operands around so the lane index operand is in the
5828 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5829 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5830 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5831 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5832 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5833 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5834 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5836 TmpInst.addOperand(Inst.getOperand(1)); // lane
5837 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5838 TmpInst.addOperand(Inst.getOperand(5));
5843 case ARM::VST3LNdWB_fixed_Asm_8:
5844 case ARM::VST3LNdWB_fixed_Asm_16:
5845 case ARM::VST3LNdWB_fixed_Asm_32:
5846 case ARM::VST3LNqWB_fixed_Asm_16:
5847 case ARM::VST3LNqWB_fixed_Asm_32: {
5849 // Shuffle the operands around so the lane index operand is in the
5852 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5853 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5854 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5855 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5856 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5857 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5860 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5862 TmpInst.addOperand(Inst.getOperand(1)); // lane
5863 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5864 TmpInst.addOperand(Inst.getOperand(5));
5869 case ARM::VST4LNdWB_fixed_Asm_8:
5870 case ARM::VST4LNdWB_fixed_Asm_16:
5871 case ARM::VST4LNdWB_fixed_Asm_32:
5872 case ARM::VST4LNqWB_fixed_Asm_16:
5873 case ARM::VST4LNqWB_fixed_Asm_32: {
5875 // Shuffle the operands around so the lane index operand is in the
5878 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5879 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5880 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5881 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5882 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5883 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5886 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5888 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5890 TmpInst.addOperand(Inst.getOperand(1)); // lane
5891 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5892 TmpInst.addOperand(Inst.getOperand(5));
5897 case ARM::VST1LNdAsm_8:
5898 case ARM::VST1LNdAsm_16:
5899 case ARM::VST1LNdAsm_32: {
5901 // Shuffle the operands around so the lane index operand is in the
5904 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5905 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5906 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5907 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5908 TmpInst.addOperand(Inst.getOperand(1)); // lane
5909 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5910 TmpInst.addOperand(Inst.getOperand(5));
5915 case ARM::VST2LNdAsm_8:
5916 case ARM::VST2LNdAsm_16:
5917 case ARM::VST2LNdAsm_32:
5918 case ARM::VST2LNqAsm_16:
5919 case ARM::VST2LNqAsm_32: {
5921 // Shuffle the operands around so the lane index operand is in the
5924 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5925 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5926 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5927 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5928 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5930 TmpInst.addOperand(Inst.getOperand(1)); // lane
5931 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5932 TmpInst.addOperand(Inst.getOperand(5));
5937 case ARM::VST3LNdAsm_8:
5938 case ARM::VST3LNdAsm_16:
5939 case ARM::VST3LNdAsm_32:
5940 case ARM::VST3LNqAsm_16:
5941 case ARM::VST3LNqAsm_32: {
5943 // Shuffle the operands around so the lane index operand is in the
5946 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5947 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5948 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5949 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5950 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5952 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5954 TmpInst.addOperand(Inst.getOperand(1)); // lane
5955 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5956 TmpInst.addOperand(Inst.getOperand(5));
5961 case ARM::VST4LNdAsm_8:
5962 case ARM::VST4LNdAsm_16:
5963 case ARM::VST4LNdAsm_32:
5964 case ARM::VST4LNqAsm_16:
5965 case ARM::VST4LNqAsm_32: {
5967 // Shuffle the operands around so the lane index operand is in the
5970 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5971 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5972 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5973 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5974 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5976 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5978 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5980 TmpInst.addOperand(Inst.getOperand(1)); // lane
5981 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5982 TmpInst.addOperand(Inst.getOperand(5));
5987 // Handle NEON VLD complex aliases.
5988 case ARM::VLD1LNdWB_register_Asm_8:
5989 case ARM::VLD1LNdWB_register_Asm_16:
5990 case ARM::VLD1LNdWB_register_Asm_32: {
5992 // Shuffle the operands around so the lane index operand is in the
5995 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5996 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5997 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5998 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5999 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6000 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6001 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6002 TmpInst.addOperand(Inst.getOperand(1)); // lane
6003 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6004 TmpInst.addOperand(Inst.getOperand(6));
6009 case ARM::VLD2LNdWB_register_Asm_8:
6010 case ARM::VLD2LNdWB_register_Asm_16:
6011 case ARM::VLD2LNdWB_register_Asm_32:
6012 case ARM::VLD2LNqWB_register_Asm_16:
6013 case ARM::VLD2LNqWB_register_Asm_32: {
6015 // Shuffle the operands around so the lane index operand is in the
6018 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6019 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6020 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6022 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6023 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6024 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6025 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6026 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6027 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6029 TmpInst.addOperand(Inst.getOperand(1)); // lane
6030 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6031 TmpInst.addOperand(Inst.getOperand(6));
6036 case ARM::VLD3LNdWB_register_Asm_8:
6037 case ARM::VLD3LNdWB_register_Asm_16:
6038 case ARM::VLD3LNdWB_register_Asm_32:
6039 case ARM::VLD3LNqWB_register_Asm_16:
6040 case ARM::VLD3LNqWB_register_Asm_32: {
6042 // Shuffle the operands around so the lane index operand is in the
6045 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6046 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6047 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6049 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6051 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6052 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6053 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6054 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6055 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6056 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6058 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6060 TmpInst.addOperand(Inst.getOperand(1)); // lane
6061 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6062 TmpInst.addOperand(Inst.getOperand(6));
6067 case ARM::VLD4LNdWB_register_Asm_8:
6068 case ARM::VLD4LNdWB_register_Asm_16:
6069 case ARM::VLD4LNdWB_register_Asm_32:
6070 case ARM::VLD4LNqWB_register_Asm_16:
6071 case ARM::VLD4LNqWB_register_Asm_32: {
6073 // Shuffle the operands around so the lane index operand is in the
6076 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6077 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6078 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6082 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6084 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6085 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6086 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6087 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6088 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6089 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6091 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6093 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6095 TmpInst.addOperand(Inst.getOperand(1)); // lane
6096 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6097 TmpInst.addOperand(Inst.getOperand(6));
6102 case ARM::VLD1LNdWB_fixed_Asm_8:
6103 case ARM::VLD1LNdWB_fixed_Asm_16:
6104 case ARM::VLD1LNdWB_fixed_Asm_32: {
6106 // Shuffle the operands around so the lane index operand is in the
6109 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6110 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6111 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6112 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6113 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6114 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6115 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6116 TmpInst.addOperand(Inst.getOperand(1)); // lane
6117 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6118 TmpInst.addOperand(Inst.getOperand(5));
6123 case ARM::VLD2LNdWB_fixed_Asm_8:
6124 case ARM::VLD2LNdWB_fixed_Asm_16:
6125 case ARM::VLD2LNdWB_fixed_Asm_32:
6126 case ARM::VLD2LNqWB_fixed_Asm_16:
6127 case ARM::VLD2LNqWB_fixed_Asm_32: {
6129 // Shuffle the operands around so the lane index operand is in the
6132 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6133 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6134 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6136 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6137 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6138 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6139 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6140 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6141 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6143 TmpInst.addOperand(Inst.getOperand(1)); // lane
6144 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6145 TmpInst.addOperand(Inst.getOperand(5));
6150 case ARM::VLD3LNdWB_fixed_Asm_8:
6151 case ARM::VLD3LNdWB_fixed_Asm_16:
6152 case ARM::VLD3LNdWB_fixed_Asm_32:
6153 case ARM::VLD3LNqWB_fixed_Asm_16:
6154 case ARM::VLD3LNqWB_fixed_Asm_32: {
6156 // Shuffle the operands around so the lane index operand is in the
6159 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6160 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6161 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6163 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6165 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6166 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6167 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6168 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6169 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6170 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6172 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6174 TmpInst.addOperand(Inst.getOperand(1)); // lane
6175 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6176 TmpInst.addOperand(Inst.getOperand(5));
6181 case ARM::VLD4LNdWB_fixed_Asm_8:
6182 case ARM::VLD4LNdWB_fixed_Asm_16:
6183 case ARM::VLD4LNdWB_fixed_Asm_32:
6184 case ARM::VLD4LNqWB_fixed_Asm_16:
6185 case ARM::VLD4LNqWB_fixed_Asm_32: {
6187 // Shuffle the operands around so the lane index operand is in the
6190 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6191 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6192 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6194 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6196 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6198 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6199 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6200 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6201 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6202 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6203 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6205 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6207 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6209 TmpInst.addOperand(Inst.getOperand(1)); // lane
6210 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6211 TmpInst.addOperand(Inst.getOperand(5));
6216 case ARM::VLD1LNdAsm_8:
6217 case ARM::VLD1LNdAsm_16:
6218 case ARM::VLD1LNdAsm_32: {
6220 // Shuffle the operands around so the lane index operand is in the
6223 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6224 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6225 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6226 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6227 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6228 TmpInst.addOperand(Inst.getOperand(1)); // lane
6229 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6230 TmpInst.addOperand(Inst.getOperand(5));
6235 case ARM::VLD2LNdAsm_8:
6236 case ARM::VLD2LNdAsm_16:
6237 case ARM::VLD2LNdAsm_32:
6238 case ARM::VLD2LNqAsm_16:
6239 case ARM::VLD2LNqAsm_32: {
6241 // Shuffle the operands around so the lane index operand is in the
6244 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6245 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6246 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6248 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6249 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6250 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6251 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6253 TmpInst.addOperand(Inst.getOperand(1)); // lane
6254 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6255 TmpInst.addOperand(Inst.getOperand(5));
6260 case ARM::VLD3LNdAsm_8:
6261 case ARM::VLD3LNdAsm_16:
6262 case ARM::VLD3LNdAsm_32:
6263 case ARM::VLD3LNqAsm_16:
6264 case ARM::VLD3LNqAsm_32: {
6266 // Shuffle the operands around so the lane index operand is in the
6269 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6270 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6271 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6273 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6275 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6276 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6277 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6278 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6280 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6282 TmpInst.addOperand(Inst.getOperand(1)); // lane
6283 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6284 TmpInst.addOperand(Inst.getOperand(5));
6289 case ARM::VLD4LNdAsm_8:
6290 case ARM::VLD4LNdAsm_16:
6291 case ARM::VLD4LNdAsm_32:
6292 case ARM::VLD4LNqAsm_16:
6293 case ARM::VLD4LNqAsm_32: {
6295 // Shuffle the operands around so the lane index operand is in the
6298 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6299 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6302 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6306 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6307 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6308 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6309 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6311 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6313 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6315 TmpInst.addOperand(Inst.getOperand(1)); // lane
6316 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6317 TmpInst.addOperand(Inst.getOperand(5));
6322 // VLD3DUP single 3-element structure to all lanes instructions.
6323 case ARM::VLD3DUPdAsm_8:
6324 case ARM::VLD3DUPdAsm_16:
6325 case ARM::VLD3DUPdAsm_32:
6326 case ARM::VLD3DUPqAsm_8:
6327 case ARM::VLD3DUPqAsm_16:
6328 case ARM::VLD3DUPqAsm_32: {
6331 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6332 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6335 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6337 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6338 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6339 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6340 TmpInst.addOperand(Inst.getOperand(4));
6345 case ARM::VLD3DUPdWB_fixed_Asm_8:
6346 case ARM::VLD3DUPdWB_fixed_Asm_16:
6347 case ARM::VLD3DUPdWB_fixed_Asm_32:
6348 case ARM::VLD3DUPqWB_fixed_Asm_8:
6349 case ARM::VLD3DUPqWB_fixed_Asm_16:
6350 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6353 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6354 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6355 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6357 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6359 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6360 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6361 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6362 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6363 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6364 TmpInst.addOperand(Inst.getOperand(4));
6369 case ARM::VLD3DUPdWB_register_Asm_8:
6370 case ARM::VLD3DUPdWB_register_Asm_16:
6371 case ARM::VLD3DUPdWB_register_Asm_32:
6372 case ARM::VLD3DUPqWB_register_Asm_8:
6373 case ARM::VLD3DUPqWB_register_Asm_16:
6374 case ARM::VLD3DUPqWB_register_Asm_32: {
6377 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6378 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6379 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6381 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6383 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6384 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6385 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6386 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6387 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6388 TmpInst.addOperand(Inst.getOperand(5));
6393 // VLD3 multiple 3-element structure instructions.
6394 case ARM::VLD3dAsm_8:
6395 case ARM::VLD3dAsm_16:
6396 case ARM::VLD3dAsm_32:
6397 case ARM::VLD3qAsm_8:
6398 case ARM::VLD3qAsm_16:
6399 case ARM::VLD3qAsm_32: {
6402 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6403 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6408 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6409 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6410 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6411 TmpInst.addOperand(Inst.getOperand(4));
6416 case ARM::VLD3dWB_fixed_Asm_8:
6417 case ARM::VLD3dWB_fixed_Asm_16:
6418 case ARM::VLD3dWB_fixed_Asm_32:
6419 case ARM::VLD3qWB_fixed_Asm_8:
6420 case ARM::VLD3qWB_fixed_Asm_16:
6421 case ARM::VLD3qWB_fixed_Asm_32: {
6424 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6425 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6426 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6430 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6431 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6432 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6433 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6434 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6435 TmpInst.addOperand(Inst.getOperand(4));
6440 case ARM::VLD3dWB_register_Asm_8:
6441 case ARM::VLD3dWB_register_Asm_16:
6442 case ARM::VLD3dWB_register_Asm_32:
6443 case ARM::VLD3qWB_register_Asm_8:
6444 case ARM::VLD3qWB_register_Asm_16:
6445 case ARM::VLD3qWB_register_Asm_32: {
6448 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6449 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6450 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6452 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6454 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6455 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6456 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6457 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6458 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6459 TmpInst.addOperand(Inst.getOperand(5));
6464 // VLD4DUP single 3-element structure to all lanes instructions.
6465 case ARM::VLD4DUPdAsm_8:
6466 case ARM::VLD4DUPdAsm_16:
6467 case ARM::VLD4DUPdAsm_32:
6468 case ARM::VLD4DUPqAsm_8:
6469 case ARM::VLD4DUPqAsm_16:
6470 case ARM::VLD4DUPqAsm_32: {
6473 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6474 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6477 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6479 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6481 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6482 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6483 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6484 TmpInst.addOperand(Inst.getOperand(4));
6489 case ARM::VLD4DUPdWB_fixed_Asm_8:
6490 case ARM::VLD4DUPdWB_fixed_Asm_16:
6491 case ARM::VLD4DUPdWB_fixed_Asm_32:
6492 case ARM::VLD4DUPqWB_fixed_Asm_8:
6493 case ARM::VLD4DUPqWB_fixed_Asm_16:
6494 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6497 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6498 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6501 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6503 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6505 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6506 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6507 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6508 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6509 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6510 TmpInst.addOperand(Inst.getOperand(4));
6515 case ARM::VLD4DUPdWB_register_Asm_8:
6516 case ARM::VLD4DUPdWB_register_Asm_16:
6517 case ARM::VLD4DUPdWB_register_Asm_32:
6518 case ARM::VLD4DUPqWB_register_Asm_8:
6519 case ARM::VLD4DUPqWB_register_Asm_16:
6520 case ARM::VLD4DUPqWB_register_Asm_32: {
6523 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6524 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6525 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6527 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6529 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6531 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6532 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6533 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6534 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6535 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6536 TmpInst.addOperand(Inst.getOperand(5));
6541 // VLD4 multiple 4-element structure instructions.
6542 case ARM::VLD4dAsm_8:
6543 case ARM::VLD4dAsm_16:
6544 case ARM::VLD4dAsm_32:
6545 case ARM::VLD4qAsm_8:
6546 case ARM::VLD4qAsm_16:
6547 case ARM::VLD4qAsm_32: {
6550 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6551 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6552 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6558 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6559 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6560 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6561 TmpInst.addOperand(Inst.getOperand(4));
6566 case ARM::VLD4dWB_fixed_Asm_8:
6567 case ARM::VLD4dWB_fixed_Asm_16:
6568 case ARM::VLD4dWB_fixed_Asm_32:
6569 case ARM::VLD4qWB_fixed_Asm_8:
6570 case ARM::VLD4qWB_fixed_Asm_16:
6571 case ARM::VLD4qWB_fixed_Asm_32: {
6574 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6575 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6578 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6582 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6583 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6584 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6585 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6586 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6587 TmpInst.addOperand(Inst.getOperand(4));
6592 case ARM::VLD4dWB_register_Asm_8:
6593 case ARM::VLD4dWB_register_Asm_16:
6594 case ARM::VLD4dWB_register_Asm_32:
6595 case ARM::VLD4qWB_register_Asm_8:
6596 case ARM::VLD4qWB_register_Asm_16:
6597 case ARM::VLD4qWB_register_Asm_32: {
6600 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6601 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6602 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6604 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6606 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6608 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6609 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6610 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6611 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6612 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6613 TmpInst.addOperand(Inst.getOperand(5));
6618 // VST3 multiple 3-element structure instructions.
6619 case ARM::VST3dAsm_8:
6620 case ARM::VST3dAsm_16:
6621 case ARM::VST3dAsm_32:
6622 case ARM::VST3qAsm_8:
6623 case ARM::VST3qAsm_16:
6624 case ARM::VST3qAsm_32: {
6627 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6628 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6629 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6630 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6631 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6635 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6636 TmpInst.addOperand(Inst.getOperand(4));
6641 case ARM::VST3dWB_fixed_Asm_8:
6642 case ARM::VST3dWB_fixed_Asm_16:
6643 case ARM::VST3dWB_fixed_Asm_32:
6644 case ARM::VST3qWB_fixed_Asm_8:
6645 case ARM::VST3qWB_fixed_Asm_16:
6646 case ARM::VST3qWB_fixed_Asm_32: {
6649 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6650 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6651 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6652 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6653 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6654 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6657 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6659 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6660 TmpInst.addOperand(Inst.getOperand(4));
6665 case ARM::VST3dWB_register_Asm_8:
6666 case ARM::VST3dWB_register_Asm_16:
6667 case ARM::VST3dWB_register_Asm_32:
6668 case ARM::VST3qWB_register_Asm_8:
6669 case ARM::VST3qWB_register_Asm_16:
6670 case ARM::VST3qWB_register_Asm_32: {
6673 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6674 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6675 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6676 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6677 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6678 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6679 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6681 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6683 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6684 TmpInst.addOperand(Inst.getOperand(5));
6689 // VST4 multiple 3-element structure instructions.
6690 case ARM::VST4dAsm_8:
6691 case ARM::VST4dAsm_16:
6692 case ARM::VST4dAsm_32:
6693 case ARM::VST4qAsm_8:
6694 case ARM::VST4qAsm_16:
6695 case ARM::VST4qAsm_32: {
6698 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6699 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6700 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6701 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6702 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6704 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6706 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6708 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6709 TmpInst.addOperand(Inst.getOperand(4));
6714 case ARM::VST4dWB_fixed_Asm_8:
6715 case ARM::VST4dWB_fixed_Asm_16:
6716 case ARM::VST4dWB_fixed_Asm_32:
6717 case ARM::VST4qWB_fixed_Asm_8:
6718 case ARM::VST4qWB_fixed_Asm_16:
6719 case ARM::VST4qWB_fixed_Asm_32: {
6722 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6723 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6724 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6725 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6726 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6727 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6728 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6730 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6732 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6734 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6735 TmpInst.addOperand(Inst.getOperand(4));
6740 case ARM::VST4dWB_register_Asm_8:
6741 case ARM::VST4dWB_register_Asm_16:
6742 case ARM::VST4dWB_register_Asm_32:
6743 case ARM::VST4qWB_register_Asm_8:
6744 case ARM::VST4qWB_register_Asm_16:
6745 case ARM::VST4qWB_register_Asm_32: {
6748 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6749 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6750 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6751 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6752 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6753 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6754 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6756 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6758 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6760 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6761 TmpInst.addOperand(Inst.getOperand(5));
6766 // Handle encoding choice for the shift-immediate instructions.
6769 case ARM::t2ASRri: {
6770 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6771 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6772 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6773 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6774 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6776 switch (Inst.getOpcode()) {
6777 default: llvm_unreachable("unexpected opcode");
6778 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6779 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6780 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6782 // The Thumb1 operands aren't in the same order. Awesome, eh?
6784 TmpInst.setOpcode(NewOpc);
6785 TmpInst.addOperand(Inst.getOperand(0));
6786 TmpInst.addOperand(Inst.getOperand(5));
6787 TmpInst.addOperand(Inst.getOperand(1));
6788 TmpInst.addOperand(Inst.getOperand(2));
6789 TmpInst.addOperand(Inst.getOperand(3));
6790 TmpInst.addOperand(Inst.getOperand(4));
6797 // Handle the Thumb2 mode MOV complex aliases.
6799 case ARM::t2MOVSsr: {
6800 // Which instruction to expand to depends on the CCOut operand and
6801 // whether we're in an IT block if the register operands are low
6803 bool isNarrow = false;
6804 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6805 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6806 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6807 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6808 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6812 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6813 default: llvm_unreachable("unexpected opcode!");
6814 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6815 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6816 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6817 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6819 TmpInst.setOpcode(newOpc);
6820 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6822 TmpInst.addOperand(MCOperand::CreateReg(
6823 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6824 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6825 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6826 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6827 TmpInst.addOperand(Inst.getOperand(5));
6829 TmpInst.addOperand(MCOperand::CreateReg(
6830 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6835 case ARM::t2MOVSsi: {
6836 // Which instruction to expand to depends on the CCOut operand and
6837 // whether we're in an IT block if the register operands are low
6839 bool isNarrow = false;
6840 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6841 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6842 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6846 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6847 default: llvm_unreachable("unexpected opcode!");
6848 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6849 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6850 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6851 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
6852 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
6854 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6855 if (Amount == 32) Amount = 0;
6856 TmpInst.setOpcode(newOpc);
6857 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6859 TmpInst.addOperand(MCOperand::CreateReg(
6860 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6861 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6862 if (newOpc != ARM::t2RRX)
6863 TmpInst.addOperand(MCOperand::CreateImm(Amount));
6864 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6865 TmpInst.addOperand(Inst.getOperand(4));
6867 TmpInst.addOperand(MCOperand::CreateReg(
6868 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6872 // Handle the ARM mode MOV complex aliases.
6877 ARM_AM::ShiftOpc ShiftTy;
6878 switch(Inst.getOpcode()) {
6879 default: llvm_unreachable("unexpected opcode!");
6880 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6881 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6882 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6883 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6885 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6887 TmpInst.setOpcode(ARM::MOVsr);
6888 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6889 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6890 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6891 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6892 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6893 TmpInst.addOperand(Inst.getOperand(4));
6894 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6902 ARM_AM::ShiftOpc ShiftTy;
6903 switch(Inst.getOpcode()) {
6904 default: llvm_unreachable("unexpected opcode!");
6905 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6906 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6907 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6908 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6910 // A shift by zero is a plain MOVr, not a MOVsi.
6911 unsigned Amt = Inst.getOperand(2).getImm();
6912 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
6913 // A shift by 32 should be encoded as 0 when permitted
6914 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6916 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
6918 TmpInst.setOpcode(Opc);
6919 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6920 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6921 if (Opc == ARM::MOVsi)
6922 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6923 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6924 TmpInst.addOperand(Inst.getOperand(4));
6925 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6930 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6932 TmpInst.setOpcode(ARM::MOVsi);
6933 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6934 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6935 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6936 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6937 TmpInst.addOperand(Inst.getOperand(3));
6938 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6942 case ARM::t2LDMIA_UPD: {
6943 // If this is a load of a single register, then we should use
6944 // a post-indexed LDR instruction instead, per the ARM ARM.
6945 if (Inst.getNumOperands() != 5)
6948 TmpInst.setOpcode(ARM::t2LDR_POST);
6949 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6950 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6951 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6952 TmpInst.addOperand(MCOperand::CreateImm(4));
6953 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6954 TmpInst.addOperand(Inst.getOperand(3));
6958 case ARM::t2STMDB_UPD: {
6959 // If this is a store of a single register, then we should use
6960 // a pre-indexed STR instruction instead, per the ARM ARM.
6961 if (Inst.getNumOperands() != 5)
6964 TmpInst.setOpcode(ARM::t2STR_PRE);
6965 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6966 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6967 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6968 TmpInst.addOperand(MCOperand::CreateImm(-4));
6969 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6970 TmpInst.addOperand(Inst.getOperand(3));
6974 case ARM::LDMIA_UPD:
6975 // If this is a load of a single register via a 'pop', then we should use
6976 // a post-indexed LDR instruction instead, per the ARM ARM.
6977 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6978 Inst.getNumOperands() == 5) {
6980 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6981 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6982 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6983 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6984 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6985 TmpInst.addOperand(MCOperand::CreateImm(4));
6986 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6987 TmpInst.addOperand(Inst.getOperand(3));
6992 case ARM::STMDB_UPD:
6993 // If this is a store of a single register via a 'push', then we should use
6994 // a pre-indexed STR instruction instead, per the ARM ARM.
6995 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6996 Inst.getNumOperands() == 5) {
6998 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6999 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7000 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7001 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7002 TmpInst.addOperand(MCOperand::CreateImm(-4));
7003 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7004 TmpInst.addOperand(Inst.getOperand(3));
7008 case ARM::t2ADDri12:
7009 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7010 // mnemonic was used (not "addw"), encoding T3 is preferred.
7011 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7012 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7014 Inst.setOpcode(ARM::t2ADDri);
7015 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7017 case ARM::t2SUBri12:
7018 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7019 // mnemonic was used (not "subw"), encoding T3 is preferred.
7020 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7021 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7023 Inst.setOpcode(ARM::t2SUBri);
7024 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7027 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7028 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7029 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7030 // to encoding T1 if <Rd> is omitted."
7031 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7032 Inst.setOpcode(ARM::tADDi3);
7037 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7038 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7039 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7040 // to encoding T1 if <Rd> is omitted."
7041 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7042 Inst.setOpcode(ARM::tSUBi3);
7047 case ARM::t2SUBri: {
7048 // If the destination and first source operand are the same, and
7049 // the flags are compatible with the current IT status, use encoding T2
7050 // instead of T3. For compatibility with the system 'as'. Make sure the
7051 // wide encoding wasn't explicit.
7052 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7053 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7054 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7055 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7056 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7057 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7058 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7061 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7062 ARM::tADDi8 : ARM::tSUBi8);
7063 TmpInst.addOperand(Inst.getOperand(0));
7064 TmpInst.addOperand(Inst.getOperand(5));
7065 TmpInst.addOperand(Inst.getOperand(0));
7066 TmpInst.addOperand(Inst.getOperand(2));
7067 TmpInst.addOperand(Inst.getOperand(3));
7068 TmpInst.addOperand(Inst.getOperand(4));
7072 case ARM::t2ADDrr: {
7073 // If the destination and first source operand are the same, and
7074 // there's no setting of the flags, use encoding T2 instead of T3.
7075 // Note that this is only for ADD, not SUB. This mirrors the system
7076 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7077 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7078 Inst.getOperand(5).getReg() != 0 ||
7079 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7080 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7083 TmpInst.setOpcode(ARM::tADDhirr);
7084 TmpInst.addOperand(Inst.getOperand(0));
7085 TmpInst.addOperand(Inst.getOperand(0));
7086 TmpInst.addOperand(Inst.getOperand(2));
7087 TmpInst.addOperand(Inst.getOperand(3));
7088 TmpInst.addOperand(Inst.getOperand(4));
7092 case ARM::tADDrSP: {
7093 // If the non-SP source operand and the destination operand are not the
7094 // same, we need to use the 32-bit encoding if it's available.
7095 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7096 Inst.setOpcode(ARM::t2ADDrr);
7097 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7103 // A Thumb conditional branch outside of an IT block is a tBcc.
7104 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7105 Inst.setOpcode(ARM::tBcc);
7110 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7111 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7112 Inst.setOpcode(ARM::t2Bcc);
7117 // If the conditional is AL or we're in an IT block, we really want t2B.
7118 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7119 Inst.setOpcode(ARM::t2B);
7124 // If the conditional is AL, we really want tB.
7125 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7126 Inst.setOpcode(ARM::tB);
7131 // If the register list contains any high registers, or if the writeback
7132 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7133 // instead if we're in Thumb2. Otherwise, this should have generated
7134 // an error in validateInstruction().
7135 unsigned Rn = Inst.getOperand(0).getReg();
7136 bool hasWritebackToken =
7137 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7138 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7139 bool listContainsBase;
7140 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7141 (!listContainsBase && !hasWritebackToken) ||
7142 (listContainsBase && hasWritebackToken)) {
7143 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7144 assert (isThumbTwo());
7145 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7146 // If we're switching to the updating version, we need to insert
7147 // the writeback tied operand.
7148 if (hasWritebackToken)
7149 Inst.insert(Inst.begin(),
7150 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7155 case ARM::tSTMIA_UPD: {
7156 // If the register list contains any high registers, we need to use
7157 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7158 // should have generated an error in validateInstruction().
7159 unsigned Rn = Inst.getOperand(0).getReg();
7160 bool listContainsBase;
7161 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7162 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7163 assert (isThumbTwo());
7164 Inst.setOpcode(ARM::t2STMIA_UPD);
7170 bool listContainsBase;
7171 // If the register list contains any high registers, we need to use
7172 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7173 // should have generated an error in validateInstruction().
7174 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7176 assert (isThumbTwo());
7177 Inst.setOpcode(ARM::t2LDMIA_UPD);
7178 // Add the base register and writeback operands.
7179 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7180 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7184 bool listContainsBase;
7185 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7187 assert (isThumbTwo());
7188 Inst.setOpcode(ARM::t2STMDB_UPD);
7189 // Add the base register and writeback operands.
7190 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7191 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7195 // If we can use the 16-bit encoding and the user didn't explicitly
7196 // request the 32-bit variant, transform it here.
7197 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7198 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7199 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7200 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7201 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7202 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7203 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7204 // The operands aren't in the same order for tMOVi8...
7206 TmpInst.setOpcode(ARM::tMOVi8);
7207 TmpInst.addOperand(Inst.getOperand(0));
7208 TmpInst.addOperand(Inst.getOperand(4));
7209 TmpInst.addOperand(Inst.getOperand(1));
7210 TmpInst.addOperand(Inst.getOperand(2));
7211 TmpInst.addOperand(Inst.getOperand(3));
7218 // If we can use the 16-bit encoding and the user didn't explicitly
7219 // request the 32-bit variant, transform it here.
7220 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7221 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7222 Inst.getOperand(2).getImm() == ARMCC::AL &&
7223 Inst.getOperand(4).getReg() == ARM::CPSR &&
7224 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7225 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7226 // The operands aren't the same for tMOV[S]r... (no cc_out)
7228 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7229 TmpInst.addOperand(Inst.getOperand(0));
7230 TmpInst.addOperand(Inst.getOperand(1));
7231 TmpInst.addOperand(Inst.getOperand(2));
7232 TmpInst.addOperand(Inst.getOperand(3));
7242 // If we can use the 16-bit encoding and the user didn't explicitly
7243 // request the 32-bit variant, transform it here.
7244 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7245 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7246 Inst.getOperand(2).getImm() == 0 &&
7247 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7248 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7250 switch (Inst.getOpcode()) {
7251 default: llvm_unreachable("Illegal opcode!");
7252 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7253 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7254 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7255 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7257 // The operands aren't the same for thumb1 (no rotate operand).
7259 TmpInst.setOpcode(NewOpc);
7260 TmpInst.addOperand(Inst.getOperand(0));
7261 TmpInst.addOperand(Inst.getOperand(1));
7262 TmpInst.addOperand(Inst.getOperand(3));
7263 TmpInst.addOperand(Inst.getOperand(4));
7270 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7271 // rrx shifts and asr/lsr of #32 is encoded as 0
7272 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7274 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7275 // Shifting by zero is accepted as a vanilla 'MOVr'
7277 TmpInst.setOpcode(ARM::MOVr);
7278 TmpInst.addOperand(Inst.getOperand(0));
7279 TmpInst.addOperand(Inst.getOperand(1));
7280 TmpInst.addOperand(Inst.getOperand(3));
7281 TmpInst.addOperand(Inst.getOperand(4));
7282 TmpInst.addOperand(Inst.getOperand(5));
7295 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7296 if (SOpc == ARM_AM::rrx) return false;
7297 switch (Inst.getOpcode()) {
7298 default: llvm_unreachable("unexpected opcode!");
7299 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7300 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7301 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7302 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7303 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7304 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7306 // If the shift is by zero, use the non-shifted instruction definition.
7307 // The exception is for right shifts, where 0 == 32
7308 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7309 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7311 TmpInst.setOpcode(newOpc);
7312 TmpInst.addOperand(Inst.getOperand(0));
7313 TmpInst.addOperand(Inst.getOperand(1));
7314 TmpInst.addOperand(Inst.getOperand(2));
7315 TmpInst.addOperand(Inst.getOperand(4));
7316 TmpInst.addOperand(Inst.getOperand(5));
7317 TmpInst.addOperand(Inst.getOperand(6));
7325 // The mask bits for all but the first condition are represented as
7326 // the low bit of the condition code value implies 't'. We currently
7327 // always have 1 implies 't', so XOR toggle the bits if the low bit
7328 // of the condition code is zero.
7329 MCOperand &MO = Inst.getOperand(1);
7330 unsigned Mask = MO.getImm();
7331 unsigned OrigMask = Mask;
7332 unsigned TZ = CountTrailingZeros_32(Mask);
7333 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7334 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7335 for (unsigned i = 3; i != TZ; --i)
7340 // Set up the IT block state according to the IT instruction we just
7342 assert(!inITBlock() && "nested IT blocks?!");
7343 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7344 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7345 ITState.CurPosition = 0;
7346 ITState.FirstCond = true;
7356 // Assemblers should use the narrow encodings of these instructions when permissible.
7357 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7358 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7359 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7360 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7361 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7362 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7363 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7365 switch (Inst.getOpcode()) {
7366 default: llvm_unreachable("unexpected opcode");
7367 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7368 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7369 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7370 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7371 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7372 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7375 TmpInst.setOpcode(NewOpc);
7376 TmpInst.addOperand(Inst.getOperand(0));
7377 TmpInst.addOperand(Inst.getOperand(5));
7378 TmpInst.addOperand(Inst.getOperand(1));
7379 TmpInst.addOperand(Inst.getOperand(2));
7380 TmpInst.addOperand(Inst.getOperand(3));
7381 TmpInst.addOperand(Inst.getOperand(4));
7392 // Assemblers should use the narrow encodings of these instructions when permissible.
7393 // These instructions are special in that they are commutable, so shorter encodings
7394 // are available more often.
7395 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7396 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7397 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7398 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7399 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7400 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7401 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7402 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7404 switch (Inst.getOpcode()) {
7405 default: llvm_unreachable("unexpected opcode");
7406 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7407 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7408 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7409 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7412 TmpInst.setOpcode(NewOpc);
7413 TmpInst.addOperand(Inst.getOperand(0));
7414 TmpInst.addOperand(Inst.getOperand(5));
7415 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7416 TmpInst.addOperand(Inst.getOperand(1));
7417 TmpInst.addOperand(Inst.getOperand(2));
7419 TmpInst.addOperand(Inst.getOperand(2));
7420 TmpInst.addOperand(Inst.getOperand(1));
7422 TmpInst.addOperand(Inst.getOperand(3));
7423 TmpInst.addOperand(Inst.getOperand(4));
7433 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7434 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7435 // suffix depending on whether they're in an IT block or not.
7436 unsigned Opc = Inst.getOpcode();
7437 const MCInstrDesc &MCID = getInstDesc(Opc);
7438 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7439 assert(MCID.hasOptionalDef() &&
7440 "optionally flag setting instruction missing optional def operand");
7441 assert(MCID.NumOperands == Inst.getNumOperands() &&
7442 "operand count mismatch!");
7443 // Find the optional-def operand (cc_out).
7446 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7449 // If we're parsing Thumb1, reject it completely.
7450 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7451 return Match_MnemonicFail;
7452 // If we're parsing Thumb2, which form is legal depends on whether we're
7454 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7456 return Match_RequiresITBlock;
7457 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7459 return Match_RequiresNotITBlock;
7461 // Some high-register supporting Thumb1 encodings only allow both registers
7462 // to be from r0-r7 when in Thumb2.
7463 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7464 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7465 isARMLowRegister(Inst.getOperand(2).getReg()))
7466 return Match_RequiresThumb2;
7467 // Others only require ARMv6 or later.
7468 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7469 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7470 isARMLowRegister(Inst.getOperand(1).getReg()))
7471 return Match_RequiresV6;
7472 return Match_Success;
7475 static const char *getSubtargetFeatureName(unsigned Val);
7477 MatchAndEmitInstruction(SMLoc IDLoc,
7478 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7483 unsigned MatchResult;
7484 MatchInstMapAndConstraints MapAndConstraints;
7485 MatchResult = MatchInstructionImpl(Operands, Kind, Inst,
7486 MapAndConstraints, ErrorInfo,
7487 /*matchingInlineAsm*/ false);
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"