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 "llvm/MC/MCTargetAsmParser.h"
11 #include "MCTargetDesc/ARMAddressingModes.h"
12 #include "MCTargetDesc/ARMBaseInfo.h"
13 #include "MCTargetDesc/ARMMCExpr.h"
14 #include "llvm/ADT/BitVector.h"
15 #include "llvm/ADT/OwningPtr.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringSwitch.h"
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/MC/MCAsmInfo.h"
21 #include "llvm/MC/MCAssembler.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCELFStreamer.h"
24 #include "llvm/MC/MCExpr.h"
25 #include "llvm/MC/MCInst.h"
26 #include "llvm/MC/MCInstrDesc.h"
27 #include "llvm/MC/MCParser/MCAsmLexer.h"
28 #include "llvm/MC/MCParser/MCAsmParser.h"
29 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
30 #include "llvm/MC/MCRegisterInfo.h"
31 #include "llvm/MC/MCStreamer.h"
32 #include "llvm/MC/MCSubtargetInfo.h"
33 #include "llvm/Support/ELF.h"
34 #include "llvm/Support/MathExtras.h"
35 #include "llvm/Support/SourceMgr.h"
36 #include "llvm/Support/TargetRegistry.h"
37 #include "llvm/Support/raw_ostream.h"
45 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
47 class ARMAsmParser : public MCTargetAsmParser {
50 const MCRegisterInfo *MRI;
52 // Unwind directives state
58 void resetUnwindDirectiveParserState() {
60 CantUnwindLoc = SMLoc();
61 PersonalityLoc = SMLoc();
62 HandlerDataLoc = SMLoc();
66 // Map of register aliases registers via the .req directive.
67 StringMap<unsigned> RegisterReqs;
70 ARMCC::CondCodes Cond; // Condition for IT block.
71 unsigned Mask:4; // Condition mask for instructions.
72 // Starting at first 1 (from lsb).
73 // '1' condition as indicated in IT.
74 // '0' inverse of condition (else).
75 // Count of instructions in IT block is
76 // 4 - trailingzeroes(mask)
78 bool FirstCond; // Explicit flag for when we're parsing the
79 // First instruction in the IT block. It's
80 // implied in the mask, so needs special
83 unsigned CurPosition; // Current position in parsing of IT
84 // block. In range [0,3]. Initialized
85 // according to count of instructions in block.
86 // ~0U if no active IT block.
88 bool inITBlock() { return ITState.CurPosition != ~0U;}
89 void forwardITPosition() {
90 if (!inITBlock()) return;
91 // Move to the next instruction in the IT block, if there is one. If not,
92 // mark the block as done.
93 unsigned TZ = countTrailingZeros(ITState.Mask);
94 if (++ITState.CurPosition == 5 - TZ)
95 ITState.CurPosition = ~0U; // Done with the IT block after this.
99 MCAsmParser &getParser() const { return Parser; }
100 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
102 bool Warning(SMLoc L, const Twine &Msg,
103 ArrayRef<SMRange> Ranges = None) {
104 return Parser.Warning(L, Msg, Ranges);
106 bool Error(SMLoc L, const Twine &Msg,
107 ArrayRef<SMRange> Ranges = None) {
108 return Parser.Error(L, Msg, Ranges);
111 int tryParseRegister();
112 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
113 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
114 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
115 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
116 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
117 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
118 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
119 unsigned &ShiftAmount);
120 bool parseDirectiveWord(unsigned Size, SMLoc L);
121 bool parseDirectiveThumb(SMLoc L);
122 bool parseDirectiveARM(SMLoc L);
123 bool parseDirectiveThumbFunc(SMLoc L);
124 bool parseDirectiveCode(SMLoc L);
125 bool parseDirectiveSyntax(SMLoc L);
126 bool parseDirectiveReq(StringRef Name, SMLoc L);
127 bool parseDirectiveUnreq(SMLoc L);
128 bool parseDirectiveArch(SMLoc L);
129 bool parseDirectiveEabiAttr(SMLoc L);
130 bool parseDirectiveFnStart(SMLoc L);
131 bool parseDirectiveFnEnd(SMLoc L);
132 bool parseDirectiveCantUnwind(SMLoc L);
133 bool parseDirectivePersonality(SMLoc L);
134 bool parseDirectiveHandlerData(SMLoc L);
135 bool parseDirectiveSetFP(SMLoc L);
136 bool parseDirectivePad(SMLoc L);
137 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
139 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
140 bool &CarrySetting, unsigned &ProcessorIMod,
142 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
143 bool &CanAcceptPredicationCode);
145 bool isThumb() const {
146 // FIXME: Can tablegen auto-generate this?
147 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
149 bool isThumbOne() const {
150 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
152 bool isThumbTwo() const {
153 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
155 bool hasV6Ops() const {
156 return STI.getFeatureBits() & ARM::HasV6Ops;
158 bool hasV7Ops() const {
159 return STI.getFeatureBits() & ARM::HasV7Ops;
162 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
163 setAvailableFeatures(FB);
165 bool isMClass() const {
166 return STI.getFeatureBits() & ARM::FeatureMClass;
169 /// @name Auto-generated Match Functions
172 #define GET_ASSEMBLER_HEADER
173 #include "ARMGenAsmMatcher.inc"
177 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
178 OperandMatchResultTy parseCoprocNumOperand(
179 SmallVectorImpl<MCParsedAsmOperand*>&);
180 OperandMatchResultTy parseCoprocRegOperand(
181 SmallVectorImpl<MCParsedAsmOperand*>&);
182 OperandMatchResultTy parseCoprocOptionOperand(
183 SmallVectorImpl<MCParsedAsmOperand*>&);
184 OperandMatchResultTy parseMemBarrierOptOperand(
185 SmallVectorImpl<MCParsedAsmOperand*>&);
186 OperandMatchResultTy parseInstSyncBarrierOptOperand(
187 SmallVectorImpl<MCParsedAsmOperand*>&);
188 OperandMatchResultTy parseProcIFlagsOperand(
189 SmallVectorImpl<MCParsedAsmOperand*>&);
190 OperandMatchResultTy parseMSRMaskOperand(
191 SmallVectorImpl<MCParsedAsmOperand*>&);
192 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
193 StringRef Op, int Low, int High);
194 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
195 return parsePKHImm(O, "lsl", 0, 31);
197 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
198 return parsePKHImm(O, "asr", 1, 32);
200 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
201 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
202 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
203 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
204 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
205 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
206 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
207 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
208 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
211 // Asm Match Converter Methods
212 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
213 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
214 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
215 const SmallVectorImpl<MCParsedAsmOperand*> &);
216 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
217 const SmallVectorImpl<MCParsedAsmOperand*> &);
218 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
219 const SmallVectorImpl<MCParsedAsmOperand*> &);
220 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
221 const SmallVectorImpl<MCParsedAsmOperand*> &);
222 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
223 const SmallVectorImpl<MCParsedAsmOperand*> &);
224 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &);
226 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
227 const SmallVectorImpl<MCParsedAsmOperand*> &);
228 void cvtLdExtTWriteBackImm(MCInst &Inst,
229 const SmallVectorImpl<MCParsedAsmOperand*> &);
230 void cvtLdExtTWriteBackReg(MCInst &Inst,
231 const SmallVectorImpl<MCParsedAsmOperand*> &);
232 void cvtStExtTWriteBackImm(MCInst &Inst,
233 const SmallVectorImpl<MCParsedAsmOperand*> &);
234 void cvtStExtTWriteBackReg(MCInst &Inst,
235 const SmallVectorImpl<MCParsedAsmOperand*> &);
236 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
237 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
238 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
239 const SmallVectorImpl<MCParsedAsmOperand*> &);
240 void cvtThumbMultiply(MCInst &Inst,
241 const SmallVectorImpl<MCParsedAsmOperand*> &);
242 void cvtVLDwbFixed(MCInst &Inst,
243 const SmallVectorImpl<MCParsedAsmOperand*> &);
244 void cvtVLDwbRegister(MCInst &Inst,
245 const SmallVectorImpl<MCParsedAsmOperand*> &);
246 void cvtVSTwbFixed(MCInst &Inst,
247 const SmallVectorImpl<MCParsedAsmOperand*> &);
248 void cvtVSTwbRegister(MCInst &Inst,
249 const SmallVectorImpl<MCParsedAsmOperand*> &);
250 bool validateInstruction(MCInst &Inst,
251 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
252 bool processInstruction(MCInst &Inst,
253 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
254 bool shouldOmitCCOutOperand(StringRef Mnemonic,
255 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
258 enum ARMMatchResultTy {
259 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
260 Match_RequiresNotITBlock,
262 Match_RequiresThumb2,
263 #define GET_OPERAND_DIAGNOSTIC_TYPES
264 #include "ARMGenAsmMatcher.inc"
268 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
269 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
270 MCAsmParserExtension::Initialize(_Parser);
272 // Cache the MCRegisterInfo.
273 MRI = &getContext().getRegisterInfo();
275 // Initialize the set of available features.
276 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
278 // Not in an ITBlock to start with.
279 ITState.CurPosition = ~0U;
281 // Set ELF header flags.
282 // FIXME: This should eventually end up somewhere else where more
283 // intelligent flag decisions can be made. For now we are just maintaining
284 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
285 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
286 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
289 // Implementation of the MCTargetAsmParser interface:
290 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
291 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
293 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
294 bool ParseDirective(AsmToken DirectiveID);
296 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
297 unsigned checkTargetMatchPredicate(MCInst &Inst);
299 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
300 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
301 MCStreamer &Out, unsigned &ErrorInfo,
302 bool MatchingInlineAsm);
304 } // end anonymous namespace
308 /// ARMOperand - Instances of this class represent a parsed ARM machine
310 class ARMOperand : public MCParsedAsmOperand {
320 k_InstSyncBarrierOpt,
331 k_VectorListAllLanes,
337 k_BitfieldDescriptor,
341 SMLoc StartLoc, EndLoc;
342 SmallVector<unsigned, 8> Registers;
345 ARMCC::CondCodes Val;
352 struct CoprocOptionOp {
365 ARM_ISB::InstSyncBOpt Val;
369 ARM_PROC::IFlags Val;
385 // A vector register list is a sequential list of 1 to 4 registers.
386 struct VectorListOp {
393 struct VectorIndexOp {
401 /// Combined record for all forms of ARM address expressions.
404 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
406 const MCConstantExpr *OffsetImm; // Offset immediate value
407 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
408 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
409 unsigned ShiftImm; // shift for OffsetReg.
410 unsigned Alignment; // 0 = no alignment specified
411 // n = alignment in bytes (2, 4, 8, 16, or 32)
412 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
415 struct PostIdxRegOp {
418 ARM_AM::ShiftOpc ShiftTy;
422 struct ShifterImmOp {
427 struct RegShiftedRegOp {
428 ARM_AM::ShiftOpc ShiftTy;
434 struct RegShiftedImmOp {
435 ARM_AM::ShiftOpc ShiftTy;
452 struct CoprocOptionOp CoprocOption;
453 struct MBOptOp MBOpt;
454 struct ISBOptOp ISBOpt;
455 struct ITMaskOp ITMask;
456 struct IFlagsOp IFlags;
457 struct MMaskOp MMask;
460 struct VectorListOp VectorList;
461 struct VectorIndexOp VectorIndex;
463 struct MemoryOp Memory;
464 struct PostIdxRegOp PostIdxReg;
465 struct ShifterImmOp ShifterImm;
466 struct RegShiftedRegOp RegShiftedReg;
467 struct RegShiftedImmOp RegShiftedImm;
468 struct RotImmOp RotImm;
469 struct BitfieldOp Bitfield;
472 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
474 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
476 StartLoc = o.StartLoc;
493 case k_DPRRegisterList:
494 case k_SPRRegisterList:
495 Registers = o.Registers;
498 case k_VectorListAllLanes:
499 case k_VectorListIndexed:
500 VectorList = o.VectorList;
507 CoprocOption = o.CoprocOption;
512 case k_MemBarrierOpt:
515 case k_InstSyncBarrierOpt:
520 case k_PostIndexRegister:
521 PostIdxReg = o.PostIdxReg;
529 case k_ShifterImmediate:
530 ShifterImm = o.ShifterImm;
532 case k_ShiftedRegister:
533 RegShiftedReg = o.RegShiftedReg;
535 case k_ShiftedImmediate:
536 RegShiftedImm = o.RegShiftedImm;
538 case k_RotateImmediate:
541 case k_BitfieldDescriptor:
542 Bitfield = o.Bitfield;
545 VectorIndex = o.VectorIndex;
550 /// getStartLoc - Get the location of the first token of this operand.
551 SMLoc getStartLoc() const { return StartLoc; }
552 /// getEndLoc - Get the location of the last token of this operand.
553 SMLoc getEndLoc() const { return EndLoc; }
554 /// getLocRange - Get the range between the first and last token of this
556 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
558 ARMCC::CondCodes getCondCode() const {
559 assert(Kind == k_CondCode && "Invalid access!");
563 unsigned getCoproc() const {
564 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
568 StringRef getToken() const {
569 assert(Kind == k_Token && "Invalid access!");
570 return StringRef(Tok.Data, Tok.Length);
573 unsigned getReg() const {
574 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
578 const SmallVectorImpl<unsigned> &getRegList() const {
579 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
580 Kind == k_SPRRegisterList) && "Invalid access!");
584 const MCExpr *getImm() const {
585 assert(isImm() && "Invalid access!");
589 unsigned getVectorIndex() const {
590 assert(Kind == k_VectorIndex && "Invalid access!");
591 return VectorIndex.Val;
594 ARM_MB::MemBOpt getMemBarrierOpt() const {
595 assert(Kind == k_MemBarrierOpt && "Invalid access!");
599 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
600 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
604 ARM_PROC::IFlags getProcIFlags() const {
605 assert(Kind == k_ProcIFlags && "Invalid access!");
609 unsigned getMSRMask() const {
610 assert(Kind == k_MSRMask && "Invalid access!");
614 bool isCoprocNum() const { return Kind == k_CoprocNum; }
615 bool isCoprocReg() const { return Kind == k_CoprocReg; }
616 bool isCoprocOption() const { return Kind == k_CoprocOption; }
617 bool isCondCode() const { return Kind == k_CondCode; }
618 bool isCCOut() const { return Kind == k_CCOut; }
619 bool isITMask() const { return Kind == k_ITCondMask; }
620 bool isITCondCode() const { return Kind == k_CondCode; }
621 bool isImm() const { return Kind == k_Immediate; }
622 bool isFPImm() const {
623 if (!isImm()) return false;
624 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
625 if (!CE) return false;
626 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
629 bool isFBits16() const {
630 if (!isImm()) return false;
631 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
632 if (!CE) return false;
633 int64_t Value = CE->getValue();
634 return Value >= 0 && Value <= 16;
636 bool isFBits32() const {
637 if (!isImm()) return false;
638 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
639 if (!CE) return false;
640 int64_t Value = CE->getValue();
641 return Value >= 1 && Value <= 32;
643 bool isImm8s4() const {
644 if (!isImm()) return false;
645 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
646 if (!CE) return false;
647 int64_t Value = CE->getValue();
648 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
650 bool isImm0_4() const {
651 if (!isImm()) return false;
652 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
653 if (!CE) return false;
654 int64_t Value = CE->getValue();
655 return Value >= 0 && Value < 5;
657 bool isImm0_1020s4() const {
658 if (!isImm()) return false;
659 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
660 if (!CE) return false;
661 int64_t Value = CE->getValue();
662 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
664 bool isImm0_508s4() const {
665 if (!isImm()) return false;
666 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
667 if (!CE) return false;
668 int64_t Value = CE->getValue();
669 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
671 bool isImm0_508s4Neg() const {
672 if (!isImm()) return false;
673 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
674 if (!CE) return false;
675 int64_t Value = -CE->getValue();
676 // explicitly exclude zero. we want that to use the normal 0_508 version.
677 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
679 bool isImm0_255() const {
680 if (!isImm()) return false;
681 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
682 if (!CE) return false;
683 int64_t Value = CE->getValue();
684 return Value >= 0 && Value < 256;
686 bool isImm0_4095() const {
687 if (!isImm()) return false;
688 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
689 if (!CE) return false;
690 int64_t Value = CE->getValue();
691 return Value >= 0 && Value < 4096;
693 bool isImm0_4095Neg() const {
694 if (!isImm()) return false;
695 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
696 if (!CE) return false;
697 int64_t Value = -CE->getValue();
698 return Value > 0 && Value < 4096;
700 bool isImm0_1() const {
701 if (!isImm()) return false;
702 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
703 if (!CE) return false;
704 int64_t Value = CE->getValue();
705 return Value >= 0 && Value < 2;
707 bool isImm0_3() const {
708 if (!isImm()) return false;
709 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
710 if (!CE) return false;
711 int64_t Value = CE->getValue();
712 return Value >= 0 && Value < 4;
714 bool isImm0_7() const {
715 if (!isImm()) return false;
716 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
717 if (!CE) return false;
718 int64_t Value = CE->getValue();
719 return Value >= 0 && Value < 8;
721 bool isImm0_15() const {
722 if (!isImm()) return false;
723 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
724 if (!CE) return false;
725 int64_t Value = CE->getValue();
726 return Value >= 0 && Value < 16;
728 bool isImm0_31() const {
729 if (!isImm()) return false;
730 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
731 if (!CE) return false;
732 int64_t Value = CE->getValue();
733 return Value >= 0 && Value < 32;
735 bool isImm0_63() const {
736 if (!isImm()) return false;
737 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
738 if (!CE) return false;
739 int64_t Value = CE->getValue();
740 return Value >= 0 && Value < 64;
742 bool isImm8() const {
743 if (!isImm()) return false;
744 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
745 if (!CE) return false;
746 int64_t Value = CE->getValue();
749 bool isImm16() const {
750 if (!isImm()) return false;
751 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
752 if (!CE) return false;
753 int64_t Value = CE->getValue();
756 bool isImm32() const {
757 if (!isImm()) return false;
758 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
759 if (!CE) return false;
760 int64_t Value = CE->getValue();
763 bool isShrImm8() const {
764 if (!isImm()) return false;
765 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
766 if (!CE) return false;
767 int64_t Value = CE->getValue();
768 return Value > 0 && Value <= 8;
770 bool isShrImm16() const {
771 if (!isImm()) return false;
772 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
773 if (!CE) return false;
774 int64_t Value = CE->getValue();
775 return Value > 0 && Value <= 16;
777 bool isShrImm32() const {
778 if (!isImm()) return false;
779 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
780 if (!CE) return false;
781 int64_t Value = CE->getValue();
782 return Value > 0 && Value <= 32;
784 bool isShrImm64() const {
785 if (!isImm()) return false;
786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
787 if (!CE) return false;
788 int64_t Value = CE->getValue();
789 return Value > 0 && Value <= 64;
791 bool isImm1_7() const {
792 if (!isImm()) return false;
793 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
794 if (!CE) return false;
795 int64_t Value = CE->getValue();
796 return Value > 0 && Value < 8;
798 bool isImm1_15() const {
799 if (!isImm()) return false;
800 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
801 if (!CE) return false;
802 int64_t Value = CE->getValue();
803 return Value > 0 && Value < 16;
805 bool isImm1_31() const {
806 if (!isImm()) return false;
807 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
808 if (!CE) return false;
809 int64_t Value = CE->getValue();
810 return Value > 0 && Value < 32;
812 bool isImm1_16() const {
813 if (!isImm()) return false;
814 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
815 if (!CE) return false;
816 int64_t Value = CE->getValue();
817 return Value > 0 && Value < 17;
819 bool isImm1_32() const {
820 if (!isImm()) return false;
821 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
822 if (!CE) return false;
823 int64_t Value = CE->getValue();
824 return Value > 0 && Value < 33;
826 bool isImm0_32() const {
827 if (!isImm()) return false;
828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
829 if (!CE) return false;
830 int64_t Value = CE->getValue();
831 return Value >= 0 && Value < 33;
833 bool isImm0_65535() const {
834 if (!isImm()) return false;
835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
836 if (!CE) return false;
837 int64_t Value = CE->getValue();
838 return Value >= 0 && Value < 65536;
840 bool isImm0_65535Expr() const {
841 if (!isImm()) return false;
842 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
843 // If it's not a constant expression, it'll generate a fixup and be
845 if (!CE) return true;
846 int64_t Value = CE->getValue();
847 return Value >= 0 && Value < 65536;
849 bool isImm24bit() const {
850 if (!isImm()) return false;
851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
852 if (!CE) return false;
853 int64_t Value = CE->getValue();
854 return Value >= 0 && Value <= 0xffffff;
856 bool isImmThumbSR() const {
857 if (!isImm()) return false;
858 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
859 if (!CE) return false;
860 int64_t Value = CE->getValue();
861 return Value > 0 && Value < 33;
863 bool isPKHLSLImm() const {
864 if (!isImm()) return false;
865 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
866 if (!CE) return false;
867 int64_t Value = CE->getValue();
868 return Value >= 0 && Value < 32;
870 bool isPKHASRImm() const {
871 if (!isImm()) return false;
872 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
873 if (!CE) return false;
874 int64_t Value = CE->getValue();
875 return Value > 0 && Value <= 32;
877 bool isAdrLabel() const {
878 // If we have an immediate that's not a constant, treat it as a label
879 // reference needing a fixup. If it is a constant, but it can't fit
880 // into shift immediate encoding, we reject it.
881 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
882 else return (isARMSOImm() || isARMSOImmNeg());
884 bool isARMSOImm() const {
885 if (!isImm()) return false;
886 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
887 if (!CE) return false;
888 int64_t Value = CE->getValue();
889 return ARM_AM::getSOImmVal(Value) != -1;
891 bool isARMSOImmNot() const {
892 if (!isImm()) return false;
893 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
894 if (!CE) return false;
895 int64_t Value = CE->getValue();
896 return ARM_AM::getSOImmVal(~Value) != -1;
898 bool isARMSOImmNeg() const {
899 if (!isImm()) return false;
900 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
901 if (!CE) return false;
902 int64_t Value = CE->getValue();
903 // Only use this when not representable as a plain so_imm.
904 return ARM_AM::getSOImmVal(Value) == -1 &&
905 ARM_AM::getSOImmVal(-Value) != -1;
907 bool isT2SOImm() const {
908 if (!isImm()) return false;
909 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
910 if (!CE) return false;
911 int64_t Value = CE->getValue();
912 return ARM_AM::getT2SOImmVal(Value) != -1;
914 bool isT2SOImmNot() const {
915 if (!isImm()) return false;
916 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
917 if (!CE) return false;
918 int64_t Value = CE->getValue();
919 return ARM_AM::getT2SOImmVal(~Value) != -1;
921 bool isT2SOImmNeg() const {
922 if (!isImm()) return false;
923 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
924 if (!CE) return false;
925 int64_t Value = CE->getValue();
926 // Only use this when not representable as a plain so_imm.
927 return ARM_AM::getT2SOImmVal(Value) == -1 &&
928 ARM_AM::getT2SOImmVal(-Value) != -1;
930 bool isSetEndImm() const {
931 if (!isImm()) return false;
932 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
933 if (!CE) return false;
934 int64_t Value = CE->getValue();
935 return Value == 1 || Value == 0;
937 bool isReg() const { return Kind == k_Register; }
938 bool isRegList() const { return Kind == k_RegisterList; }
939 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
940 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
941 bool isToken() const { return Kind == k_Token; }
942 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
943 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
944 bool isMem() const { return Kind == k_Memory; }
945 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
946 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
947 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
948 bool isRotImm() const { return Kind == k_RotateImmediate; }
949 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
950 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
951 bool isPostIdxReg() const {
952 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
954 bool isMemNoOffset(bool alignOK = false) const {
957 // No offset of any kind.
958 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
959 (alignOK || Memory.Alignment == 0);
961 bool isMemPCRelImm12() const {
962 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
964 // Base register must be PC.
965 if (Memory.BaseRegNum != ARM::PC)
967 // Immediate offset in range [-4095, 4095].
968 if (!Memory.OffsetImm) return true;
969 int64_t Val = Memory.OffsetImm->getValue();
970 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
972 bool isAlignedMemory() const {
973 return isMemNoOffset(true);
975 bool isAddrMode2() const {
976 if (!isMem() || Memory.Alignment != 0) return false;
977 // Check for register offset.
978 if (Memory.OffsetRegNum) return true;
979 // Immediate offset in range [-4095, 4095].
980 if (!Memory.OffsetImm) return true;
981 int64_t Val = Memory.OffsetImm->getValue();
982 return Val > -4096 && Val < 4096;
984 bool isAM2OffsetImm() const {
985 if (!isImm()) return false;
986 // Immediate offset in range [-4095, 4095].
987 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
988 if (!CE) return false;
989 int64_t Val = CE->getValue();
990 return Val > -4096 && Val < 4096;
992 bool isAddrMode3() const {
993 // If we have an immediate that's not a constant, treat it as a label
994 // reference needing a fixup. If it is a constant, it's something else
996 if (isImm() && !isa<MCConstantExpr>(getImm()))
998 if (!isMem() || Memory.Alignment != 0) return false;
999 // No shifts are legal for AM3.
1000 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1001 // Check for register offset.
1002 if (Memory.OffsetRegNum) return true;
1003 // Immediate offset in range [-255, 255].
1004 if (!Memory.OffsetImm) return true;
1005 int64_t Val = Memory.OffsetImm->getValue();
1006 // The #-0 offset is encoded as INT32_MIN, and we have to check
1008 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1010 bool isAM3Offset() const {
1011 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1013 if (Kind == k_PostIndexRegister)
1014 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1015 // Immediate offset in range [-255, 255].
1016 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1017 if (!CE) return false;
1018 int64_t Val = CE->getValue();
1019 // Special case, #-0 is INT32_MIN.
1020 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1022 bool isAddrMode5() const {
1023 // If we have an immediate that's not a constant, treat it as a label
1024 // reference needing a fixup. If it is a constant, it's something else
1025 // and we reject it.
1026 if (isImm() && !isa<MCConstantExpr>(getImm()))
1028 if (!isMem() || Memory.Alignment != 0) return false;
1029 // Check for register offset.
1030 if (Memory.OffsetRegNum) return false;
1031 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1032 if (!Memory.OffsetImm) return true;
1033 int64_t Val = Memory.OffsetImm->getValue();
1034 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1037 bool isMemTBB() const {
1038 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1039 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1043 bool isMemTBH() const {
1044 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1045 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1046 Memory.Alignment != 0 )
1050 bool isMemRegOffset() const {
1051 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1055 bool isT2MemRegOffset() const {
1056 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1057 Memory.Alignment != 0)
1059 // Only lsl #{0, 1, 2, 3} allowed.
1060 if (Memory.ShiftType == ARM_AM::no_shift)
1062 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1066 bool isMemThumbRR() const {
1067 // Thumb reg+reg addressing is simple. Just two registers, a base and
1068 // an offset. No shifts, negations or any other complicating factors.
1069 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1070 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1072 return isARMLowRegister(Memory.BaseRegNum) &&
1073 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1075 bool isMemThumbRIs4() const {
1076 if (!isMem() || Memory.OffsetRegNum != 0 ||
1077 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1079 // Immediate offset, multiple of 4 in range [0, 124].
1080 if (!Memory.OffsetImm) return true;
1081 int64_t Val = Memory.OffsetImm->getValue();
1082 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1084 bool isMemThumbRIs2() const {
1085 if (!isMem() || Memory.OffsetRegNum != 0 ||
1086 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1088 // Immediate offset, multiple of 4 in range [0, 62].
1089 if (!Memory.OffsetImm) return true;
1090 int64_t Val = Memory.OffsetImm->getValue();
1091 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1093 bool isMemThumbRIs1() const {
1094 if (!isMem() || Memory.OffsetRegNum != 0 ||
1095 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1097 // Immediate offset in range [0, 31].
1098 if (!Memory.OffsetImm) return true;
1099 int64_t Val = Memory.OffsetImm->getValue();
1100 return Val >= 0 && Val <= 31;
1102 bool isMemThumbSPI() const {
1103 if (!isMem() || Memory.OffsetRegNum != 0 ||
1104 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1106 // Immediate offset, multiple of 4 in range [0, 1020].
1107 if (!Memory.OffsetImm) return true;
1108 int64_t Val = Memory.OffsetImm->getValue();
1109 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1111 bool isMemImm8s4Offset() const {
1112 // If we have an immediate that's not a constant, treat it as a label
1113 // reference needing a fixup. If it is a constant, it's something else
1114 // and we reject it.
1115 if (isImm() && !isa<MCConstantExpr>(getImm()))
1117 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1119 // Immediate offset a multiple of 4 in range [-1020, 1020].
1120 if (!Memory.OffsetImm) return true;
1121 int64_t Val = Memory.OffsetImm->getValue();
1122 // Special case, #-0 is INT32_MIN.
1123 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1125 bool isMemImm0_1020s4Offset() const {
1126 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1128 // Immediate offset a multiple of 4 in range [0, 1020].
1129 if (!Memory.OffsetImm) return true;
1130 int64_t Val = Memory.OffsetImm->getValue();
1131 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1133 bool isMemImm8Offset() const {
1134 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1136 // Base reg of PC isn't allowed for these encodings.
1137 if (Memory.BaseRegNum == ARM::PC) return false;
1138 // Immediate offset in range [-255, 255].
1139 if (!Memory.OffsetImm) return true;
1140 int64_t Val = Memory.OffsetImm->getValue();
1141 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1143 bool isMemPosImm8Offset() const {
1144 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1146 // Immediate offset in range [0, 255].
1147 if (!Memory.OffsetImm) return true;
1148 int64_t Val = Memory.OffsetImm->getValue();
1149 return Val >= 0 && Val < 256;
1151 bool isMemNegImm8Offset() const {
1152 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1154 // Base reg of PC isn't allowed for these encodings.
1155 if (Memory.BaseRegNum == ARM::PC) return false;
1156 // Immediate offset in range [-255, -1].
1157 if (!Memory.OffsetImm) return false;
1158 int64_t Val = Memory.OffsetImm->getValue();
1159 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1161 bool isMemUImm12Offset() const {
1162 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1164 // Immediate offset in range [0, 4095].
1165 if (!Memory.OffsetImm) return true;
1166 int64_t Val = Memory.OffsetImm->getValue();
1167 return (Val >= 0 && Val < 4096);
1169 bool isMemImm12Offset() const {
1170 // If we have an immediate that's not a constant, treat it as a label
1171 // reference needing a fixup. If it is a constant, it's something else
1172 // and we reject it.
1173 if (isImm() && !isa<MCConstantExpr>(getImm()))
1176 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1178 // Immediate offset in range [-4095, 4095].
1179 if (!Memory.OffsetImm) return true;
1180 int64_t Val = Memory.OffsetImm->getValue();
1181 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1183 bool isPostIdxImm8() const {
1184 if (!isImm()) return false;
1185 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1186 if (!CE) return false;
1187 int64_t Val = CE->getValue();
1188 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1190 bool isPostIdxImm8s4() const {
1191 if (!isImm()) return false;
1192 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1193 if (!CE) return false;
1194 int64_t Val = CE->getValue();
1195 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1199 bool isMSRMask() const { return Kind == k_MSRMask; }
1200 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1203 bool isSingleSpacedVectorList() const {
1204 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1206 bool isDoubleSpacedVectorList() const {
1207 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1209 bool isVecListOneD() const {
1210 if (!isSingleSpacedVectorList()) return false;
1211 return VectorList.Count == 1;
1214 bool isVecListDPair() const {
1215 if (!isSingleSpacedVectorList()) return false;
1216 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1217 .contains(VectorList.RegNum));
1220 bool isVecListThreeD() const {
1221 if (!isSingleSpacedVectorList()) return false;
1222 return VectorList.Count == 3;
1225 bool isVecListFourD() const {
1226 if (!isSingleSpacedVectorList()) return false;
1227 return VectorList.Count == 4;
1230 bool isVecListDPairSpaced() const {
1231 if (isSingleSpacedVectorList()) return false;
1232 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1233 .contains(VectorList.RegNum));
1236 bool isVecListThreeQ() const {
1237 if (!isDoubleSpacedVectorList()) return false;
1238 return VectorList.Count == 3;
1241 bool isVecListFourQ() const {
1242 if (!isDoubleSpacedVectorList()) return false;
1243 return VectorList.Count == 4;
1246 bool isSingleSpacedVectorAllLanes() const {
1247 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1249 bool isDoubleSpacedVectorAllLanes() const {
1250 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1252 bool isVecListOneDAllLanes() const {
1253 if (!isSingleSpacedVectorAllLanes()) return false;
1254 return VectorList.Count == 1;
1257 bool isVecListDPairAllLanes() const {
1258 if (!isSingleSpacedVectorAllLanes()) return false;
1259 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1260 .contains(VectorList.RegNum));
1263 bool isVecListDPairSpacedAllLanes() const {
1264 if (!isDoubleSpacedVectorAllLanes()) return false;
1265 return VectorList.Count == 2;
1268 bool isVecListThreeDAllLanes() const {
1269 if (!isSingleSpacedVectorAllLanes()) return false;
1270 return VectorList.Count == 3;
1273 bool isVecListThreeQAllLanes() const {
1274 if (!isDoubleSpacedVectorAllLanes()) return false;
1275 return VectorList.Count == 3;
1278 bool isVecListFourDAllLanes() const {
1279 if (!isSingleSpacedVectorAllLanes()) return false;
1280 return VectorList.Count == 4;
1283 bool isVecListFourQAllLanes() const {
1284 if (!isDoubleSpacedVectorAllLanes()) return false;
1285 return VectorList.Count == 4;
1288 bool isSingleSpacedVectorIndexed() const {
1289 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1291 bool isDoubleSpacedVectorIndexed() const {
1292 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1294 bool isVecListOneDByteIndexed() const {
1295 if (!isSingleSpacedVectorIndexed()) return false;
1296 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1299 bool isVecListOneDHWordIndexed() const {
1300 if (!isSingleSpacedVectorIndexed()) return false;
1301 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1304 bool isVecListOneDWordIndexed() const {
1305 if (!isSingleSpacedVectorIndexed()) return false;
1306 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1309 bool isVecListTwoDByteIndexed() const {
1310 if (!isSingleSpacedVectorIndexed()) return false;
1311 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1314 bool isVecListTwoDHWordIndexed() const {
1315 if (!isSingleSpacedVectorIndexed()) return false;
1316 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1319 bool isVecListTwoQWordIndexed() const {
1320 if (!isDoubleSpacedVectorIndexed()) return false;
1321 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1324 bool isVecListTwoQHWordIndexed() const {
1325 if (!isDoubleSpacedVectorIndexed()) return false;
1326 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1329 bool isVecListTwoDWordIndexed() const {
1330 if (!isSingleSpacedVectorIndexed()) return false;
1331 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1334 bool isVecListThreeDByteIndexed() const {
1335 if (!isSingleSpacedVectorIndexed()) return false;
1336 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1339 bool isVecListThreeDHWordIndexed() const {
1340 if (!isSingleSpacedVectorIndexed()) return false;
1341 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1344 bool isVecListThreeQWordIndexed() const {
1345 if (!isDoubleSpacedVectorIndexed()) return false;
1346 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1349 bool isVecListThreeQHWordIndexed() const {
1350 if (!isDoubleSpacedVectorIndexed()) return false;
1351 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1354 bool isVecListThreeDWordIndexed() const {
1355 if (!isSingleSpacedVectorIndexed()) return false;
1356 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1359 bool isVecListFourDByteIndexed() const {
1360 if (!isSingleSpacedVectorIndexed()) return false;
1361 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1364 bool isVecListFourDHWordIndexed() const {
1365 if (!isSingleSpacedVectorIndexed()) return false;
1366 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1369 bool isVecListFourQWordIndexed() const {
1370 if (!isDoubleSpacedVectorIndexed()) return false;
1371 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1374 bool isVecListFourQHWordIndexed() const {
1375 if (!isDoubleSpacedVectorIndexed()) return false;
1376 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1379 bool isVecListFourDWordIndexed() const {
1380 if (!isSingleSpacedVectorIndexed()) return false;
1381 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1384 bool isVectorIndex8() const {
1385 if (Kind != k_VectorIndex) return false;
1386 return VectorIndex.Val < 8;
1388 bool isVectorIndex16() const {
1389 if (Kind != k_VectorIndex) return false;
1390 return VectorIndex.Val < 4;
1392 bool isVectorIndex32() const {
1393 if (Kind != k_VectorIndex) return false;
1394 return VectorIndex.Val < 2;
1397 bool isNEONi8splat() const {
1398 if (!isImm()) return false;
1399 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1400 // Must be a constant.
1401 if (!CE) return false;
1402 int64_t Value = CE->getValue();
1403 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1405 return Value >= 0 && Value < 256;
1408 bool isNEONi16splat() const {
1409 if (!isImm()) return false;
1410 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1411 // Must be a constant.
1412 if (!CE) return false;
1413 int64_t Value = CE->getValue();
1414 // i16 value in the range [0,255] or [0x0100, 0xff00]
1415 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1418 bool isNEONi32splat() const {
1419 if (!isImm()) return false;
1420 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1421 // Must be a constant.
1422 if (!CE) return false;
1423 int64_t Value = CE->getValue();
1424 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1425 return (Value >= 0 && Value < 256) ||
1426 (Value >= 0x0100 && Value <= 0xff00) ||
1427 (Value >= 0x010000 && Value <= 0xff0000) ||
1428 (Value >= 0x01000000 && Value <= 0xff000000);
1431 bool isNEONi32vmov() const {
1432 if (!isImm()) return false;
1433 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1434 // Must be a constant.
1435 if (!CE) return false;
1436 int64_t Value = CE->getValue();
1437 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1438 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1439 return (Value >= 0 && Value < 256) ||
1440 (Value >= 0x0100 && Value <= 0xff00) ||
1441 (Value >= 0x010000 && Value <= 0xff0000) ||
1442 (Value >= 0x01000000 && Value <= 0xff000000) ||
1443 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1444 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1446 bool isNEONi32vmovNeg() const {
1447 if (!isImm()) return false;
1448 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1449 // Must be a constant.
1450 if (!CE) return false;
1451 int64_t Value = ~CE->getValue();
1452 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1453 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1454 return (Value >= 0 && Value < 256) ||
1455 (Value >= 0x0100 && Value <= 0xff00) ||
1456 (Value >= 0x010000 && Value <= 0xff0000) ||
1457 (Value >= 0x01000000 && Value <= 0xff000000) ||
1458 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1459 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1462 bool isNEONi64splat() const {
1463 if (!isImm()) return false;
1464 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1465 // Must be a constant.
1466 if (!CE) return false;
1467 uint64_t Value = CE->getValue();
1468 // i64 value with each byte being either 0 or 0xff.
1469 for (unsigned i = 0; i < 8; ++i)
1470 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1474 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1475 // Add as immediates when possible. Null MCExpr = 0.
1477 Inst.addOperand(MCOperand::CreateImm(0));
1478 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1479 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1481 Inst.addOperand(MCOperand::CreateExpr(Expr));
1484 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1485 assert(N == 2 && "Invalid number of operands!");
1486 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1487 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1488 Inst.addOperand(MCOperand::CreateReg(RegNum));
1491 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1492 assert(N == 1 && "Invalid number of operands!");
1493 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1496 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1497 assert(N == 1 && "Invalid number of operands!");
1498 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1501 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1502 assert(N == 1 && "Invalid number of operands!");
1503 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1506 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1507 assert(N == 1 && "Invalid number of operands!");
1508 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1511 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1512 assert(N == 1 && "Invalid number of operands!");
1513 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1516 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1517 assert(N == 1 && "Invalid number of operands!");
1518 Inst.addOperand(MCOperand::CreateReg(getReg()));
1521 void addRegOperands(MCInst &Inst, unsigned N) const {
1522 assert(N == 1 && "Invalid number of operands!");
1523 Inst.addOperand(MCOperand::CreateReg(getReg()));
1526 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1527 assert(N == 3 && "Invalid number of operands!");
1528 assert(isRegShiftedReg() &&
1529 "addRegShiftedRegOperands() on non RegShiftedReg!");
1530 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1531 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1532 Inst.addOperand(MCOperand::CreateImm(
1533 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1536 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1537 assert(N == 2 && "Invalid number of operands!");
1538 assert(isRegShiftedImm() &&
1539 "addRegShiftedImmOperands() on non RegShiftedImm!");
1540 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1541 // Shift of #32 is encoded as 0 where permitted
1542 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1543 Inst.addOperand(MCOperand::CreateImm(
1544 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1547 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1548 assert(N == 1 && "Invalid number of operands!");
1549 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1553 void addRegListOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 const SmallVectorImpl<unsigned> &RegList = getRegList();
1556 for (SmallVectorImpl<unsigned>::const_iterator
1557 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1558 Inst.addOperand(MCOperand::CreateReg(*I));
1561 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1562 addRegListOperands(Inst, N);
1565 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1566 addRegListOperands(Inst, N);
1569 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1570 assert(N == 1 && "Invalid number of operands!");
1571 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1572 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1575 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1576 assert(N == 1 && "Invalid number of operands!");
1577 // Munge the lsb/width into a bitfield mask.
1578 unsigned lsb = Bitfield.LSB;
1579 unsigned width = Bitfield.Width;
1580 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1581 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1582 (32 - (lsb + width)));
1583 Inst.addOperand(MCOperand::CreateImm(Mask));
1586 void addImmOperands(MCInst &Inst, unsigned N) const {
1587 assert(N == 1 && "Invalid number of operands!");
1588 addExpr(Inst, getImm());
1591 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1592 assert(N == 1 && "Invalid number of operands!");
1593 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1594 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1597 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1598 assert(N == 1 && "Invalid number of operands!");
1599 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1600 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1603 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1604 assert(N == 1 && "Invalid number of operands!");
1605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1606 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1607 Inst.addOperand(MCOperand::CreateImm(Val));
1610 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1611 assert(N == 1 && "Invalid number of operands!");
1612 // FIXME: We really want to scale the value here, but the LDRD/STRD
1613 // instruction don't encode operands that way yet.
1614 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1615 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1618 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1619 assert(N == 1 && "Invalid number of operands!");
1620 // The immediate is scaled by four in the encoding and is stored
1621 // in the MCInst as such. Lop off the low two bits here.
1622 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1623 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1626 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1627 assert(N == 1 && "Invalid number of operands!");
1628 // The immediate is scaled by four in the encoding and is stored
1629 // in the MCInst as such. Lop off the low two bits here.
1630 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1631 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1634 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1635 assert(N == 1 && "Invalid number of operands!");
1636 // The immediate is scaled by four in the encoding and is stored
1637 // in the MCInst as such. Lop off the low two bits here.
1638 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1639 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1642 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1643 assert(N == 1 && "Invalid number of operands!");
1644 // The constant encodes as the immediate-1, and we store in the instruction
1645 // the bits as encoded, so subtract off one here.
1646 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1647 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1650 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1651 assert(N == 1 && "Invalid number of operands!");
1652 // The constant encodes as the immediate-1, and we store in the instruction
1653 // the bits as encoded, so subtract off one here.
1654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1655 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1658 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1659 assert(N == 1 && "Invalid number of operands!");
1660 // The constant encodes as the immediate, except for 32, which encodes as
1662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1663 unsigned Imm = CE->getValue();
1664 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1667 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1668 assert(N == 1 && "Invalid number of operands!");
1669 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1670 // the instruction as well.
1671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1672 int Val = CE->getValue();
1673 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1676 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1677 assert(N == 1 && "Invalid number of operands!");
1678 // The operand is actually a t2_so_imm, but we have its bitwise
1679 // negation in the assembly source, so twiddle it here.
1680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1681 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1684 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1685 assert(N == 1 && "Invalid number of operands!");
1686 // The operand is actually a t2_so_imm, but we have its
1687 // negation in the assembly source, so twiddle it here.
1688 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1689 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1692 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1693 assert(N == 1 && "Invalid number of operands!");
1694 // The operand is actually an imm0_4095, but we have its
1695 // negation in the assembly source, so twiddle it here.
1696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1697 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1700 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1701 assert(N == 1 && "Invalid number of operands!");
1702 // The operand is actually a so_imm, but we have its bitwise
1703 // negation in the assembly source, so twiddle it here.
1704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1705 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1708 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1709 assert(N == 1 && "Invalid number of operands!");
1710 // The operand is actually a so_imm, but we have its
1711 // negation in the assembly source, so twiddle it here.
1712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1713 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1716 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1717 assert(N == 1 && "Invalid number of operands!");
1718 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1721 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1722 assert(N == 1 && "Invalid number of operands!");
1723 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1726 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1727 assert(N == 1 && "Invalid number of operands!");
1728 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1731 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1732 assert(N == 1 && "Invalid number of operands!");
1733 int32_t Imm = Memory.OffsetImm->getValue();
1734 // FIXME: Handle #-0
1735 if (Imm == INT32_MIN) Imm = 0;
1736 Inst.addOperand(MCOperand::CreateImm(Imm));
1739 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1740 assert(N == 1 && "Invalid number of operands!");
1741 assert(isImm() && "Not an immediate!");
1743 // If we have an immediate that's not a constant, treat it as a label
1744 // reference needing a fixup.
1745 if (!isa<MCConstantExpr>(getImm())) {
1746 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1750 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1751 int Val = CE->getValue();
1752 Inst.addOperand(MCOperand::CreateImm(Val));
1755 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1756 assert(N == 2 && "Invalid number of operands!");
1757 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1758 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1761 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1762 assert(N == 3 && "Invalid number of operands!");
1763 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1764 if (!Memory.OffsetRegNum) {
1765 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1766 // Special case for #-0
1767 if (Val == INT32_MIN) Val = 0;
1768 if (Val < 0) Val = -Val;
1769 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1771 // For register offset, we encode the shift type and negation flag
1773 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1774 Memory.ShiftImm, Memory.ShiftType);
1776 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1777 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1778 Inst.addOperand(MCOperand::CreateImm(Val));
1781 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1782 assert(N == 2 && "Invalid number of operands!");
1783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1784 assert(CE && "non-constant AM2OffsetImm operand!");
1785 int32_t Val = CE->getValue();
1786 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1787 // Special case for #-0
1788 if (Val == INT32_MIN) Val = 0;
1789 if (Val < 0) Val = -Val;
1790 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1791 Inst.addOperand(MCOperand::CreateReg(0));
1792 Inst.addOperand(MCOperand::CreateImm(Val));
1795 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1796 assert(N == 3 && "Invalid number of operands!");
1797 // If we have an immediate that's not a constant, treat it as a label
1798 // reference needing a fixup. If it is a constant, it's something else
1799 // and we reject it.
1801 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1802 Inst.addOperand(MCOperand::CreateReg(0));
1803 Inst.addOperand(MCOperand::CreateImm(0));
1807 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1808 if (!Memory.OffsetRegNum) {
1809 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1810 // Special case for #-0
1811 if (Val == INT32_MIN) Val = 0;
1812 if (Val < 0) Val = -Val;
1813 Val = ARM_AM::getAM3Opc(AddSub, Val);
1815 // For register offset, we encode the shift type and negation flag
1817 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1819 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1820 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1821 Inst.addOperand(MCOperand::CreateImm(Val));
1824 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1825 assert(N == 2 && "Invalid number of operands!");
1826 if (Kind == k_PostIndexRegister) {
1828 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1829 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1830 Inst.addOperand(MCOperand::CreateImm(Val));
1835 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1836 int32_t Val = CE->getValue();
1837 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1838 // Special case for #-0
1839 if (Val == INT32_MIN) Val = 0;
1840 if (Val < 0) Val = -Val;
1841 Val = ARM_AM::getAM3Opc(AddSub, Val);
1842 Inst.addOperand(MCOperand::CreateReg(0));
1843 Inst.addOperand(MCOperand::CreateImm(Val));
1846 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1847 assert(N == 2 && "Invalid number of operands!");
1848 // If we have an immediate that's not a constant, treat it as a label
1849 // reference needing a fixup. If it is a constant, it's something else
1850 // and we reject it.
1852 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1853 Inst.addOperand(MCOperand::CreateImm(0));
1857 // The lower two bits are always zero and as such are not encoded.
1858 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1859 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1860 // Special case for #-0
1861 if (Val == INT32_MIN) Val = 0;
1862 if (Val < 0) Val = -Val;
1863 Val = ARM_AM::getAM5Opc(AddSub, Val);
1864 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1865 Inst.addOperand(MCOperand::CreateImm(Val));
1868 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1869 assert(N == 2 && "Invalid number of operands!");
1870 // If we have an immediate that's not a constant, treat it as a label
1871 // reference needing a fixup. If it is a constant, it's something else
1872 // and we reject it.
1874 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1875 Inst.addOperand(MCOperand::CreateImm(0));
1879 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1880 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1881 Inst.addOperand(MCOperand::CreateImm(Val));
1884 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1885 assert(N == 2 && "Invalid number of operands!");
1886 // The lower two bits are always zero and as such are not encoded.
1887 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1888 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1889 Inst.addOperand(MCOperand::CreateImm(Val));
1892 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1893 assert(N == 2 && "Invalid number of operands!");
1894 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1895 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1896 Inst.addOperand(MCOperand::CreateImm(Val));
1899 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1900 addMemImm8OffsetOperands(Inst, N);
1903 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1904 addMemImm8OffsetOperands(Inst, N);
1907 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1908 assert(N == 2 && "Invalid number of operands!");
1909 // If this is an immediate, it's a label reference.
1911 addExpr(Inst, getImm());
1912 Inst.addOperand(MCOperand::CreateImm(0));
1916 // Otherwise, it's a normal memory reg+offset.
1917 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1918 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1919 Inst.addOperand(MCOperand::CreateImm(Val));
1922 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1923 assert(N == 2 && "Invalid number of operands!");
1924 // If this is an immediate, it's a label reference.
1926 addExpr(Inst, getImm());
1927 Inst.addOperand(MCOperand::CreateImm(0));
1931 // Otherwise, it's a normal memory reg+offset.
1932 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1933 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1934 Inst.addOperand(MCOperand::CreateImm(Val));
1937 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1938 assert(N == 2 && "Invalid number of operands!");
1939 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1940 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1943 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1944 assert(N == 2 && "Invalid number of operands!");
1945 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1946 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1949 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1950 assert(N == 3 && "Invalid number of operands!");
1952 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1953 Memory.ShiftImm, Memory.ShiftType);
1954 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1955 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1956 Inst.addOperand(MCOperand::CreateImm(Val));
1959 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1960 assert(N == 3 && "Invalid number of operands!");
1961 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1962 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1963 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
1966 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1967 assert(N == 2 && "Invalid number of operands!");
1968 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1969 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1972 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1973 assert(N == 2 && "Invalid number of operands!");
1974 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1975 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1976 Inst.addOperand(MCOperand::CreateImm(Val));
1979 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1980 assert(N == 2 && "Invalid number of operands!");
1981 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1982 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1983 Inst.addOperand(MCOperand::CreateImm(Val));
1986 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1987 assert(N == 2 && "Invalid number of operands!");
1988 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1989 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1990 Inst.addOperand(MCOperand::CreateImm(Val));
1993 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1994 assert(N == 2 && "Invalid number of operands!");
1995 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1996 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1997 Inst.addOperand(MCOperand::CreateImm(Val));
2000 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2001 assert(N == 1 && "Invalid number of operands!");
2002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2003 assert(CE && "non-constant post-idx-imm8 operand!");
2004 int Imm = CE->getValue();
2005 bool isAdd = Imm >= 0;
2006 if (Imm == INT32_MIN) Imm = 0;
2007 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2008 Inst.addOperand(MCOperand::CreateImm(Imm));
2011 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2012 assert(N == 1 && "Invalid number of operands!");
2013 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2014 assert(CE && "non-constant post-idx-imm8s4 operand!");
2015 int Imm = CE->getValue();
2016 bool isAdd = Imm >= 0;
2017 if (Imm == INT32_MIN) Imm = 0;
2018 // Immediate is scaled by 4.
2019 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2020 Inst.addOperand(MCOperand::CreateImm(Imm));
2023 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2024 assert(N == 2 && "Invalid number of operands!");
2025 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2026 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2029 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2030 assert(N == 2 && "Invalid number of operands!");
2031 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2032 // The sign, shift type, and shift amount are encoded in a single operand
2033 // using the AM2 encoding helpers.
2034 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2035 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2036 PostIdxReg.ShiftTy);
2037 Inst.addOperand(MCOperand::CreateImm(Imm));
2040 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2041 assert(N == 1 && "Invalid number of operands!");
2042 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2045 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2046 assert(N == 1 && "Invalid number of operands!");
2047 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2050 void addVecListOperands(MCInst &Inst, unsigned N) const {
2051 assert(N == 1 && "Invalid number of operands!");
2052 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2055 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2056 assert(N == 2 && "Invalid number of operands!");
2057 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2058 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2061 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2062 assert(N == 1 && "Invalid number of operands!");
2063 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2066 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2067 assert(N == 1 && "Invalid number of operands!");
2068 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2071 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2072 assert(N == 1 && "Invalid number of operands!");
2073 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2076 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2077 assert(N == 1 && "Invalid number of operands!");
2078 // The immediate encodes the type of constant as well as the value.
2079 // Mask in that this is an i8 splat.
2080 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2081 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2084 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2085 assert(N == 1 && "Invalid number of operands!");
2086 // The immediate encodes the type of constant as well as the value.
2087 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2088 unsigned Value = CE->getValue();
2090 Value = (Value >> 8) | 0xa00;
2093 Inst.addOperand(MCOperand::CreateImm(Value));
2096 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2097 assert(N == 1 && "Invalid number of operands!");
2098 // The immediate encodes the type of constant as well as the value.
2099 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2100 unsigned Value = CE->getValue();
2101 if (Value >= 256 && Value <= 0xff00)
2102 Value = (Value >> 8) | 0x200;
2103 else if (Value > 0xffff && Value <= 0xff0000)
2104 Value = (Value >> 16) | 0x400;
2105 else if (Value > 0xffffff)
2106 Value = (Value >> 24) | 0x600;
2107 Inst.addOperand(MCOperand::CreateImm(Value));
2110 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2111 assert(N == 1 && "Invalid number of operands!");
2112 // The immediate encodes the type of constant as well as the value.
2113 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2114 unsigned Value = CE->getValue();
2115 if (Value >= 256 && Value <= 0xffff)
2116 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2117 else if (Value > 0xffff && Value <= 0xffffff)
2118 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2119 else if (Value > 0xffffff)
2120 Value = (Value >> 24) | 0x600;
2121 Inst.addOperand(MCOperand::CreateImm(Value));
2124 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2125 assert(N == 1 && "Invalid number of operands!");
2126 // The immediate encodes the type of constant as well as the value.
2127 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2128 unsigned Value = ~CE->getValue();
2129 if (Value >= 256 && Value <= 0xffff)
2130 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2131 else if (Value > 0xffff && Value <= 0xffffff)
2132 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2133 else if (Value > 0xffffff)
2134 Value = (Value >> 24) | 0x600;
2135 Inst.addOperand(MCOperand::CreateImm(Value));
2138 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2139 assert(N == 1 && "Invalid number of operands!");
2140 // The immediate encodes the type of constant as well as the value.
2141 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2142 uint64_t Value = CE->getValue();
2144 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2145 Imm |= (Value & 1) << i;
2147 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2150 virtual void print(raw_ostream &OS) const;
2152 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2153 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2154 Op->ITMask.Mask = Mask;
2160 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2161 ARMOperand *Op = new ARMOperand(k_CondCode);
2168 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2169 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2170 Op->Cop.Val = CopVal;
2176 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2177 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2178 Op->Cop.Val = CopVal;
2184 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2185 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2192 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2193 ARMOperand *Op = new ARMOperand(k_CCOut);
2194 Op->Reg.RegNum = RegNum;
2200 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2201 ARMOperand *Op = new ARMOperand(k_Token);
2202 Op->Tok.Data = Str.data();
2203 Op->Tok.Length = Str.size();
2209 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2210 ARMOperand *Op = new ARMOperand(k_Register);
2211 Op->Reg.RegNum = RegNum;
2217 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2222 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2223 Op->RegShiftedReg.ShiftTy = ShTy;
2224 Op->RegShiftedReg.SrcReg = SrcReg;
2225 Op->RegShiftedReg.ShiftReg = ShiftReg;
2226 Op->RegShiftedReg.ShiftImm = ShiftImm;
2232 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2236 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2237 Op->RegShiftedImm.ShiftTy = ShTy;
2238 Op->RegShiftedImm.SrcReg = SrcReg;
2239 Op->RegShiftedImm.ShiftImm = ShiftImm;
2245 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2247 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2248 Op->ShifterImm.isASR = isASR;
2249 Op->ShifterImm.Imm = Imm;
2255 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2256 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2257 Op->RotImm.Imm = Imm;
2263 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2265 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2266 Op->Bitfield.LSB = LSB;
2267 Op->Bitfield.Width = Width;
2274 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
2275 SMLoc StartLoc, SMLoc EndLoc) {
2276 KindTy Kind = k_RegisterList;
2278 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
2279 Kind = k_DPRRegisterList;
2280 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2281 contains(Regs.front().first))
2282 Kind = k_SPRRegisterList;
2284 ARMOperand *Op = new ARMOperand(Kind);
2285 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
2286 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2287 Op->Registers.push_back(I->first);
2288 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
2289 Op->StartLoc = StartLoc;
2290 Op->EndLoc = EndLoc;
2294 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2295 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2296 ARMOperand *Op = new ARMOperand(k_VectorList);
2297 Op->VectorList.RegNum = RegNum;
2298 Op->VectorList.Count = Count;
2299 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2305 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2306 bool isDoubleSpaced,
2308 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2309 Op->VectorList.RegNum = RegNum;
2310 Op->VectorList.Count = Count;
2311 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2317 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2319 bool isDoubleSpaced,
2321 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2322 Op->VectorList.RegNum = RegNum;
2323 Op->VectorList.Count = Count;
2324 Op->VectorList.LaneIndex = Index;
2325 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2331 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2333 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2334 Op->VectorIndex.Val = Idx;
2340 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2341 ARMOperand *Op = new ARMOperand(k_Immediate);
2348 static ARMOperand *CreateMem(unsigned BaseRegNum,
2349 const MCConstantExpr *OffsetImm,
2350 unsigned OffsetRegNum,
2351 ARM_AM::ShiftOpc ShiftType,
2356 ARMOperand *Op = new ARMOperand(k_Memory);
2357 Op->Memory.BaseRegNum = BaseRegNum;
2358 Op->Memory.OffsetImm = OffsetImm;
2359 Op->Memory.OffsetRegNum = OffsetRegNum;
2360 Op->Memory.ShiftType = ShiftType;
2361 Op->Memory.ShiftImm = ShiftImm;
2362 Op->Memory.Alignment = Alignment;
2363 Op->Memory.isNegative = isNegative;
2369 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2370 ARM_AM::ShiftOpc ShiftTy,
2373 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2374 Op->PostIdxReg.RegNum = RegNum;
2375 Op->PostIdxReg.isAdd = isAdd;
2376 Op->PostIdxReg.ShiftTy = ShiftTy;
2377 Op->PostIdxReg.ShiftImm = ShiftImm;
2383 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2384 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2385 Op->MBOpt.Val = Opt;
2391 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2393 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2394 Op->ISBOpt.Val = Opt;
2400 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2401 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2402 Op->IFlags.Val = IFlags;
2408 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2409 ARMOperand *Op = new ARMOperand(k_MSRMask);
2410 Op->MMask.Val = MMask;
2417 } // end anonymous namespace.
2419 void ARMOperand::print(raw_ostream &OS) const {
2422 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2425 OS << "<ccout " << getReg() << ">";
2427 case k_ITCondMask: {
2428 static const char *const MaskStr[] = {
2429 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2430 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2432 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2433 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2437 OS << "<coprocessor number: " << getCoproc() << ">";
2440 OS << "<coprocessor register: " << getCoproc() << ">";
2442 case k_CoprocOption:
2443 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2446 OS << "<mask: " << getMSRMask() << ">";
2449 getImm()->print(OS);
2451 case k_MemBarrierOpt:
2452 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2454 case k_InstSyncBarrierOpt:
2455 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2459 << " base:" << Memory.BaseRegNum;
2462 case k_PostIndexRegister:
2463 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2464 << PostIdxReg.RegNum;
2465 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2466 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2467 << PostIdxReg.ShiftImm;
2470 case k_ProcIFlags: {
2471 OS << "<ARM_PROC::";
2472 unsigned IFlags = getProcIFlags();
2473 for (int i=2; i >= 0; --i)
2474 if (IFlags & (1 << i))
2475 OS << ARM_PROC::IFlagsToString(1 << i);
2480 OS << "<register " << getReg() << ">";
2482 case k_ShifterImmediate:
2483 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2484 << " #" << ShifterImm.Imm << ">";
2486 case k_ShiftedRegister:
2487 OS << "<so_reg_reg "
2488 << RegShiftedReg.SrcReg << " "
2489 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2490 << " " << RegShiftedReg.ShiftReg << ">";
2492 case k_ShiftedImmediate:
2493 OS << "<so_reg_imm "
2494 << RegShiftedImm.SrcReg << " "
2495 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2496 << " #" << RegShiftedImm.ShiftImm << ">";
2498 case k_RotateImmediate:
2499 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2501 case k_BitfieldDescriptor:
2502 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2503 << ", width: " << Bitfield.Width << ">";
2505 case k_RegisterList:
2506 case k_DPRRegisterList:
2507 case k_SPRRegisterList: {
2508 OS << "<register_list ";
2510 const SmallVectorImpl<unsigned> &RegList = getRegList();
2511 for (SmallVectorImpl<unsigned>::const_iterator
2512 I = RegList.begin(), E = RegList.end(); I != E; ) {
2514 if (++I < E) OS << ", ";
2521 OS << "<vector_list " << VectorList.Count << " * "
2522 << VectorList.RegNum << ">";
2524 case k_VectorListAllLanes:
2525 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2526 << VectorList.RegNum << ">";
2528 case k_VectorListIndexed:
2529 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2530 << VectorList.Count << " * " << VectorList.RegNum << ">";
2533 OS << "'" << getToken() << "'";
2536 OS << "<vectorindex " << getVectorIndex() << ">";
2541 /// @name Auto-generated Match Functions
2544 static unsigned MatchRegisterName(StringRef Name);
2548 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2549 SMLoc &StartLoc, SMLoc &EndLoc) {
2550 StartLoc = Parser.getTok().getLoc();
2551 EndLoc = Parser.getTok().getEndLoc();
2552 RegNo = tryParseRegister();
2554 return (RegNo == (unsigned)-1);
2557 /// Try to parse a register name. The token must be an Identifier when called,
2558 /// and if it is a register name the token is eaten and the register number is
2559 /// returned. Otherwise return -1.
2561 int ARMAsmParser::tryParseRegister() {
2562 const AsmToken &Tok = Parser.getTok();
2563 if (Tok.isNot(AsmToken::Identifier)) return -1;
2565 std::string lowerCase = Tok.getString().lower();
2566 unsigned RegNum = MatchRegisterName(lowerCase);
2568 RegNum = StringSwitch<unsigned>(lowerCase)
2569 .Case("r13", ARM::SP)
2570 .Case("r14", ARM::LR)
2571 .Case("r15", ARM::PC)
2572 .Case("ip", ARM::R12)
2573 // Additional register name aliases for 'gas' compatibility.
2574 .Case("a1", ARM::R0)
2575 .Case("a2", ARM::R1)
2576 .Case("a3", ARM::R2)
2577 .Case("a4", ARM::R3)
2578 .Case("v1", ARM::R4)
2579 .Case("v2", ARM::R5)
2580 .Case("v3", ARM::R6)
2581 .Case("v4", ARM::R7)
2582 .Case("v5", ARM::R8)
2583 .Case("v6", ARM::R9)
2584 .Case("v7", ARM::R10)
2585 .Case("v8", ARM::R11)
2586 .Case("sb", ARM::R9)
2587 .Case("sl", ARM::R10)
2588 .Case("fp", ARM::R11)
2592 // Check for aliases registered via .req. Canonicalize to lower case.
2593 // That's more consistent since register names are case insensitive, and
2594 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2595 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2596 // If no match, return failure.
2597 if (Entry == RegisterReqs.end())
2599 Parser.Lex(); // Eat identifier token.
2600 return Entry->getValue();
2603 Parser.Lex(); // Eat identifier token.
2608 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2609 // If a recoverable error occurs, return 1. If an irrecoverable error
2610 // occurs, return -1. An irrecoverable error is one where tokens have been
2611 // consumed in the process of trying to parse the shifter (i.e., when it is
2612 // indeed a shifter operand, but malformed).
2613 int ARMAsmParser::tryParseShiftRegister(
2614 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2615 SMLoc S = Parser.getTok().getLoc();
2616 const AsmToken &Tok = Parser.getTok();
2617 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2619 std::string lowerCase = Tok.getString().lower();
2620 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2621 .Case("asl", ARM_AM::lsl)
2622 .Case("lsl", ARM_AM::lsl)
2623 .Case("lsr", ARM_AM::lsr)
2624 .Case("asr", ARM_AM::asr)
2625 .Case("ror", ARM_AM::ror)
2626 .Case("rrx", ARM_AM::rrx)
2627 .Default(ARM_AM::no_shift);
2629 if (ShiftTy == ARM_AM::no_shift)
2632 Parser.Lex(); // Eat the operator.
2634 // The source register for the shift has already been added to the
2635 // operand list, so we need to pop it off and combine it into the shifted
2636 // register operand instead.
2637 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2638 if (!PrevOp->isReg())
2639 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2640 int SrcReg = PrevOp->getReg();
2645 if (ShiftTy == ARM_AM::rrx) {
2646 // RRX Doesn't have an explicit shift amount. The encoder expects
2647 // the shift register to be the same as the source register. Seems odd,
2651 // Figure out if this is shifted by a constant or a register (for non-RRX).
2652 if (Parser.getTok().is(AsmToken::Hash) ||
2653 Parser.getTok().is(AsmToken::Dollar)) {
2654 Parser.Lex(); // Eat hash.
2655 SMLoc ImmLoc = Parser.getTok().getLoc();
2656 const MCExpr *ShiftExpr = 0;
2657 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2658 Error(ImmLoc, "invalid immediate shift value");
2661 // The expression must be evaluatable as an immediate.
2662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2664 Error(ImmLoc, "invalid immediate shift value");
2667 // Range check the immediate.
2668 // lsl, ror: 0 <= imm <= 31
2669 // lsr, asr: 0 <= imm <= 32
2670 Imm = CE->getValue();
2672 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2673 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2674 Error(ImmLoc, "immediate shift value out of range");
2677 // shift by zero is a nop. Always send it through as lsl.
2678 // ('as' compatibility)
2680 ShiftTy = ARM_AM::lsl;
2681 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2682 SMLoc L = Parser.getTok().getLoc();
2683 EndLoc = Parser.getTok().getEndLoc();
2684 ShiftReg = tryParseRegister();
2685 if (ShiftReg == -1) {
2686 Error (L, "expected immediate or register in shift operand");
2690 Error (Parser.getTok().getLoc(),
2691 "expected immediate or register in shift operand");
2696 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2697 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2701 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2708 /// Try to parse a register name. The token must be an Identifier when called.
2709 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2710 /// if there is a "writeback". 'true' if it's not a register.
2712 /// TODO this is likely to change to allow different register types and or to
2713 /// parse for a specific register type.
2715 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2716 const AsmToken &RegTok = Parser.getTok();
2717 int RegNo = tryParseRegister();
2721 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2722 RegTok.getEndLoc()));
2724 const AsmToken &ExclaimTok = Parser.getTok();
2725 if (ExclaimTok.is(AsmToken::Exclaim)) {
2726 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2727 ExclaimTok.getLoc()));
2728 Parser.Lex(); // Eat exclaim token
2732 // Also check for an index operand. This is only legal for vector registers,
2733 // but that'll get caught OK in operand matching, so we don't need to
2734 // explicitly filter everything else out here.
2735 if (Parser.getTok().is(AsmToken::LBrac)) {
2736 SMLoc SIdx = Parser.getTok().getLoc();
2737 Parser.Lex(); // Eat left bracket token.
2739 const MCExpr *ImmVal;
2740 if (getParser().parseExpression(ImmVal))
2742 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2744 return TokError("immediate value expected for vector index");
2746 if (Parser.getTok().isNot(AsmToken::RBrac))
2747 return Error(Parser.getTok().getLoc(), "']' expected");
2749 SMLoc E = Parser.getTok().getEndLoc();
2750 Parser.Lex(); // Eat right bracket token.
2752 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2760 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2761 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2763 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2764 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2766 switch (Name.size()) {
2769 if (Name[0] != CoprocOp)
2785 if (Name[0] != CoprocOp || Name[1] != '1')
2789 case '0': return 10;
2790 case '1': return 11;
2791 case '2': return 12;
2792 case '3': return 13;
2793 case '4': return 14;
2794 case '5': return 15;
2799 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2800 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2801 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2802 SMLoc S = Parser.getTok().getLoc();
2803 const AsmToken &Tok = Parser.getTok();
2804 if (!Tok.is(AsmToken::Identifier))
2805 return MatchOperand_NoMatch;
2806 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2807 .Case("eq", ARMCC::EQ)
2808 .Case("ne", ARMCC::NE)
2809 .Case("hs", ARMCC::HS)
2810 .Case("cs", ARMCC::HS)
2811 .Case("lo", ARMCC::LO)
2812 .Case("cc", ARMCC::LO)
2813 .Case("mi", ARMCC::MI)
2814 .Case("pl", ARMCC::PL)
2815 .Case("vs", ARMCC::VS)
2816 .Case("vc", ARMCC::VC)
2817 .Case("hi", ARMCC::HI)
2818 .Case("ls", ARMCC::LS)
2819 .Case("ge", ARMCC::GE)
2820 .Case("lt", ARMCC::LT)
2821 .Case("gt", ARMCC::GT)
2822 .Case("le", ARMCC::LE)
2823 .Case("al", ARMCC::AL)
2826 return MatchOperand_NoMatch;
2827 Parser.Lex(); // Eat the token.
2829 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2831 return MatchOperand_Success;
2834 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2835 /// token must be an Identifier when called, and if it is a coprocessor
2836 /// number, the token is eaten and the operand is added to the operand list.
2837 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2838 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2839 SMLoc S = Parser.getTok().getLoc();
2840 const AsmToken &Tok = Parser.getTok();
2841 if (Tok.isNot(AsmToken::Identifier))
2842 return MatchOperand_NoMatch;
2844 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2846 return MatchOperand_NoMatch;
2848 Parser.Lex(); // Eat identifier token.
2849 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2850 return MatchOperand_Success;
2853 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2854 /// token must be an Identifier when called, and if it is a coprocessor
2855 /// number, the token is eaten and the operand is added to the operand list.
2856 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2857 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2858 SMLoc S = Parser.getTok().getLoc();
2859 const AsmToken &Tok = Parser.getTok();
2860 if (Tok.isNot(AsmToken::Identifier))
2861 return MatchOperand_NoMatch;
2863 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2865 return MatchOperand_NoMatch;
2867 Parser.Lex(); // Eat identifier token.
2868 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2869 return MatchOperand_Success;
2872 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2873 /// coproc_option : '{' imm0_255 '}'
2874 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2875 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2876 SMLoc S = Parser.getTok().getLoc();
2878 // If this isn't a '{', this isn't a coprocessor immediate operand.
2879 if (Parser.getTok().isNot(AsmToken::LCurly))
2880 return MatchOperand_NoMatch;
2881 Parser.Lex(); // Eat the '{'
2884 SMLoc Loc = Parser.getTok().getLoc();
2885 if (getParser().parseExpression(Expr)) {
2886 Error(Loc, "illegal expression");
2887 return MatchOperand_ParseFail;
2889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2890 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2891 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2892 return MatchOperand_ParseFail;
2894 int Val = CE->getValue();
2896 // Check for and consume the closing '}'
2897 if (Parser.getTok().isNot(AsmToken::RCurly))
2898 return MatchOperand_ParseFail;
2899 SMLoc E = Parser.getTok().getEndLoc();
2900 Parser.Lex(); // Eat the '}'
2902 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2903 return MatchOperand_Success;
2906 // For register list parsing, we need to map from raw GPR register numbering
2907 // to the enumeration values. The enumeration values aren't sorted by
2908 // register number due to our using "sp", "lr" and "pc" as canonical names.
2909 static unsigned getNextRegister(unsigned Reg) {
2910 // If this is a GPR, we need to do it manually, otherwise we can rely
2911 // on the sort ordering of the enumeration since the other reg-classes
2913 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2916 default: llvm_unreachable("Invalid GPR number!");
2917 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2918 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2919 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2920 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2921 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2922 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2923 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2924 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2928 // Return the low-subreg of a given Q register.
2929 static unsigned getDRegFromQReg(unsigned QReg) {
2931 default: llvm_unreachable("expected a Q register!");
2932 case ARM::Q0: return ARM::D0;
2933 case ARM::Q1: return ARM::D2;
2934 case ARM::Q2: return ARM::D4;
2935 case ARM::Q3: return ARM::D6;
2936 case ARM::Q4: return ARM::D8;
2937 case ARM::Q5: return ARM::D10;
2938 case ARM::Q6: return ARM::D12;
2939 case ARM::Q7: return ARM::D14;
2940 case ARM::Q8: return ARM::D16;
2941 case ARM::Q9: return ARM::D18;
2942 case ARM::Q10: return ARM::D20;
2943 case ARM::Q11: return ARM::D22;
2944 case ARM::Q12: return ARM::D24;
2945 case ARM::Q13: return ARM::D26;
2946 case ARM::Q14: return ARM::D28;
2947 case ARM::Q15: return ARM::D30;
2951 /// Parse a register list.
2953 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2954 assert(Parser.getTok().is(AsmToken::LCurly) &&
2955 "Token is not a Left Curly Brace");
2956 SMLoc S = Parser.getTok().getLoc();
2957 Parser.Lex(); // Eat '{' token.
2958 SMLoc RegLoc = Parser.getTok().getLoc();
2960 // Check the first register in the list to see what register class
2961 // this is a list of.
2962 int Reg = tryParseRegister();
2964 return Error(RegLoc, "register expected");
2966 // The reglist instructions have at most 16 registers, so reserve
2967 // space for that many.
2968 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2970 // Allow Q regs and just interpret them as the two D sub-registers.
2971 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2972 Reg = getDRegFromQReg(Reg);
2973 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2976 const MCRegisterClass *RC;
2977 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2978 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2979 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2980 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2981 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2982 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2984 return Error(RegLoc, "invalid register in register list");
2986 // Store the register.
2987 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2989 // This starts immediately after the first register token in the list,
2990 // so we can see either a comma or a minus (range separator) as a legal
2992 while (Parser.getTok().is(AsmToken::Comma) ||
2993 Parser.getTok().is(AsmToken::Minus)) {
2994 if (Parser.getTok().is(AsmToken::Minus)) {
2995 Parser.Lex(); // Eat the minus.
2996 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
2997 int EndReg = tryParseRegister();
2999 return Error(AfterMinusLoc, "register expected");
3000 // Allow Q regs and just interpret them as the two D sub-registers.
3001 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3002 EndReg = getDRegFromQReg(EndReg) + 1;
3003 // If the register is the same as the start reg, there's nothing
3007 // The register must be in the same register class as the first.
3008 if (!RC->contains(EndReg))
3009 return Error(AfterMinusLoc, "invalid register in register list");
3010 // Ranges must go from low to high.
3011 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3012 return Error(AfterMinusLoc, "bad range in register list");
3014 // Add all the registers in the range to the register list.
3015 while (Reg != EndReg) {
3016 Reg = getNextRegister(Reg);
3017 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
3021 Parser.Lex(); // Eat the comma.
3022 RegLoc = Parser.getTok().getLoc();
3024 const AsmToken RegTok = Parser.getTok();
3025 Reg = tryParseRegister();
3027 return Error(RegLoc, "register expected");
3028 // Allow Q regs and just interpret them as the two D sub-registers.
3029 bool isQReg = false;
3030 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3031 Reg = getDRegFromQReg(Reg);
3034 // The register must be in the same register class as the first.
3035 if (!RC->contains(Reg))
3036 return Error(RegLoc, "invalid register in register list");
3037 // List must be monotonically increasing.
3038 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3039 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3040 Warning(RegLoc, "register list not in ascending order");
3042 return Error(RegLoc, "register list not in ascending order");
3044 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3045 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3046 ") in register list");
3049 // VFP register lists must also be contiguous.
3050 // It's OK to use the enumeration values directly here rather, as the
3051 // VFP register classes have the enum sorted properly.
3052 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3054 return Error(RegLoc, "non-contiguous register range");
3055 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
3057 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
3060 if (Parser.getTok().isNot(AsmToken::RCurly))
3061 return Error(Parser.getTok().getLoc(), "'}' expected");
3062 SMLoc E = Parser.getTok().getEndLoc();
3063 Parser.Lex(); // Eat '}' token.
3065 // Push the register list operand.
3066 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3068 // The ARM system instruction variants for LDM/STM have a '^' token here.
3069 if (Parser.getTok().is(AsmToken::Caret)) {
3070 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3071 Parser.Lex(); // Eat '^' token.
3077 // Helper function to parse the lane index for vector lists.
3078 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3079 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3080 Index = 0; // Always return a defined index value.
3081 if (Parser.getTok().is(AsmToken::LBrac)) {
3082 Parser.Lex(); // Eat the '['.
3083 if (Parser.getTok().is(AsmToken::RBrac)) {
3084 // "Dn[]" is the 'all lanes' syntax.
3085 LaneKind = AllLanes;
3086 EndLoc = Parser.getTok().getEndLoc();
3087 Parser.Lex(); // Eat the ']'.
3088 return MatchOperand_Success;
3091 // There's an optional '#' token here. Normally there wouldn't be, but
3092 // inline assemble puts one in, and it's friendly to accept that.
3093 if (Parser.getTok().is(AsmToken::Hash))
3094 Parser.Lex(); // Eat the '#'
3096 const MCExpr *LaneIndex;
3097 SMLoc Loc = Parser.getTok().getLoc();
3098 if (getParser().parseExpression(LaneIndex)) {
3099 Error(Loc, "illegal expression");
3100 return MatchOperand_ParseFail;
3102 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3104 Error(Loc, "lane index must be empty or an integer");
3105 return MatchOperand_ParseFail;
3107 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3108 Error(Parser.getTok().getLoc(), "']' expected");
3109 return MatchOperand_ParseFail;
3111 EndLoc = Parser.getTok().getEndLoc();
3112 Parser.Lex(); // Eat the ']'.
3113 int64_t Val = CE->getValue();
3115 // FIXME: Make this range check context sensitive for .8, .16, .32.
3116 if (Val < 0 || Val > 7) {
3117 Error(Parser.getTok().getLoc(), "lane index out of range");
3118 return MatchOperand_ParseFail;
3121 LaneKind = IndexedLane;
3122 return MatchOperand_Success;
3125 return MatchOperand_Success;
3128 // parse a vector register list
3129 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3130 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3131 VectorLaneTy LaneKind;
3133 SMLoc S = Parser.getTok().getLoc();
3134 // As an extension (to match gas), support a plain D register or Q register
3135 // (without encosing curly braces) as a single or double entry list,
3137 if (Parser.getTok().is(AsmToken::Identifier)) {
3138 SMLoc E = Parser.getTok().getEndLoc();
3139 int Reg = tryParseRegister();
3141 return MatchOperand_NoMatch;
3142 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3143 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3144 if (Res != MatchOperand_Success)
3148 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3151 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3155 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3160 return MatchOperand_Success;
3162 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3163 Reg = getDRegFromQReg(Reg);
3164 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3165 if (Res != MatchOperand_Success)
3169 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3170 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3171 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3174 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3175 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3176 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3180 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3185 return MatchOperand_Success;
3187 Error(S, "vector register expected");
3188 return MatchOperand_ParseFail;
3191 if (Parser.getTok().isNot(AsmToken::LCurly))
3192 return MatchOperand_NoMatch;
3194 Parser.Lex(); // Eat '{' token.
3195 SMLoc RegLoc = Parser.getTok().getLoc();
3197 int Reg = tryParseRegister();
3199 Error(RegLoc, "register expected");
3200 return MatchOperand_ParseFail;
3204 unsigned FirstReg = Reg;
3205 // The list is of D registers, but we also allow Q regs and just interpret
3206 // them as the two D sub-registers.
3207 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3208 FirstReg = Reg = getDRegFromQReg(Reg);
3209 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3210 // it's ambiguous with four-register single spaced.
3216 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3217 return MatchOperand_ParseFail;
3219 while (Parser.getTok().is(AsmToken::Comma) ||
3220 Parser.getTok().is(AsmToken::Minus)) {
3221 if (Parser.getTok().is(AsmToken::Minus)) {
3223 Spacing = 1; // Register range implies a single spaced list.
3224 else if (Spacing == 2) {
3225 Error(Parser.getTok().getLoc(),
3226 "sequential registers in double spaced list");
3227 return MatchOperand_ParseFail;
3229 Parser.Lex(); // Eat the minus.
3230 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3231 int EndReg = tryParseRegister();
3233 Error(AfterMinusLoc, "register expected");
3234 return MatchOperand_ParseFail;
3236 // Allow Q regs and just interpret them as the two D sub-registers.
3237 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3238 EndReg = getDRegFromQReg(EndReg) + 1;
3239 // If the register is the same as the start reg, there's nothing
3243 // The register must be in the same register class as the first.
3244 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3245 Error(AfterMinusLoc, "invalid register in register list");
3246 return MatchOperand_ParseFail;
3248 // Ranges must go from low to high.
3250 Error(AfterMinusLoc, "bad range in register list");
3251 return MatchOperand_ParseFail;
3253 // Parse the lane specifier if present.
3254 VectorLaneTy NextLaneKind;
3255 unsigned NextLaneIndex;
3256 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3257 MatchOperand_Success)
3258 return MatchOperand_ParseFail;
3259 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3260 Error(AfterMinusLoc, "mismatched lane index in register list");
3261 return MatchOperand_ParseFail;
3264 // Add all the registers in the range to the register list.
3265 Count += EndReg - Reg;
3269 Parser.Lex(); // Eat the comma.
3270 RegLoc = Parser.getTok().getLoc();
3272 Reg = tryParseRegister();
3274 Error(RegLoc, "register expected");
3275 return MatchOperand_ParseFail;
3277 // vector register lists must be contiguous.
3278 // It's OK to use the enumeration values directly here rather, as the
3279 // VFP register classes have the enum sorted properly.
3281 // The list is of D registers, but we also allow Q regs and just interpret
3282 // them as the two D sub-registers.
3283 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3285 Spacing = 1; // Register range implies a single spaced list.
3286 else if (Spacing == 2) {
3288 "invalid register in double-spaced list (must be 'D' register')");
3289 return MatchOperand_ParseFail;
3291 Reg = getDRegFromQReg(Reg);
3292 if (Reg != OldReg + 1) {
3293 Error(RegLoc, "non-contiguous register range");
3294 return MatchOperand_ParseFail;
3298 // Parse the lane specifier if present.
3299 VectorLaneTy NextLaneKind;
3300 unsigned NextLaneIndex;
3301 SMLoc LaneLoc = Parser.getTok().getLoc();
3302 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3303 MatchOperand_Success)
3304 return MatchOperand_ParseFail;
3305 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3306 Error(LaneLoc, "mismatched lane index in register list");
3307 return MatchOperand_ParseFail;
3311 // Normal D register.
3312 // Figure out the register spacing (single or double) of the list if
3313 // we don't know it already.
3315 Spacing = 1 + (Reg == OldReg + 2);
3317 // Just check that it's contiguous and keep going.
3318 if (Reg != OldReg + Spacing) {
3319 Error(RegLoc, "non-contiguous register range");
3320 return MatchOperand_ParseFail;
3323 // Parse the lane specifier if present.
3324 VectorLaneTy NextLaneKind;
3325 unsigned NextLaneIndex;
3326 SMLoc EndLoc = Parser.getTok().getLoc();
3327 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3328 return MatchOperand_ParseFail;
3329 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3330 Error(EndLoc, "mismatched lane index in register list");
3331 return MatchOperand_ParseFail;
3335 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3336 Error(Parser.getTok().getLoc(), "'}' expected");
3337 return MatchOperand_ParseFail;
3339 E = Parser.getTok().getEndLoc();
3340 Parser.Lex(); // Eat '}' token.
3344 // Two-register operands have been converted to the
3345 // composite register classes.
3347 const MCRegisterClass *RC = (Spacing == 1) ?
3348 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3349 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3350 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3353 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3354 (Spacing == 2), S, E));
3357 // Two-register operands have been converted to the
3358 // composite register classes.
3360 const MCRegisterClass *RC = (Spacing == 1) ?
3361 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3362 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3363 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3365 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3370 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3376 return MatchOperand_Success;
3379 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3380 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3381 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3382 SMLoc S = Parser.getTok().getLoc();
3383 const AsmToken &Tok = Parser.getTok();
3386 if (Tok.is(AsmToken::Identifier)) {
3387 StringRef OptStr = Tok.getString();
3389 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3390 .Case("sy", ARM_MB::SY)
3391 .Case("st", ARM_MB::ST)
3392 .Case("sh", ARM_MB::ISH)
3393 .Case("ish", ARM_MB::ISH)
3394 .Case("shst", ARM_MB::ISHST)
3395 .Case("ishst", ARM_MB::ISHST)
3396 .Case("nsh", ARM_MB::NSH)
3397 .Case("un", ARM_MB::NSH)
3398 .Case("nshst", ARM_MB::NSHST)
3399 .Case("unst", ARM_MB::NSHST)
3400 .Case("osh", ARM_MB::OSH)
3401 .Case("oshst", ARM_MB::OSHST)
3405 return MatchOperand_NoMatch;
3407 Parser.Lex(); // Eat identifier token.
3408 } else if (Tok.is(AsmToken::Hash) ||
3409 Tok.is(AsmToken::Dollar) ||
3410 Tok.is(AsmToken::Integer)) {
3411 if (Parser.getTok().isNot(AsmToken::Integer))
3412 Parser.Lex(); // Eat the '#'.
3413 SMLoc Loc = Parser.getTok().getLoc();
3415 const MCExpr *MemBarrierID;
3416 if (getParser().parseExpression(MemBarrierID)) {
3417 Error(Loc, "illegal expression");
3418 return MatchOperand_ParseFail;
3421 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3423 Error(Loc, "constant expression expected");
3424 return MatchOperand_ParseFail;
3427 int Val = CE->getValue();
3429 Error(Loc, "immediate value out of range");
3430 return MatchOperand_ParseFail;
3433 Opt = ARM_MB::RESERVED_0 + Val;
3435 return MatchOperand_ParseFail;
3437 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3438 return MatchOperand_Success;
3441 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3442 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3443 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3444 SMLoc S = Parser.getTok().getLoc();
3445 const AsmToken &Tok = Parser.getTok();
3448 if (Tok.is(AsmToken::Identifier)) {
3449 StringRef OptStr = Tok.getString();
3451 if (OptStr.lower() == "sy")
3454 return MatchOperand_NoMatch;
3456 Parser.Lex(); // Eat identifier token.
3457 } else if (Tok.is(AsmToken::Hash) ||
3458 Tok.is(AsmToken::Dollar) ||
3459 Tok.is(AsmToken::Integer)) {
3460 if (Parser.getTok().isNot(AsmToken::Integer))
3461 Parser.Lex(); // Eat the '#'.
3462 SMLoc Loc = Parser.getTok().getLoc();
3464 const MCExpr *ISBarrierID;
3465 if (getParser().parseExpression(ISBarrierID)) {
3466 Error(Loc, "illegal expression");
3467 return MatchOperand_ParseFail;
3470 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3472 Error(Loc, "constant expression expected");
3473 return MatchOperand_ParseFail;
3476 int Val = CE->getValue();
3478 Error(Loc, "immediate value out of range");
3479 return MatchOperand_ParseFail;
3482 Opt = ARM_ISB::RESERVED_0 + Val;
3484 return MatchOperand_ParseFail;
3486 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3487 (ARM_ISB::InstSyncBOpt)Opt, S));
3488 return MatchOperand_Success;
3492 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3493 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3494 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3495 SMLoc S = Parser.getTok().getLoc();
3496 const AsmToken &Tok = Parser.getTok();
3497 if (!Tok.is(AsmToken::Identifier))
3498 return MatchOperand_NoMatch;
3499 StringRef IFlagsStr = Tok.getString();
3501 // An iflags string of "none" is interpreted to mean that none of the AIF
3502 // bits are set. Not a terribly useful instruction, but a valid encoding.
3503 unsigned IFlags = 0;
3504 if (IFlagsStr != "none") {
3505 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3506 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3507 .Case("a", ARM_PROC::A)
3508 .Case("i", ARM_PROC::I)
3509 .Case("f", ARM_PROC::F)
3512 // If some specific iflag is already set, it means that some letter is
3513 // present more than once, this is not acceptable.
3514 if (Flag == ~0U || (IFlags & Flag))
3515 return MatchOperand_NoMatch;
3521 Parser.Lex(); // Eat identifier token.
3522 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3523 return MatchOperand_Success;
3526 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3527 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3528 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3529 SMLoc S = Parser.getTok().getLoc();
3530 const AsmToken &Tok = Parser.getTok();
3531 if (!Tok.is(AsmToken::Identifier))
3532 return MatchOperand_NoMatch;
3533 StringRef Mask = Tok.getString();
3536 // See ARMv6-M 10.1.1
3537 std::string Name = Mask.lower();
3538 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3539 // Note: in the documentation:
3540 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3541 // for MSR APSR_nzcvq.
3542 // but we do make it an alias here. This is so to get the "mask encoding"
3543 // bits correct on MSR APSR writes.
3545 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3546 // should really only be allowed when writing a special register. Note
3547 // they get dropped in the MRS instruction reading a special register as
3548 // the SYSm field is only 8 bits.
3550 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3551 // includes the DSP extension but that is not checked.
3552 .Case("apsr", 0x800)
3553 .Case("apsr_nzcvq", 0x800)
3554 .Case("apsr_g", 0x400)
3555 .Case("apsr_nzcvqg", 0xc00)
3556 .Case("iapsr", 0x801)
3557 .Case("iapsr_nzcvq", 0x801)
3558 .Case("iapsr_g", 0x401)
3559 .Case("iapsr_nzcvqg", 0xc01)
3560 .Case("eapsr", 0x802)
3561 .Case("eapsr_nzcvq", 0x802)
3562 .Case("eapsr_g", 0x402)
3563 .Case("eapsr_nzcvqg", 0xc02)
3564 .Case("xpsr", 0x803)
3565 .Case("xpsr_nzcvq", 0x803)
3566 .Case("xpsr_g", 0x403)
3567 .Case("xpsr_nzcvqg", 0xc03)
3568 .Case("ipsr", 0x805)
3569 .Case("epsr", 0x806)
3570 .Case("iepsr", 0x807)
3573 .Case("primask", 0x810)
3574 .Case("basepri", 0x811)
3575 .Case("basepri_max", 0x812)
3576 .Case("faultmask", 0x813)
3577 .Case("control", 0x814)
3580 if (FlagsVal == ~0U)
3581 return MatchOperand_NoMatch;
3583 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3584 // basepri, basepri_max and faultmask only valid for V7m.
3585 return MatchOperand_NoMatch;
3587 Parser.Lex(); // Eat identifier token.
3588 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3589 return MatchOperand_Success;
3592 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3593 size_t Start = 0, Next = Mask.find('_');
3594 StringRef Flags = "";
3595 std::string SpecReg = Mask.slice(Start, Next).lower();
3596 if (Next != StringRef::npos)
3597 Flags = Mask.slice(Next+1, Mask.size());
3599 // FlagsVal contains the complete mask:
3601 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3602 unsigned FlagsVal = 0;
3604 if (SpecReg == "apsr") {
3605 FlagsVal = StringSwitch<unsigned>(Flags)
3606 .Case("nzcvq", 0x8) // same as CPSR_f
3607 .Case("g", 0x4) // same as CPSR_s
3608 .Case("nzcvqg", 0xc) // same as CPSR_fs
3611 if (FlagsVal == ~0U) {
3613 return MatchOperand_NoMatch;
3615 FlagsVal = 8; // No flag
3617 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3618 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3619 if (Flags == "all" || Flags == "")
3621 for (int i = 0, e = Flags.size(); i != e; ++i) {
3622 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3629 // If some specific flag is already set, it means that some letter is
3630 // present more than once, this is not acceptable.
3631 if (FlagsVal == ~0U || (FlagsVal & Flag))
3632 return MatchOperand_NoMatch;
3635 } else // No match for special register.
3636 return MatchOperand_NoMatch;
3638 // Special register without flags is NOT equivalent to "fc" flags.
3639 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3640 // two lines would enable gas compatibility at the expense of breaking
3646 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3647 if (SpecReg == "spsr")
3650 Parser.Lex(); // Eat identifier token.
3651 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3652 return MatchOperand_Success;
3655 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3656 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3657 int Low, int High) {
3658 const AsmToken &Tok = Parser.getTok();
3659 if (Tok.isNot(AsmToken::Identifier)) {
3660 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3661 return MatchOperand_ParseFail;
3663 StringRef ShiftName = Tok.getString();
3664 std::string LowerOp = Op.lower();
3665 std::string UpperOp = Op.upper();
3666 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3667 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3668 return MatchOperand_ParseFail;
3670 Parser.Lex(); // Eat shift type token.
3672 // There must be a '#' and a shift amount.
3673 if (Parser.getTok().isNot(AsmToken::Hash) &&
3674 Parser.getTok().isNot(AsmToken::Dollar)) {
3675 Error(Parser.getTok().getLoc(), "'#' expected");
3676 return MatchOperand_ParseFail;
3678 Parser.Lex(); // Eat hash token.
3680 const MCExpr *ShiftAmount;
3681 SMLoc Loc = Parser.getTok().getLoc();
3683 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3684 Error(Loc, "illegal expression");
3685 return MatchOperand_ParseFail;
3687 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3689 Error(Loc, "constant expression expected");
3690 return MatchOperand_ParseFail;
3692 int Val = CE->getValue();
3693 if (Val < Low || Val > High) {
3694 Error(Loc, "immediate value out of range");
3695 return MatchOperand_ParseFail;
3698 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3700 return MatchOperand_Success;
3703 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3704 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3705 const AsmToken &Tok = Parser.getTok();
3706 SMLoc S = Tok.getLoc();
3707 if (Tok.isNot(AsmToken::Identifier)) {
3708 Error(S, "'be' or 'le' operand expected");
3709 return MatchOperand_ParseFail;
3711 int Val = StringSwitch<int>(Tok.getString().lower())
3715 Parser.Lex(); // Eat the token.
3718 Error(S, "'be' or 'le' operand expected");
3719 return MatchOperand_ParseFail;
3721 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3723 S, Tok.getEndLoc()));
3724 return MatchOperand_Success;
3727 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3728 /// instructions. Legal values are:
3729 /// lsl #n 'n' in [0,31]
3730 /// asr #n 'n' in [1,32]
3731 /// n == 32 encoded as n == 0.
3732 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3733 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3734 const AsmToken &Tok = Parser.getTok();
3735 SMLoc S = Tok.getLoc();
3736 if (Tok.isNot(AsmToken::Identifier)) {
3737 Error(S, "shift operator 'asr' or 'lsl' expected");
3738 return MatchOperand_ParseFail;
3740 StringRef ShiftName = Tok.getString();
3742 if (ShiftName == "lsl" || ShiftName == "LSL")
3744 else if (ShiftName == "asr" || ShiftName == "ASR")
3747 Error(S, "shift operator 'asr' or 'lsl' expected");
3748 return MatchOperand_ParseFail;
3750 Parser.Lex(); // Eat the operator.
3752 // A '#' and a shift amount.
3753 if (Parser.getTok().isNot(AsmToken::Hash) &&
3754 Parser.getTok().isNot(AsmToken::Dollar)) {
3755 Error(Parser.getTok().getLoc(), "'#' expected");
3756 return MatchOperand_ParseFail;
3758 Parser.Lex(); // Eat hash token.
3759 SMLoc ExLoc = Parser.getTok().getLoc();
3761 const MCExpr *ShiftAmount;
3763 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3764 Error(ExLoc, "malformed shift expression");
3765 return MatchOperand_ParseFail;
3767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3769 Error(ExLoc, "shift amount must be an immediate");
3770 return MatchOperand_ParseFail;
3773 int64_t Val = CE->getValue();
3775 // Shift amount must be in [1,32]
3776 if (Val < 1 || Val > 32) {
3777 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3778 return MatchOperand_ParseFail;
3780 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3781 if (isThumb() && Val == 32) {
3782 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3783 return MatchOperand_ParseFail;
3785 if (Val == 32) Val = 0;
3787 // Shift amount must be in [1,32]
3788 if (Val < 0 || Val > 31) {
3789 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3790 return MatchOperand_ParseFail;
3794 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3796 return MatchOperand_Success;
3799 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3800 /// of instructions. Legal values are:
3801 /// ror #n 'n' in {0, 8, 16, 24}
3802 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3803 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3804 const AsmToken &Tok = Parser.getTok();
3805 SMLoc S = Tok.getLoc();
3806 if (Tok.isNot(AsmToken::Identifier))
3807 return MatchOperand_NoMatch;
3808 StringRef ShiftName = Tok.getString();
3809 if (ShiftName != "ror" && ShiftName != "ROR")
3810 return MatchOperand_NoMatch;
3811 Parser.Lex(); // Eat the operator.
3813 // A '#' and a rotate amount.
3814 if (Parser.getTok().isNot(AsmToken::Hash) &&
3815 Parser.getTok().isNot(AsmToken::Dollar)) {
3816 Error(Parser.getTok().getLoc(), "'#' expected");
3817 return MatchOperand_ParseFail;
3819 Parser.Lex(); // Eat hash token.
3820 SMLoc ExLoc = Parser.getTok().getLoc();
3822 const MCExpr *ShiftAmount;
3824 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3825 Error(ExLoc, "malformed rotate expression");
3826 return MatchOperand_ParseFail;
3828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3830 Error(ExLoc, "rotate amount must be an immediate");
3831 return MatchOperand_ParseFail;
3834 int64_t Val = CE->getValue();
3835 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3836 // normally, zero is represented in asm by omitting the rotate operand
3838 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3839 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
3840 return MatchOperand_ParseFail;
3843 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
3845 return MatchOperand_Success;
3848 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3849 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3850 SMLoc S = Parser.getTok().getLoc();
3851 // The bitfield descriptor is really two operands, the LSB and the width.
3852 if (Parser.getTok().isNot(AsmToken::Hash) &&
3853 Parser.getTok().isNot(AsmToken::Dollar)) {
3854 Error(Parser.getTok().getLoc(), "'#' expected");
3855 return MatchOperand_ParseFail;
3857 Parser.Lex(); // Eat hash token.
3859 const MCExpr *LSBExpr;
3860 SMLoc E = Parser.getTok().getLoc();
3861 if (getParser().parseExpression(LSBExpr)) {
3862 Error(E, "malformed immediate expression");
3863 return MatchOperand_ParseFail;
3865 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3867 Error(E, "'lsb' operand must be an immediate");
3868 return MatchOperand_ParseFail;
3871 int64_t LSB = CE->getValue();
3872 // The LSB must be in the range [0,31]
3873 if (LSB < 0 || LSB > 31) {
3874 Error(E, "'lsb' operand must be in the range [0,31]");
3875 return MatchOperand_ParseFail;
3877 E = Parser.getTok().getLoc();
3879 // Expect another immediate operand.
3880 if (Parser.getTok().isNot(AsmToken::Comma)) {
3881 Error(Parser.getTok().getLoc(), "too few operands");
3882 return MatchOperand_ParseFail;
3884 Parser.Lex(); // Eat hash token.
3885 if (Parser.getTok().isNot(AsmToken::Hash) &&
3886 Parser.getTok().isNot(AsmToken::Dollar)) {
3887 Error(Parser.getTok().getLoc(), "'#' expected");
3888 return MatchOperand_ParseFail;
3890 Parser.Lex(); // Eat hash token.
3892 const MCExpr *WidthExpr;
3894 if (getParser().parseExpression(WidthExpr, EndLoc)) {
3895 Error(E, "malformed immediate expression");
3896 return MatchOperand_ParseFail;
3898 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3900 Error(E, "'width' operand must be an immediate");
3901 return MatchOperand_ParseFail;
3904 int64_t Width = CE->getValue();
3905 // The LSB must be in the range [1,32-lsb]
3906 if (Width < 1 || Width > 32 - LSB) {
3907 Error(E, "'width' operand must be in the range [1,32-lsb]");
3908 return MatchOperand_ParseFail;
3911 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
3913 return MatchOperand_Success;
3916 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3917 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3918 // Check for a post-index addressing register operand. Specifically:
3919 // postidx_reg := '+' register {, shift}
3920 // | '-' register {, shift}
3921 // | register {, shift}
3923 // This method must return MatchOperand_NoMatch without consuming any tokens
3924 // in the case where there is no match, as other alternatives take other
3926 AsmToken Tok = Parser.getTok();
3927 SMLoc S = Tok.getLoc();
3928 bool haveEaten = false;
3930 if (Tok.is(AsmToken::Plus)) {
3931 Parser.Lex(); // Eat the '+' token.
3933 } else if (Tok.is(AsmToken::Minus)) {
3934 Parser.Lex(); // Eat the '-' token.
3939 SMLoc E = Parser.getTok().getEndLoc();
3940 int Reg = tryParseRegister();
3943 return MatchOperand_NoMatch;
3944 Error(Parser.getTok().getLoc(), "register expected");
3945 return MatchOperand_ParseFail;
3948 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3949 unsigned ShiftImm = 0;
3950 if (Parser.getTok().is(AsmToken::Comma)) {
3951 Parser.Lex(); // Eat the ','.
3952 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3953 return MatchOperand_ParseFail;
3955 // FIXME: Only approximates end...may include intervening whitespace.
3956 E = Parser.getTok().getLoc();
3959 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3962 return MatchOperand_Success;
3965 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3966 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3967 // Check for a post-index addressing register operand. Specifically:
3968 // am3offset := '+' register
3975 // This method must return MatchOperand_NoMatch without consuming any tokens
3976 // in the case where there is no match, as other alternatives take other
3978 AsmToken Tok = Parser.getTok();
3979 SMLoc S = Tok.getLoc();
3981 // Do immediates first, as we always parse those if we have a '#'.
3982 if (Parser.getTok().is(AsmToken::Hash) ||
3983 Parser.getTok().is(AsmToken::Dollar)) {
3984 Parser.Lex(); // Eat the '#'.
3985 // Explicitly look for a '-', as we need to encode negative zero
3987 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3988 const MCExpr *Offset;
3990 if (getParser().parseExpression(Offset, E))
3991 return MatchOperand_ParseFail;
3992 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3994 Error(S, "constant expression expected");
3995 return MatchOperand_ParseFail;
3997 // Negative zero is encoded as the flag value INT32_MIN.
3998 int32_t Val = CE->getValue();
3999 if (isNegative && Val == 0)
4003 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4005 return MatchOperand_Success;
4009 bool haveEaten = false;
4011 if (Tok.is(AsmToken::Plus)) {
4012 Parser.Lex(); // Eat the '+' token.
4014 } else if (Tok.is(AsmToken::Minus)) {
4015 Parser.Lex(); // Eat the '-' token.
4020 Tok = Parser.getTok();
4021 int Reg = tryParseRegister();
4024 return MatchOperand_NoMatch;
4025 Error(Tok.getLoc(), "register expected");
4026 return MatchOperand_ParseFail;
4029 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4030 0, S, Tok.getEndLoc()));
4032 return MatchOperand_Success;
4035 /// cvtT2LdrdPre - Convert parsed operands to MCInst.
4036 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4037 /// when they refer multiple MIOperands inside a single one.
4039 cvtT2LdrdPre(MCInst &Inst,
4040 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4042 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4043 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4044 // Create a writeback register dummy placeholder.
4045 Inst.addOperand(MCOperand::CreateReg(0));
4047 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4049 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4052 /// cvtT2StrdPre - Convert parsed operands to MCInst.
4053 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4054 /// when they refer multiple MIOperands inside a single one.
4056 cvtT2StrdPre(MCInst &Inst,
4057 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4058 // Create a writeback register dummy placeholder.
4059 Inst.addOperand(MCOperand::CreateReg(0));
4061 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4062 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4064 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4066 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4069 /// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4070 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4071 /// when they refer multiple MIOperands inside a single one.
4073 cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
4074 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4075 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4077 // Create a writeback register dummy placeholder.
4078 Inst.addOperand(MCOperand::CreateImm(0));
4080 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4081 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4084 /// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4085 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4086 /// when they refer multiple MIOperands inside a single one.
4088 cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
4089 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4090 // Create a writeback register dummy placeholder.
4091 Inst.addOperand(MCOperand::CreateImm(0));
4092 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4093 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4094 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4097 /// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
4098 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4099 /// when they refer multiple MIOperands inside a single one.
4101 cvtLdWriteBackRegAddrMode2(MCInst &Inst,
4102 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4103 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4105 // Create a writeback register dummy placeholder.
4106 Inst.addOperand(MCOperand::CreateImm(0));
4108 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4109 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4112 /// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4113 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4114 /// when they refer multiple MIOperands inside a single one.
4116 cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
4117 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4118 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4120 // Create a writeback register dummy placeholder.
4121 Inst.addOperand(MCOperand::CreateImm(0));
4123 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4124 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4128 /// cvtStWriteBackRegAddrModeImm12 - 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 cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
4133 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4134 // Create a writeback register dummy placeholder.
4135 Inst.addOperand(MCOperand::CreateImm(0));
4136 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4137 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4138 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4141 /// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
4142 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4143 /// when they refer multiple MIOperands inside a single one.
4145 cvtStWriteBackRegAddrMode2(MCInst &Inst,
4146 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4147 // Create a writeback register dummy placeholder.
4148 Inst.addOperand(MCOperand::CreateImm(0));
4149 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4150 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4151 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4154 /// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4155 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4156 /// when they refer multiple MIOperands inside a single one.
4158 cvtStWriteBackRegAddrMode3(MCInst &Inst,
4159 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4160 // Create a writeback register dummy placeholder.
4161 Inst.addOperand(MCOperand::CreateImm(0));
4162 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4163 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4164 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4167 /// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4168 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4169 /// when they refer multiple MIOperands inside a single one.
4171 cvtLdExtTWriteBackImm(MCInst &Inst,
4172 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4174 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4175 // Create a writeback register dummy placeholder.
4176 Inst.addOperand(MCOperand::CreateImm(0));
4178 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4180 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4182 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4185 /// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
4186 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4187 /// when they refer multiple MIOperands inside a single one.
4189 cvtLdExtTWriteBackReg(MCInst &Inst,
4190 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4192 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4193 // Create a writeback register dummy placeholder.
4194 Inst.addOperand(MCOperand::CreateImm(0));
4196 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4198 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4200 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4203 /// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
4204 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4205 /// when they refer multiple MIOperands inside a single one.
4207 cvtStExtTWriteBackImm(MCInst &Inst,
4208 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4209 // Create a writeback register dummy placeholder.
4210 Inst.addOperand(MCOperand::CreateImm(0));
4212 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4214 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4216 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4218 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4221 /// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4222 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4223 /// when they refer multiple MIOperands inside a single one.
4225 cvtStExtTWriteBackReg(MCInst &Inst,
4226 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4227 // Create a writeback register dummy placeholder.
4228 Inst.addOperand(MCOperand::CreateImm(0));
4230 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4232 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4234 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4236 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4239 /// cvtLdrdPre - Convert parsed operands to MCInst.
4240 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4241 /// when they refer multiple MIOperands inside a single one.
4243 cvtLdrdPre(MCInst &Inst,
4244 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4246 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4247 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4248 // Create a writeback register dummy placeholder.
4249 Inst.addOperand(MCOperand::CreateImm(0));
4251 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4253 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4256 /// cvtStrdPre - Convert parsed operands to MCInst.
4257 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4258 /// when they refer multiple MIOperands inside a single one.
4260 cvtStrdPre(MCInst &Inst,
4261 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4262 // Create a writeback register dummy placeholder.
4263 Inst.addOperand(MCOperand::CreateImm(0));
4265 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4266 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4268 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4270 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4273 /// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4274 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4275 /// when they refer multiple MIOperands inside a single one.
4277 cvtLdWriteBackRegAddrMode3(MCInst &Inst,
4278 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4279 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4280 // Create a writeback register dummy placeholder.
4281 Inst.addOperand(MCOperand::CreateImm(0));
4282 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4283 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4286 /// cvtThumbMultiply - Convert parsed operands to MCInst.
4287 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4288 /// when they refer multiple MIOperands inside a single one.
4290 cvtThumbMultiply(MCInst &Inst,
4291 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4292 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4293 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4294 // If we have a three-operand form, make sure to set Rn to be the operand
4295 // that isn't the same as Rd.
4297 if (Operands.size() == 6 &&
4298 ((ARMOperand*)Operands[4])->getReg() ==
4299 ((ARMOperand*)Operands[3])->getReg())
4301 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4302 Inst.addOperand(Inst.getOperand(0));
4303 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4307 cvtVLDwbFixed(MCInst &Inst,
4308 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4310 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4311 // Create a writeback register dummy placeholder.
4312 Inst.addOperand(MCOperand::CreateImm(0));
4314 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4316 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4320 cvtVLDwbRegister(MCInst &Inst,
4321 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4323 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4324 // Create a writeback register dummy placeholder.
4325 Inst.addOperand(MCOperand::CreateImm(0));
4327 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4329 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4331 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4335 cvtVSTwbFixed(MCInst &Inst,
4336 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4337 // Create a writeback register dummy placeholder.
4338 Inst.addOperand(MCOperand::CreateImm(0));
4340 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4342 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4344 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4348 cvtVSTwbRegister(MCInst &Inst,
4349 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4350 // Create a writeback register dummy placeholder.
4351 Inst.addOperand(MCOperand::CreateImm(0));
4353 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4355 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4357 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4359 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4362 /// Parse an ARM memory expression, return false if successful else return true
4363 /// or an error. The first token must be a '[' when called.
4365 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4367 assert(Parser.getTok().is(AsmToken::LBrac) &&
4368 "Token is not a Left Bracket");
4369 S = Parser.getTok().getLoc();
4370 Parser.Lex(); // Eat left bracket token.
4372 const AsmToken &BaseRegTok = Parser.getTok();
4373 int BaseRegNum = tryParseRegister();
4374 if (BaseRegNum == -1)
4375 return Error(BaseRegTok.getLoc(), "register expected");
4377 // The next token must either be a comma, a colon or a closing bracket.
4378 const AsmToken &Tok = Parser.getTok();
4379 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4380 !Tok.is(AsmToken::RBrac))
4381 return Error(Tok.getLoc(), "malformed memory operand");
4383 if (Tok.is(AsmToken::RBrac)) {
4384 E = Tok.getEndLoc();
4385 Parser.Lex(); // Eat right bracket token.
4387 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4388 0, 0, false, S, E));
4390 // If there's a pre-indexing writeback marker, '!', just add it as a token
4391 // operand. It's rather odd, but syntactically valid.
4392 if (Parser.getTok().is(AsmToken::Exclaim)) {
4393 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4394 Parser.Lex(); // Eat the '!'.
4400 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4401 "Lost colon or comma in memory operand?!");
4402 if (Tok.is(AsmToken::Comma)) {
4403 Parser.Lex(); // Eat the comma.
4406 // If we have a ':', it's an alignment specifier.
4407 if (Parser.getTok().is(AsmToken::Colon)) {
4408 Parser.Lex(); // Eat the ':'.
4409 E = Parser.getTok().getLoc();
4412 if (getParser().parseExpression(Expr))
4415 // The expression has to be a constant. Memory references with relocations
4416 // don't come through here, as they use the <label> forms of the relevant
4418 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4420 return Error (E, "constant expression expected");
4423 switch (CE->getValue()) {
4426 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4427 case 16: Align = 2; break;
4428 case 32: Align = 4; break;
4429 case 64: Align = 8; break;
4430 case 128: Align = 16; break;
4431 case 256: Align = 32; break;
4434 // Now we should have the closing ']'
4435 if (Parser.getTok().isNot(AsmToken::RBrac))
4436 return Error(Parser.getTok().getLoc(), "']' expected");
4437 E = Parser.getTok().getEndLoc();
4438 Parser.Lex(); // Eat right bracket token.
4440 // Don't worry about range checking the value here. That's handled by
4441 // the is*() predicates.
4442 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4443 ARM_AM::no_shift, 0, Align,
4446 // If there's a pre-indexing writeback marker, '!', just add it as a token
4448 if (Parser.getTok().is(AsmToken::Exclaim)) {
4449 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4450 Parser.Lex(); // Eat the '!'.
4456 // If we have a '#', it's an immediate offset, else assume it's a register
4457 // offset. Be friendly and also accept a plain integer (without a leading
4458 // hash) for gas compatibility.
4459 if (Parser.getTok().is(AsmToken::Hash) ||
4460 Parser.getTok().is(AsmToken::Dollar) ||
4461 Parser.getTok().is(AsmToken::Integer)) {
4462 if (Parser.getTok().isNot(AsmToken::Integer))
4463 Parser.Lex(); // Eat the '#'.
4464 E = Parser.getTok().getLoc();
4466 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4467 const MCExpr *Offset;
4468 if (getParser().parseExpression(Offset))
4471 // The expression has to be a constant. Memory references with relocations
4472 // don't come through here, as they use the <label> forms of the relevant
4474 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4476 return Error (E, "constant expression expected");
4478 // If the constant was #-0, represent it as INT32_MIN.
4479 int32_t Val = CE->getValue();
4480 if (isNegative && Val == 0)
4481 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4483 // Now we should have the closing ']'
4484 if (Parser.getTok().isNot(AsmToken::RBrac))
4485 return Error(Parser.getTok().getLoc(), "']' expected");
4486 E = Parser.getTok().getEndLoc();
4487 Parser.Lex(); // Eat right bracket token.
4489 // Don't worry about range checking the value here. That's handled by
4490 // the is*() predicates.
4491 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4492 ARM_AM::no_shift, 0, 0,
4495 // If there's a pre-indexing writeback marker, '!', just add it as a token
4497 if (Parser.getTok().is(AsmToken::Exclaim)) {
4498 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4499 Parser.Lex(); // Eat the '!'.
4505 // The register offset is optionally preceded by a '+' or '-'
4506 bool isNegative = false;
4507 if (Parser.getTok().is(AsmToken::Minus)) {
4509 Parser.Lex(); // Eat the '-'.
4510 } else if (Parser.getTok().is(AsmToken::Plus)) {
4512 Parser.Lex(); // Eat the '+'.
4515 E = Parser.getTok().getLoc();
4516 int OffsetRegNum = tryParseRegister();
4517 if (OffsetRegNum == -1)
4518 return Error(E, "register expected");
4520 // If there's a shift operator, handle it.
4521 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4522 unsigned ShiftImm = 0;
4523 if (Parser.getTok().is(AsmToken::Comma)) {
4524 Parser.Lex(); // Eat the ','.
4525 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4529 // Now we should have the closing ']'
4530 if (Parser.getTok().isNot(AsmToken::RBrac))
4531 return Error(Parser.getTok().getLoc(), "']' expected");
4532 E = Parser.getTok().getEndLoc();
4533 Parser.Lex(); // Eat right bracket token.
4535 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4536 ShiftType, ShiftImm, 0, isNegative,
4539 // If there's a pre-indexing writeback marker, '!', just add it as a token
4541 if (Parser.getTok().is(AsmToken::Exclaim)) {
4542 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4543 Parser.Lex(); // Eat the '!'.
4549 /// parseMemRegOffsetShift - one of these two:
4550 /// ( lsl | lsr | asr | ror ) , # shift_amount
4552 /// return true if it parses a shift otherwise it returns false.
4553 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4555 SMLoc Loc = Parser.getTok().getLoc();
4556 const AsmToken &Tok = Parser.getTok();
4557 if (Tok.isNot(AsmToken::Identifier))
4559 StringRef ShiftName = Tok.getString();
4560 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4561 ShiftName == "asl" || ShiftName == "ASL")
4563 else if (ShiftName == "lsr" || ShiftName == "LSR")
4565 else if (ShiftName == "asr" || ShiftName == "ASR")
4567 else if (ShiftName == "ror" || ShiftName == "ROR")
4569 else if (ShiftName == "rrx" || ShiftName == "RRX")
4572 return Error(Loc, "illegal shift operator");
4573 Parser.Lex(); // Eat shift type token.
4575 // rrx stands alone.
4577 if (St != ARM_AM::rrx) {
4578 Loc = Parser.getTok().getLoc();
4579 // A '#' and a shift amount.
4580 const AsmToken &HashTok = Parser.getTok();
4581 if (HashTok.isNot(AsmToken::Hash) &&
4582 HashTok.isNot(AsmToken::Dollar))
4583 return Error(HashTok.getLoc(), "'#' expected");
4584 Parser.Lex(); // Eat hash token.
4587 if (getParser().parseExpression(Expr))
4589 // Range check the immediate.
4590 // lsl, ror: 0 <= imm <= 31
4591 // lsr, asr: 0 <= imm <= 32
4592 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4594 return Error(Loc, "shift amount must be an immediate");
4595 int64_t Imm = CE->getValue();
4597 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4598 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4599 return Error(Loc, "immediate shift value out of range");
4600 // If <ShiftTy> #0, turn it into a no_shift.
4603 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4612 /// parseFPImm - A floating point immediate expression operand.
4613 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4614 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4615 // Anything that can accept a floating point constant as an operand
4616 // needs to go through here, as the regular parseExpression is
4619 // This routine still creates a generic Immediate operand, containing
4620 // a bitcast of the 64-bit floating point value. The various operands
4621 // that accept floats can check whether the value is valid for them
4622 // via the standard is*() predicates.
4624 SMLoc S = Parser.getTok().getLoc();
4626 if (Parser.getTok().isNot(AsmToken::Hash) &&
4627 Parser.getTok().isNot(AsmToken::Dollar))
4628 return MatchOperand_NoMatch;
4630 // Disambiguate the VMOV forms that can accept an FP immediate.
4631 // vmov.f32 <sreg>, #imm
4632 // vmov.f64 <dreg>, #imm
4633 // vmov.f32 <dreg>, #imm @ vector f32x2
4634 // vmov.f32 <qreg>, #imm @ vector f32x4
4636 // There are also the NEON VMOV instructions which expect an
4637 // integer constant. Make sure we don't try to parse an FPImm
4639 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4640 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4641 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4642 TyOp->getToken() != ".f64"))
4643 return MatchOperand_NoMatch;
4645 Parser.Lex(); // Eat the '#'.
4647 // Handle negation, as that still comes through as a separate token.
4648 bool isNegative = false;
4649 if (Parser.getTok().is(AsmToken::Minus)) {
4653 const AsmToken &Tok = Parser.getTok();
4654 SMLoc Loc = Tok.getLoc();
4655 if (Tok.is(AsmToken::Real)) {
4656 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4657 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4658 // If we had a '-' in front, toggle the sign bit.
4659 IntVal ^= (uint64_t)isNegative << 31;
4660 Parser.Lex(); // Eat the token.
4661 Operands.push_back(ARMOperand::CreateImm(
4662 MCConstantExpr::Create(IntVal, getContext()),
4663 S, Parser.getTok().getLoc()));
4664 return MatchOperand_Success;
4666 // Also handle plain integers. Instructions which allow floating point
4667 // immediates also allow a raw encoded 8-bit value.
4668 if (Tok.is(AsmToken::Integer)) {
4669 int64_t Val = Tok.getIntVal();
4670 Parser.Lex(); // Eat the token.
4671 if (Val > 255 || Val < 0) {
4672 Error(Loc, "encoded floating point value out of range");
4673 return MatchOperand_ParseFail;
4675 double RealVal = ARM_AM::getFPImmFloat(Val);
4676 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4677 Operands.push_back(ARMOperand::CreateImm(
4678 MCConstantExpr::Create(Val, getContext()), S,
4679 Parser.getTok().getLoc()));
4680 return MatchOperand_Success;
4683 Error(Loc, "invalid floating point immediate");
4684 return MatchOperand_ParseFail;
4687 /// Parse a arm instruction operand. For now this parses the operand regardless
4688 /// of the mnemonic.
4689 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4690 StringRef Mnemonic) {
4693 // Check if the current operand has a custom associated parser, if so, try to
4694 // custom parse the operand, or fallback to the general approach.
4695 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4696 if (ResTy == MatchOperand_Success)
4698 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4699 // there was a match, but an error occurred, in which case, just return that
4700 // the operand parsing failed.
4701 if (ResTy == MatchOperand_ParseFail)
4704 switch (getLexer().getKind()) {
4706 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4708 case AsmToken::Identifier: {
4709 // If we've seen a branch mnemonic, the next operand must be a label. This
4710 // is true even if the label is a register name. So "br r1" means branch to
4712 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4714 if (!tryParseRegisterWithWriteBack(Operands))
4716 int Res = tryParseShiftRegister(Operands);
4717 if (Res == 0) // success
4719 else if (Res == -1) // irrecoverable error
4721 // If this is VMRS, check for the apsr_nzcv operand.
4722 if (Mnemonic == "vmrs" &&
4723 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4724 S = Parser.getTok().getLoc();
4726 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4731 // Fall though for the Identifier case that is not a register or a
4734 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4735 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4736 case AsmToken::String: // quoted label names.
4737 case AsmToken::Dot: { // . as a branch target
4738 // This was not a register so parse other operands that start with an
4739 // identifier (like labels) as expressions and create them as immediates.
4740 const MCExpr *IdVal;
4741 S = Parser.getTok().getLoc();
4742 if (getParser().parseExpression(IdVal))
4744 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4745 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4748 case AsmToken::LBrac:
4749 return parseMemory(Operands);
4750 case AsmToken::LCurly:
4751 return parseRegisterList(Operands);
4752 case AsmToken::Dollar:
4753 case AsmToken::Hash: {
4754 // #42 -> immediate.
4755 S = Parser.getTok().getLoc();
4758 if (Parser.getTok().isNot(AsmToken::Colon)) {
4759 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4760 const MCExpr *ImmVal;
4761 if (getParser().parseExpression(ImmVal))
4763 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4765 int32_t Val = CE->getValue();
4766 if (isNegative && Val == 0)
4767 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4769 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4770 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4772 // There can be a trailing '!' on operands that we want as a separate
4773 // '!' Token operand. Handle that here. For example, the compatibilty
4774 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4775 if (Parser.getTok().is(AsmToken::Exclaim)) {
4776 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4777 Parser.getTok().getLoc()));
4778 Parser.Lex(); // Eat exclaim token
4782 // w/ a ':' after the '#', it's just like a plain ':'.
4785 case AsmToken::Colon: {
4786 // ":lower16:" and ":upper16:" expression prefixes
4787 // FIXME: Check it's an expression prefix,
4788 // e.g. (FOO - :lower16:BAR) isn't legal.
4789 ARMMCExpr::VariantKind RefKind;
4790 if (parsePrefix(RefKind))
4793 const MCExpr *SubExprVal;
4794 if (getParser().parseExpression(SubExprVal))
4797 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4799 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4800 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4806 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4807 // :lower16: and :upper16:.
4808 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4809 RefKind = ARMMCExpr::VK_ARM_None;
4811 // :lower16: and :upper16: modifiers
4812 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4813 Parser.Lex(); // Eat ':'
4815 if (getLexer().isNot(AsmToken::Identifier)) {
4816 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4820 StringRef IDVal = Parser.getTok().getIdentifier();
4821 if (IDVal == "lower16") {
4822 RefKind = ARMMCExpr::VK_ARM_LO16;
4823 } else if (IDVal == "upper16") {
4824 RefKind = ARMMCExpr::VK_ARM_HI16;
4826 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4831 if (getLexer().isNot(AsmToken::Colon)) {
4832 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4835 Parser.Lex(); // Eat the last ':'
4839 /// \brief Given a mnemonic, split out possible predication code and carry
4840 /// setting letters to form a canonical mnemonic and flags.
4842 // FIXME: Would be nice to autogen this.
4843 // FIXME: This is a bit of a maze of special cases.
4844 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4845 unsigned &PredicationCode,
4847 unsigned &ProcessorIMod,
4848 StringRef &ITMask) {
4849 PredicationCode = ARMCC::AL;
4850 CarrySetting = false;
4853 // Ignore some mnemonics we know aren't predicated forms.
4855 // FIXME: Would be nice to autogen this.
4856 if ((Mnemonic == "movs" && isThumb()) ||
4857 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4858 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4859 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4860 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4861 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
4862 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4863 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4864 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4865 Mnemonic == "fmuls")
4868 // First, split out any predication code. Ignore mnemonics we know aren't
4869 // predicated but do have a carry-set and so weren't caught above.
4870 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4871 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4872 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4873 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4874 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4875 .Case("eq", ARMCC::EQ)
4876 .Case("ne", ARMCC::NE)
4877 .Case("hs", ARMCC::HS)
4878 .Case("cs", ARMCC::HS)
4879 .Case("lo", ARMCC::LO)
4880 .Case("cc", ARMCC::LO)
4881 .Case("mi", ARMCC::MI)
4882 .Case("pl", ARMCC::PL)
4883 .Case("vs", ARMCC::VS)
4884 .Case("vc", ARMCC::VC)
4885 .Case("hi", ARMCC::HI)
4886 .Case("ls", ARMCC::LS)
4887 .Case("ge", ARMCC::GE)
4888 .Case("lt", ARMCC::LT)
4889 .Case("gt", ARMCC::GT)
4890 .Case("le", ARMCC::LE)
4891 .Case("al", ARMCC::AL)
4894 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4895 PredicationCode = CC;
4899 // Next, determine if we have a carry setting bit. We explicitly ignore all
4900 // the instructions we know end in 's'.
4901 if (Mnemonic.endswith("s") &&
4902 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4903 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4904 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4905 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4906 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4907 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4908 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4909 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4910 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4911 (Mnemonic == "movs" && isThumb()))) {
4912 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4913 CarrySetting = true;
4916 // The "cps" instruction can have a interrupt mode operand which is glued into
4917 // the mnemonic. Check if this is the case, split it and parse the imod op
4918 if (Mnemonic.startswith("cps")) {
4919 // Split out any imod code.
4921 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4922 .Case("ie", ARM_PROC::IE)
4923 .Case("id", ARM_PROC::ID)
4926 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4927 ProcessorIMod = IMod;
4931 // The "it" instruction has the condition mask on the end of the mnemonic.
4932 if (Mnemonic.startswith("it")) {
4933 ITMask = Mnemonic.slice(2, Mnemonic.size());
4934 Mnemonic = Mnemonic.slice(0, 2);
4940 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4941 /// inclusion of carry set or predication code operands.
4943 // FIXME: It would be nice to autogen this.
4945 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
4946 bool &CanAcceptPredicationCode) {
4947 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4948 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4949 Mnemonic == "add" || Mnemonic == "adc" ||
4950 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4951 Mnemonic == "orr" || Mnemonic == "mvn" ||
4952 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4953 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4954 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4955 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4956 Mnemonic == "mla" || Mnemonic == "smlal" ||
4957 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4958 CanAcceptCarrySet = true;
4960 CanAcceptCarrySet = false;
4962 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4963 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4964 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4965 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
4966 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4967 (Mnemonic == "clrex" && !isThumb()) ||
4968 (Mnemonic == "nop" && isThumbOne()) ||
4969 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4970 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4971 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
4972 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4974 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
4975 CanAcceptPredicationCode = false;
4977 CanAcceptPredicationCode = true;
4980 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
4981 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
4982 CanAcceptPredicationCode = false;
4986 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4987 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4988 // FIXME: This is all horribly hacky. We really need a better way to deal
4989 // with optional operands like this in the matcher table.
4991 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4992 // another does not. Specifically, the MOVW instruction does not. So we
4993 // special case it here and remove the defaulted (non-setting) cc_out
4994 // operand if that's the instruction we're trying to match.
4996 // We do this as post-processing of the explicit operands rather than just
4997 // conditionally adding the cc_out in the first place because we need
4998 // to check the type of the parsed immediate operand.
4999 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
5000 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
5001 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
5002 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5005 // Register-register 'add' for thumb does not have a cc_out operand
5006 // when there are only two register operands.
5007 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
5008 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5009 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5010 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5012 // Register-register 'add' for thumb does not have a cc_out operand
5013 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5014 // have to check the immediate range here since Thumb2 has a variant
5015 // that can handle a different range and has a cc_out operand.
5016 if (((isThumb() && Mnemonic == "add") ||
5017 (isThumbTwo() && Mnemonic == "sub")) &&
5018 Operands.size() == 6 &&
5019 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5020 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5021 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
5022 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5023 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
5024 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
5026 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5027 // imm0_4095 variant. That's the least-preferred variant when
5028 // selecting via the generic "add" mnemonic, so to know that we
5029 // should remove the cc_out operand, we have to explicitly check that
5030 // it's not one of the other variants. Ugh.
5031 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5032 Operands.size() == 6 &&
5033 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5034 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5035 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5036 // Nest conditions rather than one big 'if' statement for readability.
5038 // If either register is a high reg, it's either one of the SP
5039 // variants (handled above) or a 32-bit encoding, so we just
5040 // check against T3. If the second register is the PC, this is an
5041 // alternate form of ADR, which uses encoding T4, so check for that too.
5042 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5043 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
5044 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5045 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5047 // If both registers are low, we're in an IT block, and the immediate is
5048 // in range, we should use encoding T1 instead, which has a cc_out.
5050 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5051 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5052 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5055 // Otherwise, we use encoding T4, which does not have a cc_out
5060 // The thumb2 multiply instruction doesn't have a CCOut register, so
5061 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5062 // use the 16-bit encoding or not.
5063 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5064 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5065 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5066 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5067 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5068 // If the registers aren't low regs, the destination reg isn't the
5069 // same as one of the source regs, or the cc_out operand is zero
5070 // outside of an IT block, we have to use the 32-bit encoding, so
5071 // remove the cc_out operand.
5072 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5073 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5074 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
5076 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5077 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5078 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5079 static_cast<ARMOperand*>(Operands[4])->getReg())))
5082 // Also check the 'mul' syntax variant that doesn't specify an explicit
5083 // destination register.
5084 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5085 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5086 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5087 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5088 // If the registers aren't low regs or the cc_out operand is zero
5089 // outside of an IT block, we have to use the 32-bit encoding, so
5090 // remove the cc_out operand.
5091 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5092 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5098 // Register-register 'add/sub' for thumb does not have a cc_out operand
5099 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5100 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5101 // right, this will result in better diagnostics (which operand is off)
5103 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5104 (Operands.size() == 5 || Operands.size() == 6) &&
5105 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5106 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
5107 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5108 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5109 (Operands.size() == 6 &&
5110 static_cast<ARMOperand*>(Operands[5])->isImm())))
5116 static bool isDataTypeToken(StringRef Tok) {
5117 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5118 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5119 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5120 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5121 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5122 Tok == ".f" || Tok == ".d";
5125 // FIXME: This bit should probably be handled via an explicit match class
5126 // in the .td files that matches the suffix instead of having it be
5127 // a literal string token the way it is now.
5128 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5129 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5131 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5132 unsigned VariantID);
5133 /// Parse an arm instruction mnemonic followed by its operands.
5134 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5136 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5137 // Apply mnemonic aliases before doing anything else, as the destination
5138 // mnemnonic may include suffices and we want to handle them normally.
5139 // The generic tblgen'erated code does this later, at the start of
5140 // MatchInstructionImpl(), but that's too late for aliases that include
5141 // any sort of suffix.
5142 unsigned AvailableFeatures = getAvailableFeatures();
5143 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5144 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5146 // First check for the ARM-specific .req directive.
5147 if (Parser.getTok().is(AsmToken::Identifier) &&
5148 Parser.getTok().getIdentifier() == ".req") {
5149 parseDirectiveReq(Name, NameLoc);
5150 // We always return 'error' for this, as we're done with this
5151 // statement and don't need to match the 'instruction."
5155 // Create the leading tokens for the mnemonic, split by '.' characters.
5156 size_t Start = 0, Next = Name.find('.');
5157 StringRef Mnemonic = Name.slice(Start, Next);
5159 // Split out the predication code and carry setting flag from the mnemonic.
5160 unsigned PredicationCode;
5161 unsigned ProcessorIMod;
5164 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5165 ProcessorIMod, ITMask);
5167 // In Thumb1, only the branch (B) instruction can be predicated.
5168 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5169 Parser.eatToEndOfStatement();
5170 return Error(NameLoc, "conditional execution not supported in Thumb1");
5173 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5175 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5176 // is the mask as it will be for the IT encoding if the conditional
5177 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5178 // where the conditional bit0 is zero, the instruction post-processing
5179 // will adjust the mask accordingly.
5180 if (Mnemonic == "it") {
5181 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5182 if (ITMask.size() > 3) {
5183 Parser.eatToEndOfStatement();
5184 return Error(Loc, "too many conditions on IT instruction");
5187 for (unsigned i = ITMask.size(); i != 0; --i) {
5188 char pos = ITMask[i - 1];
5189 if (pos != 't' && pos != 'e') {
5190 Parser.eatToEndOfStatement();
5191 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5194 if (ITMask[i - 1] == 't')
5197 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5200 // FIXME: This is all a pretty gross hack. We should automatically handle
5201 // optional operands like this via tblgen.
5203 // Next, add the CCOut and ConditionCode operands, if needed.
5205 // For mnemonics which can ever incorporate a carry setting bit or predication
5206 // code, our matching model involves us always generating CCOut and
5207 // ConditionCode operands to match the mnemonic "as written" and then we let
5208 // the matcher deal with finding the right instruction or generating an
5209 // appropriate error.
5210 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5211 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
5213 // If we had a carry-set on an instruction that can't do that, issue an
5215 if (!CanAcceptCarrySet && CarrySetting) {
5216 Parser.eatToEndOfStatement();
5217 return Error(NameLoc, "instruction '" + Mnemonic +
5218 "' can not set flags, but 's' suffix specified");
5220 // If we had a predication code on an instruction that can't do that, issue an
5222 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5223 Parser.eatToEndOfStatement();
5224 return Error(NameLoc, "instruction '" + Mnemonic +
5225 "' is not predicable, but condition code specified");
5228 // Add the carry setting operand, if necessary.
5229 if (CanAcceptCarrySet) {
5230 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5231 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5235 // Add the predication code operand, if necessary.
5236 if (CanAcceptPredicationCode) {
5237 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5239 Operands.push_back(ARMOperand::CreateCondCode(
5240 ARMCC::CondCodes(PredicationCode), Loc));
5243 // Add the processor imod operand, if necessary.
5244 if (ProcessorIMod) {
5245 Operands.push_back(ARMOperand::CreateImm(
5246 MCConstantExpr::Create(ProcessorIMod, getContext()),
5250 // Add the remaining tokens in the mnemonic.
5251 while (Next != StringRef::npos) {
5253 Next = Name.find('.', Start + 1);
5254 StringRef ExtraToken = Name.slice(Start, Next);
5256 // Some NEON instructions have an optional datatype suffix that is
5257 // completely ignored. Check for that.
5258 if (isDataTypeToken(ExtraToken) &&
5259 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5262 if (ExtraToken != ".n") {
5263 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5264 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5268 // Read the remaining operands.
5269 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5270 // Read the first operand.
5271 if (parseOperand(Operands, Mnemonic)) {
5272 Parser.eatToEndOfStatement();
5276 while (getLexer().is(AsmToken::Comma)) {
5277 Parser.Lex(); // Eat the comma.
5279 // Parse and remember the operand.
5280 if (parseOperand(Operands, Mnemonic)) {
5281 Parser.eatToEndOfStatement();
5287 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5288 SMLoc Loc = getLexer().getLoc();
5289 Parser.eatToEndOfStatement();
5290 return Error(Loc, "unexpected token in argument list");
5293 Parser.Lex(); // Consume the EndOfStatement
5295 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5296 // do and don't have a cc_out optional-def operand. With some spot-checks
5297 // of the operand list, we can figure out which variant we're trying to
5298 // parse and adjust accordingly before actually matching. We shouldn't ever
5299 // try to remove a cc_out operand that was explicitly set on the the
5300 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5301 // table driven matcher doesn't fit well with the ARM instruction set.
5302 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5303 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5304 Operands.erase(Operands.begin() + 1);
5308 // ARM mode 'blx' need special handling, as the register operand version
5309 // is predicable, but the label operand version is not. So, we can't rely
5310 // on the Mnemonic based checking to correctly figure out when to put
5311 // a k_CondCode operand in the list. If we're trying to match the label
5312 // version, remove the k_CondCode operand here.
5313 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5314 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5315 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5316 Operands.erase(Operands.begin() + 1);
5320 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5321 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5322 // a single GPRPair reg operand is used in the .td file to replace the two
5323 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5324 // expressed as a GPRPair, so we have to manually merge them.
5325 // FIXME: We would really like to be able to tablegen'erate this.
5326 if (!isThumb() && Operands.size() > 4 &&
5327 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5328 bool isLoad = (Mnemonic == "ldrexd");
5329 unsigned Idx = isLoad ? 2 : 3;
5330 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5331 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5333 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5334 // Adjust only if Op1 and Op2 are GPRs.
5335 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5336 MRC.contains(Op2->getReg())) {
5337 unsigned Reg1 = Op1->getReg();
5338 unsigned Reg2 = Op2->getReg();
5339 unsigned Rt = MRI->getEncodingValue(Reg1);
5340 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5342 // Rt2 must be Rt + 1 and Rt must be even.
5343 if (Rt + 1 != Rt2 || (Rt & 1)) {
5344 Error(Op2->getStartLoc(), isLoad ?
5345 "destination operands must be sequential" :
5346 "source operands must be sequential");
5349 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5350 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5351 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5352 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5353 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5362 // Validate context-sensitive operand constraints.
5364 // return 'true' if register list contains non-low GPR registers,
5365 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5366 // 'containsReg' to true.
5367 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5368 unsigned HiReg, bool &containsReg) {
5369 containsReg = false;
5370 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5371 unsigned OpReg = Inst.getOperand(i).getReg();
5374 // Anything other than a low register isn't legal here.
5375 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5381 // Check if the specified regisgter is in the register list of the inst,
5382 // starting at the indicated operand number.
5383 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5384 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5385 unsigned OpReg = Inst.getOperand(i).getReg();
5392 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5393 // the ARMInsts array) instead. Getting that here requires awkward
5394 // API changes, though. Better way?
5396 extern const MCInstrDesc ARMInsts[];
5398 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
5399 return ARMInsts[Opcode];
5402 // FIXME: We would really like to be able to tablegen'erate this.
5404 validateInstruction(MCInst &Inst,
5405 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5406 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
5407 SMLoc Loc = Operands[0]->getStartLoc();
5408 // Check the IT block state first.
5409 // NOTE: BKPT instruction has the interesting property of being
5410 // allowed in IT blocks, but not being predicable. It just always
5412 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5413 Inst.getOpcode() != ARM::BKPT) {
5415 if (ITState.FirstCond)
5416 ITState.FirstCond = false;
5418 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5419 // The instruction must be predicable.
5420 if (!MCID.isPredicable())
5421 return Error(Loc, "instructions in IT block must be predicable");
5422 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5423 unsigned ITCond = bit ? ITState.Cond :
5424 ARMCC::getOppositeCondition(ITState.Cond);
5425 if (Cond != ITCond) {
5426 // Find the condition code Operand to get its SMLoc information.
5428 for (unsigned i = 1; i < Operands.size(); ++i)
5429 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5430 CondLoc = Operands[i]->getStartLoc();
5431 return Error(CondLoc, "incorrect condition in IT block; got '" +
5432 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5433 "', but expected '" +
5434 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5436 // Check for non-'al' condition codes outside of the IT block.
5437 } else if (isThumbTwo() && MCID.isPredicable() &&
5438 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5439 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5440 Inst.getOpcode() != ARM::t2B)
5441 return Error(Loc, "predicated instructions must be in IT block");
5443 switch (Inst.getOpcode()) {
5446 case ARM::LDRD_POST: {
5447 // Rt2 must be Rt + 1.
5448 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5449 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5451 return Error(Operands[3]->getStartLoc(),
5452 "destination operands must be sequential");
5456 // Rt2 must be Rt + 1.
5457 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5458 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5460 return Error(Operands[3]->getStartLoc(),
5461 "source operands must be sequential");
5465 case ARM::STRD_POST: {
5466 // Rt2 must be Rt + 1.
5467 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5468 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5470 return Error(Operands[3]->getStartLoc(),
5471 "source operands must be sequential");
5476 // width must be in range [1, 32-lsb]
5477 unsigned lsb = Inst.getOperand(2).getImm();
5478 unsigned widthm1 = Inst.getOperand(3).getImm();
5479 if (widthm1 >= 32 - lsb)
5480 return Error(Operands[5]->getStartLoc(),
5481 "bitfield width must be in range [1,32-lsb]");
5485 // If we're parsing Thumb2, the .w variant is available and handles
5486 // most cases that are normally illegal for a Thumb1 LDM
5487 // instruction. We'll make the transformation in processInstruction()
5490 // Thumb LDM instructions are writeback iff the base register is not
5491 // in the register list.
5492 unsigned Rn = Inst.getOperand(0).getReg();
5493 bool hasWritebackToken =
5494 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5495 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5496 bool listContainsBase;
5497 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5498 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5499 "registers must be in range r0-r7");
5500 // If we should have writeback, then there should be a '!' token.
5501 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5502 return Error(Operands[2]->getStartLoc(),
5503 "writeback operator '!' expected");
5504 // If we should not have writeback, there must not be a '!'. This is
5505 // true even for the 32-bit wide encodings.
5506 if (listContainsBase && hasWritebackToken)
5507 return Error(Operands[3]->getStartLoc(),
5508 "writeback operator '!' not allowed when base register "
5509 "in register list");
5513 case ARM::t2LDMIA_UPD: {
5514 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5515 return Error(Operands[4]->getStartLoc(),
5516 "writeback operator '!' not allowed when base register "
5517 "in register list");
5521 // The second source operand must be the same register as the destination
5524 // In this case, we must directly check the parsed operands because the
5525 // cvtThumbMultiply() function is written in such a way that it guarantees
5526 // this first statement is always true for the new Inst. Essentially, the
5527 // destination is unconditionally copied into the second source operand
5528 // without checking to see if it matches what we actually parsed.
5529 if (Operands.size() == 6 &&
5530 (((ARMOperand*)Operands[3])->getReg() !=
5531 ((ARMOperand*)Operands[5])->getReg()) &&
5532 (((ARMOperand*)Operands[3])->getReg() !=
5533 ((ARMOperand*)Operands[4])->getReg())) {
5534 return Error(Operands[3]->getStartLoc(),
5535 "destination register must match source register");
5539 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5540 // so only issue a diagnostic for thumb1. The instructions will be
5541 // switched to the t2 encodings in processInstruction() if necessary.
5543 bool listContainsBase;
5544 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5546 return Error(Operands[2]->getStartLoc(),
5547 "registers must be in range r0-r7 or pc");
5551 bool listContainsBase;
5552 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5554 return Error(Operands[2]->getStartLoc(),
5555 "registers must be in range r0-r7 or lr");
5558 case ARM::tSTMIA_UPD: {
5559 bool listContainsBase;
5560 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5561 return Error(Operands[4]->getStartLoc(),
5562 "registers must be in range r0-r7");
5565 case ARM::tADDrSP: {
5566 // If the non-SP source operand and the destination operand are not the
5567 // same, we need thumb2 (for the wide encoding), or we have an error.
5568 if (!isThumbTwo() &&
5569 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5570 return Error(Operands[4]->getStartLoc(),
5571 "source register must be the same as destination");
5580 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5582 default: llvm_unreachable("unexpected opcode!");
5584 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5585 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5586 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5587 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5588 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5589 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5590 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5591 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5592 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5595 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5596 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5597 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5598 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5599 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5601 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5602 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5603 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5604 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5605 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5607 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5608 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5609 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5610 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5611 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5614 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5615 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5616 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5617 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5618 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5619 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5620 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5621 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5622 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5623 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5624 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5625 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5626 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5627 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5628 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5631 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5632 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5633 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5634 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5635 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5636 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5637 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5638 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5639 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5640 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5641 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5642 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5643 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5644 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5645 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5646 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5647 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5648 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5651 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5652 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5653 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5654 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5655 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5656 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5657 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5658 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5659 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5660 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5661 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5662 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5663 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5664 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5665 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5668 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5669 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5670 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5671 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5672 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5673 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5674 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5675 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5676 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5677 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5678 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5679 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5680 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5681 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5682 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5683 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5684 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5685 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5689 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5691 default: llvm_unreachable("unexpected opcode!");
5693 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5694 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5695 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5696 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5697 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5698 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5699 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5700 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5701 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5704 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5705 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5706 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5707 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5708 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5709 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5710 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5711 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5712 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5713 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5714 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5715 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5716 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5717 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5718 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5721 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5722 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5723 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5724 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5725 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5726 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5727 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5728 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5729 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5730 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5731 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5732 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5733 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5734 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5735 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5736 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5737 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5738 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5741 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5742 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5743 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5744 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5745 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5746 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5747 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5748 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5749 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5750 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5751 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5752 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5753 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5754 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5755 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5758 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5759 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5760 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5761 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5762 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5763 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5764 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5765 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5766 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5767 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5768 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5769 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5770 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5771 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5772 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5773 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5774 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5775 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5778 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5779 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5780 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5781 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5782 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5783 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5784 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5785 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5786 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5787 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5788 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5789 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5790 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5791 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5792 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5795 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5796 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5797 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5798 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5799 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5800 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5801 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5802 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5803 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5804 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5805 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5806 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5807 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5808 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5809 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5810 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5811 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5812 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5815 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5816 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5817 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5818 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5819 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5820 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5821 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5822 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5823 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5824 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5825 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5826 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5827 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5828 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5829 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5830 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5831 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5832 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5837 processInstruction(MCInst &Inst,
5838 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5839 switch (Inst.getOpcode()) {
5840 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5842 if (Inst.getOperand(1).getReg() != ARM::PC ||
5843 Inst.getOperand(5).getReg() != 0)
5846 TmpInst.setOpcode(ARM::ADR);
5847 TmpInst.addOperand(Inst.getOperand(0));
5848 TmpInst.addOperand(Inst.getOperand(2));
5849 TmpInst.addOperand(Inst.getOperand(3));
5850 TmpInst.addOperand(Inst.getOperand(4));
5854 // Aliases for alternate PC+imm syntax of LDR instructions.
5855 case ARM::t2LDRpcrel:
5856 // Select the narrow version if the immediate will fit.
5857 if (Inst.getOperand(1).getImm() > 0 &&
5858 Inst.getOperand(1).getImm() <= 0xff)
5859 Inst.setOpcode(ARM::tLDRpci);
5861 Inst.setOpcode(ARM::t2LDRpci);
5863 case ARM::t2LDRBpcrel:
5864 Inst.setOpcode(ARM::t2LDRBpci);
5866 case ARM::t2LDRHpcrel:
5867 Inst.setOpcode(ARM::t2LDRHpci);
5869 case ARM::t2LDRSBpcrel:
5870 Inst.setOpcode(ARM::t2LDRSBpci);
5872 case ARM::t2LDRSHpcrel:
5873 Inst.setOpcode(ARM::t2LDRSHpci);
5875 // Handle NEON VST complex aliases.
5876 case ARM::VST1LNdWB_register_Asm_8:
5877 case ARM::VST1LNdWB_register_Asm_16:
5878 case ARM::VST1LNdWB_register_Asm_32: {
5880 // Shuffle the operands around so the lane index operand is in the
5883 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5884 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5885 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5886 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5887 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5888 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5889 TmpInst.addOperand(Inst.getOperand(1)); // lane
5890 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5891 TmpInst.addOperand(Inst.getOperand(6));
5896 case ARM::VST2LNdWB_register_Asm_8:
5897 case ARM::VST2LNdWB_register_Asm_16:
5898 case ARM::VST2LNdWB_register_Asm_32:
5899 case ARM::VST2LNqWB_register_Asm_16:
5900 case ARM::VST2LNqWB_register_Asm_32: {
5902 // Shuffle the operands around so the lane index operand is in the
5905 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5906 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5907 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5908 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5909 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5910 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5911 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5913 TmpInst.addOperand(Inst.getOperand(1)); // lane
5914 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5915 TmpInst.addOperand(Inst.getOperand(6));
5920 case ARM::VST3LNdWB_register_Asm_8:
5921 case ARM::VST3LNdWB_register_Asm_16:
5922 case ARM::VST3LNdWB_register_Asm_32:
5923 case ARM::VST3LNqWB_register_Asm_16:
5924 case ARM::VST3LNqWB_register_Asm_32: {
5926 // Shuffle the operands around so the lane index operand is in the
5929 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5930 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5931 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5932 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5933 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5934 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5935 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5937 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5939 TmpInst.addOperand(Inst.getOperand(1)); // lane
5940 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5941 TmpInst.addOperand(Inst.getOperand(6));
5946 case ARM::VST4LNdWB_register_Asm_8:
5947 case ARM::VST4LNdWB_register_Asm_16:
5948 case ARM::VST4LNdWB_register_Asm_32:
5949 case ARM::VST4LNqWB_register_Asm_16:
5950 case ARM::VST4LNqWB_register_Asm_32: {
5952 // Shuffle the operands around so the lane index operand is in the
5955 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5956 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5957 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5958 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5959 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5960 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5961 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5963 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5965 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5967 TmpInst.addOperand(Inst.getOperand(1)); // lane
5968 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5969 TmpInst.addOperand(Inst.getOperand(6));
5974 case ARM::VST1LNdWB_fixed_Asm_8:
5975 case ARM::VST1LNdWB_fixed_Asm_16:
5976 case ARM::VST1LNdWB_fixed_Asm_32: {
5978 // Shuffle the operands around so the lane index operand is in the
5981 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5982 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5983 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5984 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5985 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5986 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5987 TmpInst.addOperand(Inst.getOperand(1)); // lane
5988 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5989 TmpInst.addOperand(Inst.getOperand(5));
5994 case ARM::VST2LNdWB_fixed_Asm_8:
5995 case ARM::VST2LNdWB_fixed_Asm_16:
5996 case ARM::VST2LNdWB_fixed_Asm_32:
5997 case ARM::VST2LNqWB_fixed_Asm_16:
5998 case ARM::VST2LNqWB_fixed_Asm_32: {
6000 // Shuffle the operands around so the lane index operand is in the
6003 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6004 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6005 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6006 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6007 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6008 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6009 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6011 TmpInst.addOperand(Inst.getOperand(1)); // lane
6012 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6013 TmpInst.addOperand(Inst.getOperand(5));
6018 case ARM::VST3LNdWB_fixed_Asm_8:
6019 case ARM::VST3LNdWB_fixed_Asm_16:
6020 case ARM::VST3LNdWB_fixed_Asm_32:
6021 case ARM::VST3LNqWB_fixed_Asm_16:
6022 case ARM::VST3LNqWB_fixed_Asm_32: {
6024 // Shuffle the operands around so the lane index operand is in the
6027 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6028 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6029 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6030 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6031 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6032 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6033 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6035 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6037 TmpInst.addOperand(Inst.getOperand(1)); // lane
6038 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6039 TmpInst.addOperand(Inst.getOperand(5));
6044 case ARM::VST4LNdWB_fixed_Asm_8:
6045 case ARM::VST4LNdWB_fixed_Asm_16:
6046 case ARM::VST4LNdWB_fixed_Asm_32:
6047 case ARM::VST4LNqWB_fixed_Asm_16:
6048 case ARM::VST4LNqWB_fixed_Asm_32: {
6050 // Shuffle the operands around so the lane index operand is in the
6053 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6054 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6055 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6056 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6057 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6058 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6059 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6061 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6063 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6065 TmpInst.addOperand(Inst.getOperand(1)); // lane
6066 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6067 TmpInst.addOperand(Inst.getOperand(5));
6072 case ARM::VST1LNdAsm_8:
6073 case ARM::VST1LNdAsm_16:
6074 case ARM::VST1LNdAsm_32: {
6076 // Shuffle the operands around so the lane index operand is in the
6079 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6080 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6081 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6082 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6083 TmpInst.addOperand(Inst.getOperand(1)); // lane
6084 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6085 TmpInst.addOperand(Inst.getOperand(5));
6090 case ARM::VST2LNdAsm_8:
6091 case ARM::VST2LNdAsm_16:
6092 case ARM::VST2LNdAsm_32:
6093 case ARM::VST2LNqAsm_16:
6094 case ARM::VST2LNqAsm_32: {
6096 // Shuffle the operands around so the lane index operand is in the
6099 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6100 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6101 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6102 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6103 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6105 TmpInst.addOperand(Inst.getOperand(1)); // lane
6106 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6107 TmpInst.addOperand(Inst.getOperand(5));
6112 case ARM::VST3LNdAsm_8:
6113 case ARM::VST3LNdAsm_16:
6114 case ARM::VST3LNdAsm_32:
6115 case ARM::VST3LNqAsm_16:
6116 case ARM::VST3LNqAsm_32: {
6118 // Shuffle the operands around so the lane index operand is in the
6121 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6122 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6123 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6124 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6125 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6127 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6129 TmpInst.addOperand(Inst.getOperand(1)); // lane
6130 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6131 TmpInst.addOperand(Inst.getOperand(5));
6136 case ARM::VST4LNdAsm_8:
6137 case ARM::VST4LNdAsm_16:
6138 case ARM::VST4LNdAsm_32:
6139 case ARM::VST4LNqAsm_16:
6140 case ARM::VST4LNqAsm_32: {
6142 // Shuffle the operands around so the lane index operand is in the
6145 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6146 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6147 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6148 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6149 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6151 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6153 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6155 TmpInst.addOperand(Inst.getOperand(1)); // lane
6156 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6157 TmpInst.addOperand(Inst.getOperand(5));
6162 // Handle NEON VLD complex aliases.
6163 case ARM::VLD1LNdWB_register_Asm_8:
6164 case ARM::VLD1LNdWB_register_Asm_16:
6165 case ARM::VLD1LNdWB_register_Asm_32: {
6167 // Shuffle the operands around so the lane index operand is in the
6170 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6171 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6172 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6173 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6174 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6175 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6176 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6177 TmpInst.addOperand(Inst.getOperand(1)); // lane
6178 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6179 TmpInst.addOperand(Inst.getOperand(6));
6184 case ARM::VLD2LNdWB_register_Asm_8:
6185 case ARM::VLD2LNdWB_register_Asm_16:
6186 case ARM::VLD2LNdWB_register_Asm_32:
6187 case ARM::VLD2LNqWB_register_Asm_16:
6188 case ARM::VLD2LNqWB_register_Asm_32: {
6190 // Shuffle the operands around so the lane index operand is in the
6193 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6194 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6195 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6197 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6198 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6199 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6200 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6201 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6202 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6204 TmpInst.addOperand(Inst.getOperand(1)); // lane
6205 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6206 TmpInst.addOperand(Inst.getOperand(6));
6211 case ARM::VLD3LNdWB_register_Asm_8:
6212 case ARM::VLD3LNdWB_register_Asm_16:
6213 case ARM::VLD3LNdWB_register_Asm_32:
6214 case ARM::VLD3LNqWB_register_Asm_16:
6215 case ARM::VLD3LNqWB_register_Asm_32: {
6217 // Shuffle the operands around so the lane index operand is in the
6220 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6221 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6222 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6224 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6226 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6227 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6228 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6229 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6230 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6231 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6233 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6235 TmpInst.addOperand(Inst.getOperand(1)); // lane
6236 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6237 TmpInst.addOperand(Inst.getOperand(6));
6242 case ARM::VLD4LNdWB_register_Asm_8:
6243 case ARM::VLD4LNdWB_register_Asm_16:
6244 case ARM::VLD4LNdWB_register_Asm_32:
6245 case ARM::VLD4LNqWB_register_Asm_16:
6246 case ARM::VLD4LNqWB_register_Asm_32: {
6248 // Shuffle the operands around so the lane index operand is in the
6251 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6252 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6253 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6255 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6257 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6259 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6260 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6261 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6262 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6263 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6264 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6266 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6268 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6270 TmpInst.addOperand(Inst.getOperand(1)); // lane
6271 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6272 TmpInst.addOperand(Inst.getOperand(6));
6277 case ARM::VLD1LNdWB_fixed_Asm_8:
6278 case ARM::VLD1LNdWB_fixed_Asm_16:
6279 case ARM::VLD1LNdWB_fixed_Asm_32: {
6281 // Shuffle the operands around so the lane index operand is in the
6284 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6285 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6286 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6287 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6288 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6289 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6290 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6291 TmpInst.addOperand(Inst.getOperand(1)); // lane
6292 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6293 TmpInst.addOperand(Inst.getOperand(5));
6298 case ARM::VLD2LNdWB_fixed_Asm_8:
6299 case ARM::VLD2LNdWB_fixed_Asm_16:
6300 case ARM::VLD2LNdWB_fixed_Asm_32:
6301 case ARM::VLD2LNqWB_fixed_Asm_16:
6302 case ARM::VLD2LNqWB_fixed_Asm_32: {
6304 // Shuffle the operands around so the lane index operand is in the
6307 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6308 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6309 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6311 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6312 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6313 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6314 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6315 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6316 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6318 TmpInst.addOperand(Inst.getOperand(1)); // lane
6319 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6320 TmpInst.addOperand(Inst.getOperand(5));
6325 case ARM::VLD3LNdWB_fixed_Asm_8:
6326 case ARM::VLD3LNdWB_fixed_Asm_16:
6327 case ARM::VLD3LNdWB_fixed_Asm_32:
6328 case ARM::VLD3LNqWB_fixed_Asm_16:
6329 case ARM::VLD3LNqWB_fixed_Asm_32: {
6331 // Shuffle the operands around so the lane index operand is in the
6334 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6335 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6336 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6338 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6340 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6341 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6342 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6343 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6344 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6347 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6349 TmpInst.addOperand(Inst.getOperand(1)); // lane
6350 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6351 TmpInst.addOperand(Inst.getOperand(5));
6356 case ARM::VLD4LNdWB_fixed_Asm_8:
6357 case ARM::VLD4LNdWB_fixed_Asm_16:
6358 case ARM::VLD4LNdWB_fixed_Asm_32:
6359 case ARM::VLD4LNqWB_fixed_Asm_16:
6360 case ARM::VLD4LNqWB_fixed_Asm_32: {
6362 // Shuffle the operands around so the lane index operand is in the
6365 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6366 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6367 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6369 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6371 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6373 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6374 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6375 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6376 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6377 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6378 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6380 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6382 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6384 TmpInst.addOperand(Inst.getOperand(1)); // lane
6385 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6386 TmpInst.addOperand(Inst.getOperand(5));
6391 case ARM::VLD1LNdAsm_8:
6392 case ARM::VLD1LNdAsm_16:
6393 case ARM::VLD1LNdAsm_32: {
6395 // Shuffle the operands around so the lane index operand is in the
6398 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6399 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6400 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6401 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6402 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6403 TmpInst.addOperand(Inst.getOperand(1)); // lane
6404 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6405 TmpInst.addOperand(Inst.getOperand(5));
6410 case ARM::VLD2LNdAsm_8:
6411 case ARM::VLD2LNdAsm_16:
6412 case ARM::VLD2LNdAsm_32:
6413 case ARM::VLD2LNqAsm_16:
6414 case ARM::VLD2LNqAsm_32: {
6416 // Shuffle the operands around so the lane index operand is in the
6419 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6420 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6421 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6423 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6424 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6425 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6426 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6428 TmpInst.addOperand(Inst.getOperand(1)); // lane
6429 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6430 TmpInst.addOperand(Inst.getOperand(5));
6435 case ARM::VLD3LNdAsm_8:
6436 case ARM::VLD3LNdAsm_16:
6437 case ARM::VLD3LNdAsm_32:
6438 case ARM::VLD3LNqAsm_16:
6439 case ARM::VLD3LNqAsm_32: {
6441 // Shuffle the operands around so the lane index operand is in the
6444 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6445 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6446 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6448 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6450 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6451 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6452 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6453 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6455 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6457 TmpInst.addOperand(Inst.getOperand(1)); // lane
6458 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6459 TmpInst.addOperand(Inst.getOperand(5));
6464 case ARM::VLD4LNdAsm_8:
6465 case ARM::VLD4LNdAsm_16:
6466 case ARM::VLD4LNdAsm_32:
6467 case ARM::VLD4LNqAsm_16:
6468 case ARM::VLD4LNqAsm_32: {
6470 // Shuffle the operands around so the lane index operand is in the
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(2)); // Rn
6482 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6483 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6484 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6486 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6488 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6490 TmpInst.addOperand(Inst.getOperand(1)); // lane
6491 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6492 TmpInst.addOperand(Inst.getOperand(5));
6497 // VLD3DUP single 3-element structure to all lanes instructions.
6498 case ARM::VLD3DUPdAsm_8:
6499 case ARM::VLD3DUPdAsm_16:
6500 case ARM::VLD3DUPdAsm_32:
6501 case ARM::VLD3DUPqAsm_8:
6502 case ARM::VLD3DUPqAsm_16:
6503 case ARM::VLD3DUPqAsm_32: {
6506 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6507 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6508 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6510 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6512 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6513 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6514 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6515 TmpInst.addOperand(Inst.getOperand(4));
6520 case ARM::VLD3DUPdWB_fixed_Asm_8:
6521 case ARM::VLD3DUPdWB_fixed_Asm_16:
6522 case ARM::VLD3DUPdWB_fixed_Asm_32:
6523 case ARM::VLD3DUPqWB_fixed_Asm_8:
6524 case ARM::VLD3DUPqWB_fixed_Asm_16:
6525 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6528 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6529 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6534 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6535 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6536 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6537 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6538 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6539 TmpInst.addOperand(Inst.getOperand(4));
6544 case ARM::VLD3DUPdWB_register_Asm_8:
6545 case ARM::VLD3DUPdWB_register_Asm_16:
6546 case ARM::VLD3DUPdWB_register_Asm_32:
6547 case ARM::VLD3DUPqWB_register_Asm_8:
6548 case ARM::VLD3DUPqWB_register_Asm_16:
6549 case ARM::VLD3DUPqWB_register_Asm_32: {
6552 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6553 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6556 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6558 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6559 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6560 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6561 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6562 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6563 TmpInst.addOperand(Inst.getOperand(5));
6568 // VLD3 multiple 3-element structure instructions.
6569 case ARM::VLD3dAsm_8:
6570 case ARM::VLD3dAsm_16:
6571 case ARM::VLD3dAsm_32:
6572 case ARM::VLD3qAsm_8:
6573 case ARM::VLD3qAsm_16:
6574 case ARM::VLD3qAsm_32: {
6577 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6578 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6579 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6581 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6583 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6584 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6585 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6586 TmpInst.addOperand(Inst.getOperand(4));
6591 case ARM::VLD3dWB_fixed_Asm_8:
6592 case ARM::VLD3dWB_fixed_Asm_16:
6593 case ARM::VLD3dWB_fixed_Asm_32:
6594 case ARM::VLD3qWB_fixed_Asm_8:
6595 case ARM::VLD3qWB_fixed_Asm_16:
6596 case ARM::VLD3qWB_fixed_Asm_32: {
6599 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6600 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6601 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6603 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6605 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6606 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6607 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6608 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6609 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6610 TmpInst.addOperand(Inst.getOperand(4));
6615 case ARM::VLD3dWB_register_Asm_8:
6616 case ARM::VLD3dWB_register_Asm_16:
6617 case ARM::VLD3dWB_register_Asm_32:
6618 case ARM::VLD3qWB_register_Asm_8:
6619 case ARM::VLD3qWB_register_Asm_16:
6620 case ARM::VLD3qWB_register_Asm_32: {
6623 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6624 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6625 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6627 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6629 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6630 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6631 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6632 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6633 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6634 TmpInst.addOperand(Inst.getOperand(5));
6639 // VLD4DUP single 3-element structure to all lanes instructions.
6640 case ARM::VLD4DUPdAsm_8:
6641 case ARM::VLD4DUPdAsm_16:
6642 case ARM::VLD4DUPdAsm_32:
6643 case ARM::VLD4DUPqAsm_8:
6644 case ARM::VLD4DUPqAsm_16:
6645 case ARM::VLD4DUPqAsm_32: {
6648 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6649 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6650 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6652 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6654 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6656 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6657 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6658 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6659 TmpInst.addOperand(Inst.getOperand(4));
6664 case ARM::VLD4DUPdWB_fixed_Asm_8:
6665 case ARM::VLD4DUPdWB_fixed_Asm_16:
6666 case ARM::VLD4DUPdWB_fixed_Asm_32:
6667 case ARM::VLD4DUPqWB_fixed_Asm_8:
6668 case ARM::VLD4DUPqWB_fixed_Asm_16:
6669 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6672 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6673 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6678 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6680 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6681 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6682 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6683 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6684 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6685 TmpInst.addOperand(Inst.getOperand(4));
6690 case ARM::VLD4DUPdWB_register_Asm_8:
6691 case ARM::VLD4DUPdWB_register_Asm_16:
6692 case ARM::VLD4DUPdWB_register_Asm_32:
6693 case ARM::VLD4DUPqWB_register_Asm_8:
6694 case ARM::VLD4DUPqWB_register_Asm_16:
6695 case ARM::VLD4DUPqWB_register_Asm_32: {
6698 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6699 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6700 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6702 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6704 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6706 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6707 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6708 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6709 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6710 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6711 TmpInst.addOperand(Inst.getOperand(5));
6716 // VLD4 multiple 4-element structure instructions.
6717 case ARM::VLD4dAsm_8:
6718 case ARM::VLD4dAsm_16:
6719 case ARM::VLD4dAsm_32:
6720 case ARM::VLD4qAsm_8:
6721 case ARM::VLD4qAsm_16:
6722 case ARM::VLD4qAsm_32: {
6725 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6726 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6727 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6729 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6731 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6733 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6734 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6735 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6736 TmpInst.addOperand(Inst.getOperand(4));
6741 case ARM::VLD4dWB_fixed_Asm_8:
6742 case ARM::VLD4dWB_fixed_Asm_16:
6743 case ARM::VLD4dWB_fixed_Asm_32:
6744 case ARM::VLD4qWB_fixed_Asm_8:
6745 case ARM::VLD4qWB_fixed_Asm_16:
6746 case ARM::VLD4qWB_fixed_Asm_32: {
6749 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6750 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6751 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6755 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6757 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6758 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6759 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6760 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6761 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6762 TmpInst.addOperand(Inst.getOperand(4));
6767 case ARM::VLD4dWB_register_Asm_8:
6768 case ARM::VLD4dWB_register_Asm_16:
6769 case ARM::VLD4dWB_register_Asm_32:
6770 case ARM::VLD4qWB_register_Asm_8:
6771 case ARM::VLD4qWB_register_Asm_16:
6772 case ARM::VLD4qWB_register_Asm_32: {
6775 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6776 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6783 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6784 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6785 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6786 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6787 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6788 TmpInst.addOperand(Inst.getOperand(5));
6793 // VST3 multiple 3-element structure instructions.
6794 case ARM::VST3dAsm_8:
6795 case ARM::VST3dAsm_16:
6796 case ARM::VST3dAsm_32:
6797 case ARM::VST3qAsm_8:
6798 case ARM::VST3qAsm_16:
6799 case ARM::VST3qAsm_32: {
6802 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6803 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6804 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6805 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6806 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6808 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6810 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6811 TmpInst.addOperand(Inst.getOperand(4));
6816 case ARM::VST3dWB_fixed_Asm_8:
6817 case ARM::VST3dWB_fixed_Asm_16:
6818 case ARM::VST3dWB_fixed_Asm_32:
6819 case ARM::VST3qWB_fixed_Asm_8:
6820 case ARM::VST3qWB_fixed_Asm_16:
6821 case ARM::VST3qWB_fixed_Asm_32: {
6824 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6825 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6826 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6827 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6828 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6829 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6830 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6832 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6834 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6835 TmpInst.addOperand(Inst.getOperand(4));
6840 case ARM::VST3dWB_register_Asm_8:
6841 case ARM::VST3dWB_register_Asm_16:
6842 case ARM::VST3dWB_register_Asm_32:
6843 case ARM::VST3qWB_register_Asm_8:
6844 case ARM::VST3qWB_register_Asm_16:
6845 case ARM::VST3qWB_register_Asm_32: {
6848 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6849 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6850 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6851 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6852 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6853 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6854 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6856 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6858 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6859 TmpInst.addOperand(Inst.getOperand(5));
6864 // VST4 multiple 3-element structure instructions.
6865 case ARM::VST4dAsm_8:
6866 case ARM::VST4dAsm_16:
6867 case ARM::VST4dAsm_32:
6868 case ARM::VST4qAsm_8:
6869 case ARM::VST4qAsm_16:
6870 case ARM::VST4qAsm_32: {
6873 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6874 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6875 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6876 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6877 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6881 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6883 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6884 TmpInst.addOperand(Inst.getOperand(4));
6889 case ARM::VST4dWB_fixed_Asm_8:
6890 case ARM::VST4dWB_fixed_Asm_16:
6891 case ARM::VST4dWB_fixed_Asm_32:
6892 case ARM::VST4qWB_fixed_Asm_8:
6893 case ARM::VST4qWB_fixed_Asm_16:
6894 case ARM::VST4qWB_fixed_Asm_32: {
6897 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6898 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6899 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6900 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6901 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6902 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6903 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6905 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6907 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6909 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6910 TmpInst.addOperand(Inst.getOperand(4));
6915 case ARM::VST4dWB_register_Asm_8:
6916 case ARM::VST4dWB_register_Asm_16:
6917 case ARM::VST4dWB_register_Asm_32:
6918 case ARM::VST4qWB_register_Asm_8:
6919 case ARM::VST4qWB_register_Asm_16:
6920 case ARM::VST4qWB_register_Asm_32: {
6923 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6924 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6925 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6926 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6927 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6928 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6929 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6931 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6933 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6935 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6936 TmpInst.addOperand(Inst.getOperand(5));
6941 // Handle encoding choice for the shift-immediate instructions.
6944 case ARM::t2ASRri: {
6945 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6946 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6947 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6948 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6949 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6951 switch (Inst.getOpcode()) {
6952 default: llvm_unreachable("unexpected opcode");
6953 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6954 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6955 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6957 // The Thumb1 operands aren't in the same order. Awesome, eh?
6959 TmpInst.setOpcode(NewOpc);
6960 TmpInst.addOperand(Inst.getOperand(0));
6961 TmpInst.addOperand(Inst.getOperand(5));
6962 TmpInst.addOperand(Inst.getOperand(1));
6963 TmpInst.addOperand(Inst.getOperand(2));
6964 TmpInst.addOperand(Inst.getOperand(3));
6965 TmpInst.addOperand(Inst.getOperand(4));
6972 // Handle the Thumb2 mode MOV complex aliases.
6974 case ARM::t2MOVSsr: {
6975 // Which instruction to expand to depends on the CCOut operand and
6976 // whether we're in an IT block if the register operands are low
6978 bool isNarrow = false;
6979 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6980 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6981 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6982 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6983 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6987 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6988 default: llvm_unreachable("unexpected opcode!");
6989 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6990 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6991 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6992 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6994 TmpInst.setOpcode(newOpc);
6995 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6997 TmpInst.addOperand(MCOperand::CreateReg(
6998 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6999 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7000 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7001 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7002 TmpInst.addOperand(Inst.getOperand(5));
7004 TmpInst.addOperand(MCOperand::CreateReg(
7005 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7010 case ARM::t2MOVSsi: {
7011 // Which instruction to expand to depends on the CCOut operand and
7012 // whether we're in an IT block if the register operands are low
7014 bool isNarrow = false;
7015 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7016 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7017 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7021 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7022 default: llvm_unreachable("unexpected opcode!");
7023 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7024 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7025 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7026 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7027 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7029 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7030 if (Amount == 32) Amount = 0;
7031 TmpInst.setOpcode(newOpc);
7032 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7034 TmpInst.addOperand(MCOperand::CreateReg(
7035 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7036 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7037 if (newOpc != ARM::t2RRX)
7038 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7039 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7040 TmpInst.addOperand(Inst.getOperand(4));
7042 TmpInst.addOperand(MCOperand::CreateReg(
7043 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7047 // Handle the ARM mode MOV complex aliases.
7052 ARM_AM::ShiftOpc ShiftTy;
7053 switch(Inst.getOpcode()) {
7054 default: llvm_unreachable("unexpected opcode!");
7055 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7056 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7057 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7058 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7060 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7062 TmpInst.setOpcode(ARM::MOVsr);
7063 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7064 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7065 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7066 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7067 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7068 TmpInst.addOperand(Inst.getOperand(4));
7069 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7077 ARM_AM::ShiftOpc ShiftTy;
7078 switch(Inst.getOpcode()) {
7079 default: llvm_unreachable("unexpected opcode!");
7080 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7081 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7082 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7083 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7085 // A shift by zero is a plain MOVr, not a MOVsi.
7086 unsigned Amt = Inst.getOperand(2).getImm();
7087 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7088 // A shift by 32 should be encoded as 0 when permitted
7089 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7091 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7093 TmpInst.setOpcode(Opc);
7094 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7095 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7096 if (Opc == ARM::MOVsi)
7097 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7098 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7099 TmpInst.addOperand(Inst.getOperand(4));
7100 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7105 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7107 TmpInst.setOpcode(ARM::MOVsi);
7108 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7109 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7110 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7111 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7112 TmpInst.addOperand(Inst.getOperand(3));
7113 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7117 case ARM::t2LDMIA_UPD: {
7118 // If this is a load of a single register, then we should use
7119 // a post-indexed LDR instruction instead, per the ARM ARM.
7120 if (Inst.getNumOperands() != 5)
7123 TmpInst.setOpcode(ARM::t2LDR_POST);
7124 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7125 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7126 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7127 TmpInst.addOperand(MCOperand::CreateImm(4));
7128 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7129 TmpInst.addOperand(Inst.getOperand(3));
7133 case ARM::t2STMDB_UPD: {
7134 // If this is a store of a single register, then we should use
7135 // a pre-indexed STR instruction instead, per the ARM ARM.
7136 if (Inst.getNumOperands() != 5)
7139 TmpInst.setOpcode(ARM::t2STR_PRE);
7140 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7141 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7142 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7143 TmpInst.addOperand(MCOperand::CreateImm(-4));
7144 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7145 TmpInst.addOperand(Inst.getOperand(3));
7149 case ARM::LDMIA_UPD:
7150 // If this is a load of a single register via a 'pop', then we should use
7151 // a post-indexed LDR instruction instead, per the ARM ARM.
7152 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7153 Inst.getNumOperands() == 5) {
7155 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7156 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7157 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7158 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7159 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7160 TmpInst.addOperand(MCOperand::CreateImm(4));
7161 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7162 TmpInst.addOperand(Inst.getOperand(3));
7167 case ARM::STMDB_UPD:
7168 // If this is a store of a single register via a 'push', then we should use
7169 // a pre-indexed STR instruction instead, per the ARM ARM.
7170 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7171 Inst.getNumOperands() == 5) {
7173 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7174 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7175 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7176 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7177 TmpInst.addOperand(MCOperand::CreateImm(-4));
7178 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7179 TmpInst.addOperand(Inst.getOperand(3));
7183 case ARM::t2ADDri12:
7184 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7185 // mnemonic was used (not "addw"), encoding T3 is preferred.
7186 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7187 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7189 Inst.setOpcode(ARM::t2ADDri);
7190 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7192 case ARM::t2SUBri12:
7193 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7194 // mnemonic was used (not "subw"), encoding T3 is preferred.
7195 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7196 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7198 Inst.setOpcode(ARM::t2SUBri);
7199 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7202 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7203 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7204 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7205 // to encoding T1 if <Rd> is omitted."
7206 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7207 Inst.setOpcode(ARM::tADDi3);
7212 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7213 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7214 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7215 // to encoding T1 if <Rd> is omitted."
7216 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7217 Inst.setOpcode(ARM::tSUBi3);
7222 case ARM::t2SUBri: {
7223 // If the destination and first source operand are the same, and
7224 // the flags are compatible with the current IT status, use encoding T2
7225 // instead of T3. For compatibility with the system 'as'. Make sure the
7226 // wide encoding wasn't explicit.
7227 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7228 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7229 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7230 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7231 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7232 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7233 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7236 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7237 ARM::tADDi8 : ARM::tSUBi8);
7238 TmpInst.addOperand(Inst.getOperand(0));
7239 TmpInst.addOperand(Inst.getOperand(5));
7240 TmpInst.addOperand(Inst.getOperand(0));
7241 TmpInst.addOperand(Inst.getOperand(2));
7242 TmpInst.addOperand(Inst.getOperand(3));
7243 TmpInst.addOperand(Inst.getOperand(4));
7247 case ARM::t2ADDrr: {
7248 // If the destination and first source operand are the same, and
7249 // there's no setting of the flags, use encoding T2 instead of T3.
7250 // Note that this is only for ADD, not SUB. This mirrors the system
7251 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7252 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7253 Inst.getOperand(5).getReg() != 0 ||
7254 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7255 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7258 TmpInst.setOpcode(ARM::tADDhirr);
7259 TmpInst.addOperand(Inst.getOperand(0));
7260 TmpInst.addOperand(Inst.getOperand(0));
7261 TmpInst.addOperand(Inst.getOperand(2));
7262 TmpInst.addOperand(Inst.getOperand(3));
7263 TmpInst.addOperand(Inst.getOperand(4));
7267 case ARM::tADDrSP: {
7268 // If the non-SP source operand and the destination operand are not the
7269 // same, we need to use the 32-bit encoding if it's available.
7270 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7271 Inst.setOpcode(ARM::t2ADDrr);
7272 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7278 // A Thumb conditional branch outside of an IT block is a tBcc.
7279 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7280 Inst.setOpcode(ARM::tBcc);
7285 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7286 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7287 Inst.setOpcode(ARM::t2Bcc);
7292 // If the conditional is AL or we're in an IT block, we really want t2B.
7293 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7294 Inst.setOpcode(ARM::t2B);
7299 // If the conditional is AL, we really want tB.
7300 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7301 Inst.setOpcode(ARM::tB);
7306 // If the register list contains any high registers, or if the writeback
7307 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7308 // instead if we're in Thumb2. Otherwise, this should have generated
7309 // an error in validateInstruction().
7310 unsigned Rn = Inst.getOperand(0).getReg();
7311 bool hasWritebackToken =
7312 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7313 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7314 bool listContainsBase;
7315 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7316 (!listContainsBase && !hasWritebackToken) ||
7317 (listContainsBase && hasWritebackToken)) {
7318 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7319 assert (isThumbTwo());
7320 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7321 // If we're switching to the updating version, we need to insert
7322 // the writeback tied operand.
7323 if (hasWritebackToken)
7324 Inst.insert(Inst.begin(),
7325 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7330 case ARM::tSTMIA_UPD: {
7331 // If the register list contains any high registers, we need to use
7332 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7333 // should have generated an error in validateInstruction().
7334 unsigned Rn = Inst.getOperand(0).getReg();
7335 bool listContainsBase;
7336 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7337 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7338 assert (isThumbTwo());
7339 Inst.setOpcode(ARM::t2STMIA_UPD);
7345 bool listContainsBase;
7346 // If the register list contains any high registers, we need to use
7347 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7348 // should have generated an error in validateInstruction().
7349 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7351 assert (isThumbTwo());
7352 Inst.setOpcode(ARM::t2LDMIA_UPD);
7353 // Add the base register and writeback operands.
7354 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7355 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7359 bool listContainsBase;
7360 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7362 assert (isThumbTwo());
7363 Inst.setOpcode(ARM::t2STMDB_UPD);
7364 // Add the base register and writeback operands.
7365 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7366 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7370 // If we can use the 16-bit encoding and the user didn't explicitly
7371 // request the 32-bit variant, transform it here.
7372 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7373 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7374 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7375 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7376 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7377 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7378 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7379 // The operands aren't in the same order for tMOVi8...
7381 TmpInst.setOpcode(ARM::tMOVi8);
7382 TmpInst.addOperand(Inst.getOperand(0));
7383 TmpInst.addOperand(Inst.getOperand(4));
7384 TmpInst.addOperand(Inst.getOperand(1));
7385 TmpInst.addOperand(Inst.getOperand(2));
7386 TmpInst.addOperand(Inst.getOperand(3));
7393 // If we can use the 16-bit encoding and the user didn't explicitly
7394 // request the 32-bit variant, transform it here.
7395 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7396 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7397 Inst.getOperand(2).getImm() == ARMCC::AL &&
7398 Inst.getOperand(4).getReg() == ARM::CPSR &&
7399 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7400 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7401 // The operands aren't the same for tMOV[S]r... (no cc_out)
7403 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7404 TmpInst.addOperand(Inst.getOperand(0));
7405 TmpInst.addOperand(Inst.getOperand(1));
7406 TmpInst.addOperand(Inst.getOperand(2));
7407 TmpInst.addOperand(Inst.getOperand(3));
7417 // If we can use the 16-bit encoding and the user didn't explicitly
7418 // request the 32-bit variant, transform it here.
7419 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7420 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7421 Inst.getOperand(2).getImm() == 0 &&
7422 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7423 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7425 switch (Inst.getOpcode()) {
7426 default: llvm_unreachable("Illegal opcode!");
7427 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7428 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7429 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7430 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7432 // The operands aren't the same for thumb1 (no rotate operand).
7434 TmpInst.setOpcode(NewOpc);
7435 TmpInst.addOperand(Inst.getOperand(0));
7436 TmpInst.addOperand(Inst.getOperand(1));
7437 TmpInst.addOperand(Inst.getOperand(3));
7438 TmpInst.addOperand(Inst.getOperand(4));
7445 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7446 // rrx shifts and asr/lsr of #32 is encoded as 0
7447 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7449 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7450 // Shifting by zero is accepted as a vanilla 'MOVr'
7452 TmpInst.setOpcode(ARM::MOVr);
7453 TmpInst.addOperand(Inst.getOperand(0));
7454 TmpInst.addOperand(Inst.getOperand(1));
7455 TmpInst.addOperand(Inst.getOperand(3));
7456 TmpInst.addOperand(Inst.getOperand(4));
7457 TmpInst.addOperand(Inst.getOperand(5));
7470 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7471 if (SOpc == ARM_AM::rrx) return false;
7472 switch (Inst.getOpcode()) {
7473 default: llvm_unreachable("unexpected opcode!");
7474 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7475 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7476 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7477 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7478 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7479 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7481 // If the shift is by zero, use the non-shifted instruction definition.
7482 // The exception is for right shifts, where 0 == 32
7483 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7484 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7486 TmpInst.setOpcode(newOpc);
7487 TmpInst.addOperand(Inst.getOperand(0));
7488 TmpInst.addOperand(Inst.getOperand(1));
7489 TmpInst.addOperand(Inst.getOperand(2));
7490 TmpInst.addOperand(Inst.getOperand(4));
7491 TmpInst.addOperand(Inst.getOperand(5));
7492 TmpInst.addOperand(Inst.getOperand(6));
7500 // The mask bits for all but the first condition are represented as
7501 // the low bit of the condition code value implies 't'. We currently
7502 // always have 1 implies 't', so XOR toggle the bits if the low bit
7503 // of the condition code is zero.
7504 MCOperand &MO = Inst.getOperand(1);
7505 unsigned Mask = MO.getImm();
7506 unsigned OrigMask = Mask;
7507 unsigned TZ = countTrailingZeros(Mask);
7508 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7509 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7510 Mask ^= (0xE << TZ) & 0xF;
7514 // Set up the IT block state according to the IT instruction we just
7516 assert(!inITBlock() && "nested IT blocks?!");
7517 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7518 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7519 ITState.CurPosition = 0;
7520 ITState.FirstCond = true;
7530 // Assemblers should use the narrow encodings of these instructions when permissible.
7531 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7532 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7533 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7534 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7535 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7536 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7537 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7539 switch (Inst.getOpcode()) {
7540 default: llvm_unreachable("unexpected opcode");
7541 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7542 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7543 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7544 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7545 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7546 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7549 TmpInst.setOpcode(NewOpc);
7550 TmpInst.addOperand(Inst.getOperand(0));
7551 TmpInst.addOperand(Inst.getOperand(5));
7552 TmpInst.addOperand(Inst.getOperand(1));
7553 TmpInst.addOperand(Inst.getOperand(2));
7554 TmpInst.addOperand(Inst.getOperand(3));
7555 TmpInst.addOperand(Inst.getOperand(4));
7566 // Assemblers should use the narrow encodings of these instructions when permissible.
7567 // These instructions are special in that they are commutable, so shorter encodings
7568 // are available more often.
7569 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7570 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7571 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7572 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7573 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7574 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7575 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7576 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7578 switch (Inst.getOpcode()) {
7579 default: llvm_unreachable("unexpected opcode");
7580 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7581 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7582 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7583 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7586 TmpInst.setOpcode(NewOpc);
7587 TmpInst.addOperand(Inst.getOperand(0));
7588 TmpInst.addOperand(Inst.getOperand(5));
7589 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7590 TmpInst.addOperand(Inst.getOperand(1));
7591 TmpInst.addOperand(Inst.getOperand(2));
7593 TmpInst.addOperand(Inst.getOperand(2));
7594 TmpInst.addOperand(Inst.getOperand(1));
7596 TmpInst.addOperand(Inst.getOperand(3));
7597 TmpInst.addOperand(Inst.getOperand(4));
7607 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7608 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7609 // suffix depending on whether they're in an IT block or not.
7610 unsigned Opc = Inst.getOpcode();
7611 const MCInstrDesc &MCID = getInstDesc(Opc);
7612 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7613 assert(MCID.hasOptionalDef() &&
7614 "optionally flag setting instruction missing optional def operand");
7615 assert(MCID.NumOperands == Inst.getNumOperands() &&
7616 "operand count mismatch!");
7617 // Find the optional-def operand (cc_out).
7620 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7623 // If we're parsing Thumb1, reject it completely.
7624 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7625 return Match_MnemonicFail;
7626 // If we're parsing Thumb2, which form is legal depends on whether we're
7628 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7630 return Match_RequiresITBlock;
7631 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7633 return Match_RequiresNotITBlock;
7635 // Some high-register supporting Thumb1 encodings only allow both registers
7636 // to be from r0-r7 when in Thumb2.
7637 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7638 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7639 isARMLowRegister(Inst.getOperand(2).getReg()))
7640 return Match_RequiresThumb2;
7641 // Others only require ARMv6 or later.
7642 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7643 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7644 isARMLowRegister(Inst.getOperand(1).getReg()))
7645 return Match_RequiresV6;
7646 return Match_Success;
7649 static const char *getSubtargetFeatureName(unsigned Val);
7651 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7652 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7653 MCStreamer &Out, unsigned &ErrorInfo,
7654 bool MatchingInlineAsm) {
7656 unsigned MatchResult;
7658 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7660 switch (MatchResult) {
7663 // Context sensitive operand constraints aren't handled by the matcher,
7664 // so check them here.
7665 if (validateInstruction(Inst, Operands)) {
7666 // Still progress the IT block, otherwise one wrong condition causes
7667 // nasty cascading errors.
7668 forwardITPosition();
7672 // Some instructions need post-processing to, for example, tweak which
7673 // encoding is selected. Loop on it while changes happen so the
7674 // individual transformations can chain off each other. E.g.,
7675 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7676 while (processInstruction(Inst, Operands))
7679 // Only move forward at the very end so that everything in validate
7680 // and process gets a consistent answer about whether we're in an IT
7682 forwardITPosition();
7684 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7685 // doesn't actually encode.
7686 if (Inst.getOpcode() == ARM::ITasm)
7690 Out.EmitInstruction(Inst);
7692 case Match_MissingFeature: {
7693 assert(ErrorInfo && "Unknown missing feature!");
7694 // Special case the error message for the very common case where only
7695 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7696 std::string Msg = "instruction requires:";
7698 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7699 if (ErrorInfo & Mask) {
7701 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7705 return Error(IDLoc, Msg);
7707 case Match_InvalidOperand: {
7708 SMLoc ErrorLoc = IDLoc;
7709 if (ErrorInfo != ~0U) {
7710 if (ErrorInfo >= Operands.size())
7711 return Error(IDLoc, "too few operands for instruction");
7713 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7714 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7717 return Error(ErrorLoc, "invalid operand for instruction");
7719 case Match_MnemonicFail:
7720 return Error(IDLoc, "invalid instruction",
7721 ((ARMOperand*)Operands[0])->getLocRange());
7722 case Match_RequiresNotITBlock:
7723 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7724 case Match_RequiresITBlock:
7725 return Error(IDLoc, "instruction only valid inside IT block");
7726 case Match_RequiresV6:
7727 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7728 case Match_RequiresThumb2:
7729 return Error(IDLoc, "instruction variant requires Thumb2");
7730 case Match_ImmRange0_4: {
7731 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7732 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7733 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7735 case Match_ImmRange0_15: {
7736 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7737 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7738 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7742 llvm_unreachable("Implement any new match types added!");
7745 /// parseDirective parses the arm specific directives
7746 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7747 StringRef IDVal = DirectiveID.getIdentifier();
7748 if (IDVal == ".word")
7749 return parseDirectiveWord(4, DirectiveID.getLoc());
7750 else if (IDVal == ".thumb")
7751 return parseDirectiveThumb(DirectiveID.getLoc());
7752 else if (IDVal == ".arm")
7753 return parseDirectiveARM(DirectiveID.getLoc());
7754 else if (IDVal == ".thumb_func")
7755 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7756 else if (IDVal == ".code")
7757 return parseDirectiveCode(DirectiveID.getLoc());
7758 else if (IDVal == ".syntax")
7759 return parseDirectiveSyntax(DirectiveID.getLoc());
7760 else if (IDVal == ".unreq")
7761 return parseDirectiveUnreq(DirectiveID.getLoc());
7762 else if (IDVal == ".arch")
7763 return parseDirectiveArch(DirectiveID.getLoc());
7764 else if (IDVal == ".eabi_attribute")
7765 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7766 else if (IDVal == ".fnstart")
7767 return parseDirectiveFnStart(DirectiveID.getLoc());
7768 else if (IDVal == ".fnend")
7769 return parseDirectiveFnEnd(DirectiveID.getLoc());
7770 else if (IDVal == ".cantunwind")
7771 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7772 else if (IDVal == ".personality")
7773 return parseDirectivePersonality(DirectiveID.getLoc());
7774 else if (IDVal == ".handlerdata")
7775 return parseDirectiveHandlerData(DirectiveID.getLoc());
7776 else if (IDVal == ".setfp")
7777 return parseDirectiveSetFP(DirectiveID.getLoc());
7778 else if (IDVal == ".pad")
7779 return parseDirectivePad(DirectiveID.getLoc());
7780 else if (IDVal == ".save")
7781 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7782 else if (IDVal == ".vsave")
7783 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7787 /// parseDirectiveWord
7788 /// ::= .word [ expression (, expression)* ]
7789 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7790 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7792 const MCExpr *Value;
7793 if (getParser().parseExpression(Value))
7796 getParser().getStreamer().EmitValue(Value, Size);
7798 if (getLexer().is(AsmToken::EndOfStatement))
7801 // FIXME: Improve diagnostic.
7802 if (getLexer().isNot(AsmToken::Comma))
7803 return Error(L, "unexpected token in directive");
7812 /// parseDirectiveThumb
7814 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7815 if (getLexer().isNot(AsmToken::EndOfStatement))
7816 return Error(L, "unexpected token in directive");
7821 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7825 /// parseDirectiveARM
7827 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7828 if (getLexer().isNot(AsmToken::EndOfStatement))
7829 return Error(L, "unexpected token in directive");
7834 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7838 /// parseDirectiveThumbFunc
7839 /// ::= .thumbfunc symbol_name
7840 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7841 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7842 bool isMachO = MAI.hasSubsectionsViaSymbols();
7844 bool needFuncName = true;
7846 // Darwin asm has (optionally) function name after .thumb_func direction
7849 const AsmToken &Tok = Parser.getTok();
7850 if (Tok.isNot(AsmToken::EndOfStatement)) {
7851 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7852 return Error(L, "unexpected token in .thumb_func directive");
7853 Name = Tok.getIdentifier();
7854 Parser.Lex(); // Consume the identifier token.
7855 needFuncName = false;
7859 if (getLexer().isNot(AsmToken::EndOfStatement))
7860 return Error(L, "unexpected token in directive");
7862 // Eat the end of statement and any blank lines that follow.
7863 while (getLexer().is(AsmToken::EndOfStatement))
7866 // FIXME: assuming function name will be the line following .thumb_func
7867 // We really should be checking the next symbol definition even if there's
7868 // stuff in between.
7870 Name = Parser.getTok().getIdentifier();
7873 // Mark symbol as a thumb symbol.
7874 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7875 getParser().getStreamer().EmitThumbFunc(Func);
7879 /// parseDirectiveSyntax
7880 /// ::= .syntax unified | divided
7881 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7882 const AsmToken &Tok = Parser.getTok();
7883 if (Tok.isNot(AsmToken::Identifier))
7884 return Error(L, "unexpected token in .syntax directive");
7885 StringRef Mode = Tok.getString();
7886 if (Mode == "unified" || Mode == "UNIFIED")
7888 else if (Mode == "divided" || Mode == "DIVIDED")
7889 return Error(L, "'.syntax divided' arm asssembly not supported");
7891 return Error(L, "unrecognized syntax mode in .syntax directive");
7893 if (getLexer().isNot(AsmToken::EndOfStatement))
7894 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7897 // TODO tell the MC streamer the mode
7898 // getParser().getStreamer().Emit???();
7902 /// parseDirectiveCode
7903 /// ::= .code 16 | 32
7904 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7905 const AsmToken &Tok = Parser.getTok();
7906 if (Tok.isNot(AsmToken::Integer))
7907 return Error(L, "unexpected token in .code directive");
7908 int64_t Val = Parser.getTok().getIntVal();
7914 return Error(L, "invalid operand to .code directive");
7916 if (getLexer().isNot(AsmToken::EndOfStatement))
7917 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7923 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7927 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7933 /// parseDirectiveReq
7934 /// ::= name .req registername
7935 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7936 Parser.Lex(); // Eat the '.req' token.
7938 SMLoc SRegLoc, ERegLoc;
7939 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7940 Parser.eatToEndOfStatement();
7941 return Error(SRegLoc, "register name expected");
7944 // Shouldn't be anything else.
7945 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7946 Parser.eatToEndOfStatement();
7947 return Error(Parser.getTok().getLoc(),
7948 "unexpected input in .req directive.");
7951 Parser.Lex(); // Consume the EndOfStatement
7953 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7954 return Error(SRegLoc, "redefinition of '" + Name +
7955 "' does not match original.");
7960 /// parseDirectiveUneq
7961 /// ::= .unreq registername
7962 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7963 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7964 Parser.eatToEndOfStatement();
7965 return Error(L, "unexpected input in .unreq directive.");
7967 RegisterReqs.erase(Parser.getTok().getIdentifier());
7968 Parser.Lex(); // Eat the identifier.
7972 /// parseDirectiveArch
7974 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7978 /// parseDirectiveEabiAttr
7979 /// ::= .eabi_attribute int, int
7980 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7984 /// parseDirectiveFnStart
7986 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7987 if (FnStartLoc.isValid()) {
7988 Error(L, ".fnstart starts before the end of previous one");
7989 Error(FnStartLoc, "previous .fnstart starts here");
7994 getParser().getStreamer().EmitFnStart();
7998 /// parseDirectiveFnEnd
8000 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8001 // Check the ordering of unwind directives
8002 if (!FnStartLoc.isValid())
8003 return Error(L, ".fnstart must precede .fnend directive");
8005 // Reset the unwind directives parser state
8006 resetUnwindDirectiveParserState();
8008 getParser().getStreamer().EmitFnEnd();
8012 /// parseDirectiveCantUnwind
8014 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8015 // Check the ordering of unwind directives
8017 if (!FnStartLoc.isValid())
8018 return Error(L, ".fnstart must precede .cantunwind directive");
8019 if (HandlerDataLoc.isValid()) {
8020 Error(L, ".cantunwind can't be used with .handlerdata directive");
8021 Error(HandlerDataLoc, ".handlerdata was specified here");
8024 if (PersonalityLoc.isValid()) {
8025 Error(L, ".cantunwind can't be used with .personality directive");
8026 Error(PersonalityLoc, ".personality was specified here");
8030 getParser().getStreamer().EmitCantUnwind();
8034 /// parseDirectivePersonality
8035 /// ::= .personality name
8036 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8037 // Check the ordering of unwind directives
8039 if (!FnStartLoc.isValid())
8040 return Error(L, ".fnstart must precede .personality directive");
8041 if (CantUnwindLoc.isValid()) {
8042 Error(L, ".personality can't be used with .cantunwind directive");
8043 Error(CantUnwindLoc, ".cantunwind was specified here");
8046 if (HandlerDataLoc.isValid()) {
8047 Error(L, ".personality must precede .handlerdata directive");
8048 Error(HandlerDataLoc, ".handlerdata was specified here");
8052 // Parse the name of the personality routine
8053 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8054 Parser.eatToEndOfStatement();
8055 return Error(L, "unexpected input in .personality directive.");
8057 StringRef Name(Parser.getTok().getIdentifier());
8060 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8061 getParser().getStreamer().EmitPersonality(PR);
8065 /// parseDirectiveHandlerData
8066 /// ::= .handlerdata
8067 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8068 // Check the ordering of unwind directives
8070 if (!FnStartLoc.isValid())
8071 return Error(L, ".fnstart must precede .personality directive");
8072 if (CantUnwindLoc.isValid()) {
8073 Error(L, ".handlerdata can't be used with .cantunwind directive");
8074 Error(CantUnwindLoc, ".cantunwind was specified here");
8078 getParser().getStreamer().EmitHandlerData();
8082 /// parseDirectiveSetFP
8083 /// ::= .setfp fpreg, spreg [, offset]
8084 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8085 // Check the ordering of unwind directives
8086 if (!FnStartLoc.isValid())
8087 return Error(L, ".fnstart must precede .setfp directive");
8088 if (HandlerDataLoc.isValid())
8089 return Error(L, ".setfp must precede .handlerdata directive");
8092 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8093 int NewFPReg = tryParseRegister();
8095 return Error(NewFPRegLoc, "frame pointer register expected");
8098 if (!Parser.getTok().is(AsmToken::Comma))
8099 return Error(Parser.getTok().getLoc(), "comma expected");
8100 Parser.Lex(); // skip comma
8103 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8104 int NewSPReg = tryParseRegister();
8106 return Error(NewSPRegLoc, "stack pointer register expected");
8108 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8109 return Error(NewSPRegLoc,
8110 "register should be either $sp or the latest fp register");
8112 // Update the frame pointer register
8117 if (Parser.getTok().is(AsmToken::Comma)) {
8118 Parser.Lex(); // skip comma
8120 if (Parser.getTok().isNot(AsmToken::Hash) &&
8121 Parser.getTok().isNot(AsmToken::Dollar)) {
8122 return Error(Parser.getTok().getLoc(), "'#' expected");
8124 Parser.Lex(); // skip hash token.
8126 const MCExpr *OffsetExpr;
8127 SMLoc ExLoc = Parser.getTok().getLoc();
8129 if (getParser().parseExpression(OffsetExpr, EndLoc))
8130 return Error(ExLoc, "malformed setfp offset");
8131 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8133 return Error(ExLoc, "setfp offset must be an immediate");
8135 Offset = CE->getValue();
8138 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8139 static_cast<unsigned>(NewSPReg),
8146 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8147 // Check the ordering of unwind directives
8148 if (!FnStartLoc.isValid())
8149 return Error(L, ".fnstart must precede .pad directive");
8150 if (HandlerDataLoc.isValid())
8151 return Error(L, ".pad must precede .handlerdata directive");
8154 if (Parser.getTok().isNot(AsmToken::Hash) &&
8155 Parser.getTok().isNot(AsmToken::Dollar)) {
8156 return Error(Parser.getTok().getLoc(), "'#' expected");
8158 Parser.Lex(); // skip hash token.
8160 const MCExpr *OffsetExpr;
8161 SMLoc ExLoc = Parser.getTok().getLoc();
8163 if (getParser().parseExpression(OffsetExpr, EndLoc))
8164 return Error(ExLoc, "malformed pad offset");
8165 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8167 return Error(ExLoc, "pad offset must be an immediate");
8169 getParser().getStreamer().EmitPad(CE->getValue());
8173 /// parseDirectiveRegSave
8174 /// ::= .save { registers }
8175 /// ::= .vsave { registers }
8176 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8177 // Check the ordering of unwind directives
8178 if (!FnStartLoc.isValid())
8179 return Error(L, ".fnstart must precede .save or .vsave directives");
8180 if (HandlerDataLoc.isValid())
8181 return Error(L, ".save or .vsave must precede .handlerdata directive");
8183 // Parse the register list
8184 SmallVector<MCParsedAsmOperand*, 1> Operands;
8185 if (parseRegisterList(Operands))
8187 ARMOperand *Op = (ARMOperand*)Operands[0];
8188 if (!IsVector && !Op->isRegList())
8189 return Error(L, ".save expects GPR registers");
8190 if (IsVector && !Op->isDPRRegList())
8191 return Error(L, ".vsave expects DPR registers");
8193 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8197 /// Force static initialization.
8198 extern "C" void LLVMInitializeARMAsmParser() {
8199 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8200 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8203 #define GET_REGISTER_MATCHER
8204 #define GET_SUBTARGET_FEATURE_NAME
8205 #define GET_MATCHER_IMPLEMENTATION
8206 #include "ARMGenAsmMatcher.inc"
8208 // Define this matcher function after the auto-generated include so we
8209 // have the match class enum definitions.
8210 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8212 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8213 // If the kind is a token for a literal immediate, check if our asm
8214 // operand matches. This is for InstAliases which have a fixed-value
8215 // immediate in the syntax.
8216 if (Kind == MCK__35_0 && Op->isImm()) {
8217 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8219 return Match_InvalidOperand;
8220 if (CE->getValue() == 0)
8221 return Match_Success;
8223 return Match_InvalidOperand;