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 hasThumb() const {
156 return STI.getFeatureBits() & ARM::HasV4TOps;
158 bool hasV6Ops() const {
159 return STI.getFeatureBits() & ARM::HasV6Ops;
161 bool hasV7Ops() const {
162 return STI.getFeatureBits() & ARM::HasV7Ops;
164 bool hasV8Ops() const {
165 return STI.getFeatureBits() & ARM::HasV8Ops;
167 bool hasARM() const {
168 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
172 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
173 setAvailableFeatures(FB);
175 bool isMClass() const {
176 return STI.getFeatureBits() & ARM::FeatureMClass;
179 /// @name Auto-generated Match Functions
182 #define GET_ASSEMBLER_HEADER
183 #include "ARMGenAsmMatcher.inc"
187 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
188 OperandMatchResultTy parseCoprocNumOperand(
189 SmallVectorImpl<MCParsedAsmOperand*>&);
190 OperandMatchResultTy parseCoprocRegOperand(
191 SmallVectorImpl<MCParsedAsmOperand*>&);
192 OperandMatchResultTy parseCoprocOptionOperand(
193 SmallVectorImpl<MCParsedAsmOperand*>&);
194 OperandMatchResultTy parseMemBarrierOptOperand(
195 SmallVectorImpl<MCParsedAsmOperand*>&);
196 OperandMatchResultTy parseInstSyncBarrierOptOperand(
197 SmallVectorImpl<MCParsedAsmOperand*>&);
198 OperandMatchResultTy parseProcIFlagsOperand(
199 SmallVectorImpl<MCParsedAsmOperand*>&);
200 OperandMatchResultTy parseMSRMaskOperand(
201 SmallVectorImpl<MCParsedAsmOperand*>&);
202 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
203 StringRef Op, int Low, int High);
204 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
205 return parsePKHImm(O, "lsl", 0, 31);
207 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
208 return parsePKHImm(O, "asr", 1, 32);
210 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
211 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
212 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
213 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
214 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
215 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
216 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
217 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
218 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
221 // Asm Match Converter Methods
222 void cvtT2LdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
223 void cvtT2StrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
224 void cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
225 const SmallVectorImpl<MCParsedAsmOperand*> &);
226 void cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
227 const SmallVectorImpl<MCParsedAsmOperand*> &);
228 void cvtLdWriteBackRegAddrMode2(MCInst &Inst,
229 const SmallVectorImpl<MCParsedAsmOperand*> &);
230 void cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
231 const SmallVectorImpl<MCParsedAsmOperand*> &);
232 void cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
233 const SmallVectorImpl<MCParsedAsmOperand*> &);
234 void cvtStWriteBackRegAddrMode2(MCInst &Inst,
235 const SmallVectorImpl<MCParsedAsmOperand*> &);
236 void cvtStWriteBackRegAddrMode3(MCInst &Inst,
237 const SmallVectorImpl<MCParsedAsmOperand*> &);
238 void cvtLdExtTWriteBackImm(MCInst &Inst,
239 const SmallVectorImpl<MCParsedAsmOperand*> &);
240 void cvtLdExtTWriteBackReg(MCInst &Inst,
241 const SmallVectorImpl<MCParsedAsmOperand*> &);
242 void cvtStExtTWriteBackImm(MCInst &Inst,
243 const SmallVectorImpl<MCParsedAsmOperand*> &);
244 void cvtStExtTWriteBackReg(MCInst &Inst,
245 const SmallVectorImpl<MCParsedAsmOperand*> &);
246 void cvtLdrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
247 void cvtStrdPre(MCInst &Inst, const SmallVectorImpl<MCParsedAsmOperand*> &);
248 void cvtLdWriteBackRegAddrMode3(MCInst &Inst,
249 const SmallVectorImpl<MCParsedAsmOperand*> &);
250 void cvtThumbMultiply(MCInst &Inst,
251 const SmallVectorImpl<MCParsedAsmOperand*> &);
252 void cvtVLDwbFixed(MCInst &Inst,
253 const SmallVectorImpl<MCParsedAsmOperand*> &);
254 void cvtVLDwbRegister(MCInst &Inst,
255 const SmallVectorImpl<MCParsedAsmOperand*> &);
256 void cvtVSTwbFixed(MCInst &Inst,
257 const SmallVectorImpl<MCParsedAsmOperand*> &);
258 void cvtVSTwbRegister(MCInst &Inst,
259 const SmallVectorImpl<MCParsedAsmOperand*> &);
260 bool validateInstruction(MCInst &Inst,
261 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
262 bool processInstruction(MCInst &Inst,
263 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
264 bool shouldOmitCCOutOperand(StringRef Mnemonic,
265 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
268 enum ARMMatchResultTy {
269 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
270 Match_RequiresNotITBlock,
272 Match_RequiresThumb2,
273 #define GET_OPERAND_DIAGNOSTIC_TYPES
274 #include "ARMGenAsmMatcher.inc"
278 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
279 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
280 MCAsmParserExtension::Initialize(_Parser);
282 // Cache the MCRegisterInfo.
283 MRI = getContext().getRegisterInfo();
285 // Initialize the set of available features.
286 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
288 // Not in an ITBlock to start with.
289 ITState.CurPosition = ~0U;
291 // Set ELF header flags.
292 // FIXME: This should eventually end up somewhere else where more
293 // intelligent flag decisions can be made. For now we are just maintaining
294 // the statu/parseDirects quo for ARM and setting EF_ARM_EABI_VER5 as the default.
295 if (MCELFStreamer *MES = dyn_cast<MCELFStreamer>(&Parser.getStreamer()))
296 MES->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
299 // Implementation of the MCTargetAsmParser interface:
300 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
301 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
303 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
304 bool ParseDirective(AsmToken DirectiveID);
306 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
307 unsigned checkTargetMatchPredicate(MCInst &Inst);
309 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
310 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
311 MCStreamer &Out, unsigned &ErrorInfo,
312 bool MatchingInlineAsm);
314 } // end anonymous namespace
318 /// ARMOperand - Instances of this class represent a parsed ARM machine
320 class ARMOperand : public MCParsedAsmOperand {
330 k_InstSyncBarrierOpt,
341 k_VectorListAllLanes,
347 k_BitfieldDescriptor,
351 SMLoc StartLoc, EndLoc;
352 SmallVector<unsigned, 8> Registers;
355 ARMCC::CondCodes Val;
362 struct CoprocOptionOp {
375 ARM_ISB::InstSyncBOpt Val;
379 ARM_PROC::IFlags Val;
395 // A vector register list is a sequential list of 1 to 4 registers.
396 struct VectorListOp {
403 struct VectorIndexOp {
411 /// Combined record for all forms of ARM address expressions.
414 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
416 const MCConstantExpr *OffsetImm; // Offset immediate value
417 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
418 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
419 unsigned ShiftImm; // shift for OffsetReg.
420 unsigned Alignment; // 0 = no alignment specified
421 // n = alignment in bytes (2, 4, 8, 16, or 32)
422 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
425 struct PostIdxRegOp {
428 ARM_AM::ShiftOpc ShiftTy;
432 struct ShifterImmOp {
437 struct RegShiftedRegOp {
438 ARM_AM::ShiftOpc ShiftTy;
444 struct RegShiftedImmOp {
445 ARM_AM::ShiftOpc ShiftTy;
462 struct CoprocOptionOp CoprocOption;
463 struct MBOptOp MBOpt;
464 struct ISBOptOp ISBOpt;
465 struct ITMaskOp ITMask;
466 struct IFlagsOp IFlags;
467 struct MMaskOp MMask;
470 struct VectorListOp VectorList;
471 struct VectorIndexOp VectorIndex;
473 struct MemoryOp Memory;
474 struct PostIdxRegOp PostIdxReg;
475 struct ShifterImmOp ShifterImm;
476 struct RegShiftedRegOp RegShiftedReg;
477 struct RegShiftedImmOp RegShiftedImm;
478 struct RotImmOp RotImm;
479 struct BitfieldOp Bitfield;
482 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
484 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
486 StartLoc = o.StartLoc;
503 case k_DPRRegisterList:
504 case k_SPRRegisterList:
505 Registers = o.Registers;
508 case k_VectorListAllLanes:
509 case k_VectorListIndexed:
510 VectorList = o.VectorList;
517 CoprocOption = o.CoprocOption;
522 case k_MemBarrierOpt:
525 case k_InstSyncBarrierOpt:
530 case k_PostIndexRegister:
531 PostIdxReg = o.PostIdxReg;
539 case k_ShifterImmediate:
540 ShifterImm = o.ShifterImm;
542 case k_ShiftedRegister:
543 RegShiftedReg = o.RegShiftedReg;
545 case k_ShiftedImmediate:
546 RegShiftedImm = o.RegShiftedImm;
548 case k_RotateImmediate:
551 case k_BitfieldDescriptor:
552 Bitfield = o.Bitfield;
555 VectorIndex = o.VectorIndex;
560 /// getStartLoc - Get the location of the first token of this operand.
561 SMLoc getStartLoc() const { return StartLoc; }
562 /// getEndLoc - Get the location of the last token of this operand.
563 SMLoc getEndLoc() const { return EndLoc; }
564 /// getLocRange - Get the range between the first and last token of this
566 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
568 ARMCC::CondCodes getCondCode() const {
569 assert(Kind == k_CondCode && "Invalid access!");
573 unsigned getCoproc() const {
574 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
578 StringRef getToken() const {
579 assert(Kind == k_Token && "Invalid access!");
580 return StringRef(Tok.Data, Tok.Length);
583 unsigned getReg() const {
584 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
588 const SmallVectorImpl<unsigned> &getRegList() const {
589 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
590 Kind == k_SPRRegisterList) && "Invalid access!");
594 const MCExpr *getImm() const {
595 assert(isImm() && "Invalid access!");
599 unsigned getVectorIndex() const {
600 assert(Kind == k_VectorIndex && "Invalid access!");
601 return VectorIndex.Val;
604 ARM_MB::MemBOpt getMemBarrierOpt() const {
605 assert(Kind == k_MemBarrierOpt && "Invalid access!");
609 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
610 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
614 ARM_PROC::IFlags getProcIFlags() const {
615 assert(Kind == k_ProcIFlags && "Invalid access!");
619 unsigned getMSRMask() const {
620 assert(Kind == k_MSRMask && "Invalid access!");
624 bool isCoprocNum() const { return Kind == k_CoprocNum; }
625 bool isCoprocReg() const { return Kind == k_CoprocReg; }
626 bool isCoprocOption() const { return Kind == k_CoprocOption; }
627 bool isCondCode() const { return Kind == k_CondCode; }
628 bool isCCOut() const { return Kind == k_CCOut; }
629 bool isITMask() const { return Kind == k_ITCondMask; }
630 bool isITCondCode() const { return Kind == k_CondCode; }
631 bool isImm() const { return Kind == k_Immediate; }
632 bool isFPImm() const {
633 if (!isImm()) return false;
634 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
635 if (!CE) return false;
636 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
639 bool isFBits16() const {
640 if (!isImm()) return false;
641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
642 if (!CE) return false;
643 int64_t Value = CE->getValue();
644 return Value >= 0 && Value <= 16;
646 bool isFBits32() const {
647 if (!isImm()) return false;
648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
649 if (!CE) return false;
650 int64_t Value = CE->getValue();
651 return Value >= 1 && Value <= 32;
653 bool isImm8s4() const {
654 if (!isImm()) return false;
655 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
656 if (!CE) return false;
657 int64_t Value = CE->getValue();
658 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
660 bool isImm0_4() const {
661 if (!isImm()) return false;
662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
663 if (!CE) return false;
664 int64_t Value = CE->getValue();
665 return Value >= 0 && Value < 5;
667 bool isImm0_1020s4() const {
668 if (!isImm()) return false;
669 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
670 if (!CE) return false;
671 int64_t Value = CE->getValue();
672 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
674 bool isImm0_508s4() const {
675 if (!isImm()) return false;
676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
677 if (!CE) return false;
678 int64_t Value = CE->getValue();
679 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
681 bool isImm0_508s4Neg() const {
682 if (!isImm()) return false;
683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
684 if (!CE) return false;
685 int64_t Value = -CE->getValue();
686 // explicitly exclude zero. we want that to use the normal 0_508 version.
687 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
689 bool isImm0_255() const {
690 if (!isImm()) return false;
691 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
692 if (!CE) return false;
693 int64_t Value = CE->getValue();
694 return Value >= 0 && Value < 256;
696 bool isImm0_4095() const {
697 if (!isImm()) return false;
698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
699 if (!CE) return false;
700 int64_t Value = CE->getValue();
701 return Value >= 0 && Value < 4096;
703 bool isImm0_4095Neg() const {
704 if (!isImm()) return false;
705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
706 if (!CE) return false;
707 int64_t Value = -CE->getValue();
708 return Value > 0 && Value < 4096;
710 bool isImm0_1() const {
711 if (!isImm()) return false;
712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
713 if (!CE) return false;
714 int64_t Value = CE->getValue();
715 return Value >= 0 && Value < 2;
717 bool isImm0_3() const {
718 if (!isImm()) return false;
719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
720 if (!CE) return false;
721 int64_t Value = CE->getValue();
722 return Value >= 0 && Value < 4;
724 bool isImm0_7() const {
725 if (!isImm()) return false;
726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
727 if (!CE) return false;
728 int64_t Value = CE->getValue();
729 return Value >= 0 && Value < 8;
731 bool isImm0_15() const {
732 if (!isImm()) return false;
733 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
734 if (!CE) return false;
735 int64_t Value = CE->getValue();
736 return Value >= 0 && Value < 16;
738 bool isImm0_31() const {
739 if (!isImm()) return false;
740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
741 if (!CE) return false;
742 int64_t Value = CE->getValue();
743 return Value >= 0 && Value < 32;
745 bool isImm0_63() const {
746 if (!isImm()) return false;
747 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
748 if (!CE) return false;
749 int64_t Value = CE->getValue();
750 return Value >= 0 && Value < 64;
752 bool isImm8() const {
753 if (!isImm()) return false;
754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
755 if (!CE) return false;
756 int64_t Value = CE->getValue();
759 bool isImm16() const {
760 if (!isImm()) return false;
761 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
762 if (!CE) return false;
763 int64_t Value = CE->getValue();
766 bool isImm32() const {
767 if (!isImm()) return false;
768 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
769 if (!CE) return false;
770 int64_t Value = CE->getValue();
773 bool isShrImm8() const {
774 if (!isImm()) return false;
775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
776 if (!CE) return false;
777 int64_t Value = CE->getValue();
778 return Value > 0 && Value <= 8;
780 bool isShrImm16() const {
781 if (!isImm()) return false;
782 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
783 if (!CE) return false;
784 int64_t Value = CE->getValue();
785 return Value > 0 && Value <= 16;
787 bool isShrImm32() const {
788 if (!isImm()) return false;
789 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
790 if (!CE) return false;
791 int64_t Value = CE->getValue();
792 return Value > 0 && Value <= 32;
794 bool isShrImm64() const {
795 if (!isImm()) return false;
796 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
797 if (!CE) return false;
798 int64_t Value = CE->getValue();
799 return Value > 0 && Value <= 64;
801 bool isImm1_7() const {
802 if (!isImm()) return false;
803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
804 if (!CE) return false;
805 int64_t Value = CE->getValue();
806 return Value > 0 && Value < 8;
808 bool isImm1_15() const {
809 if (!isImm()) return false;
810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return Value > 0 && Value < 16;
815 bool isImm1_31() const {
816 if (!isImm()) return false;
817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
818 if (!CE) return false;
819 int64_t Value = CE->getValue();
820 return Value > 0 && Value < 32;
822 bool isImm1_16() const {
823 if (!isImm()) return false;
824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
825 if (!CE) return false;
826 int64_t Value = CE->getValue();
827 return Value > 0 && Value < 17;
829 bool isImm1_32() const {
830 if (!isImm()) return false;
831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
832 if (!CE) return false;
833 int64_t Value = CE->getValue();
834 return Value > 0 && Value < 33;
836 bool isImm0_32() const {
837 if (!isImm()) return false;
838 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
839 if (!CE) return false;
840 int64_t Value = CE->getValue();
841 return Value >= 0 && Value < 33;
843 bool isImm0_65535() const {
844 if (!isImm()) return false;
845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
846 if (!CE) return false;
847 int64_t Value = CE->getValue();
848 return Value >= 0 && Value < 65536;
850 bool isImm0_65535Expr() const {
851 if (!isImm()) return false;
852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
853 // If it's not a constant expression, it'll generate a fixup and be
855 if (!CE) return true;
856 int64_t Value = CE->getValue();
857 return Value >= 0 && Value < 65536;
859 bool isImm24bit() const {
860 if (!isImm()) return false;
861 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
862 if (!CE) return false;
863 int64_t Value = CE->getValue();
864 return Value >= 0 && Value <= 0xffffff;
866 bool isImmThumbSR() const {
867 if (!isImm()) return false;
868 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
869 if (!CE) return false;
870 int64_t Value = CE->getValue();
871 return Value > 0 && Value < 33;
873 bool isPKHLSLImm() const {
874 if (!isImm()) return false;
875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
876 if (!CE) return false;
877 int64_t Value = CE->getValue();
878 return Value >= 0 && Value < 32;
880 bool isPKHASRImm() const {
881 if (!isImm()) return false;
882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
883 if (!CE) return false;
884 int64_t Value = CE->getValue();
885 return Value > 0 && Value <= 32;
887 bool isAdrLabel() const {
888 // If we have an immediate that's not a constant, treat it as a label
889 // reference needing a fixup. If it is a constant, but it can't fit
890 // into shift immediate encoding, we reject it.
891 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
892 else return (isARMSOImm() || isARMSOImmNeg());
894 bool isARMSOImm() const {
895 if (!isImm()) return false;
896 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
897 if (!CE) return false;
898 int64_t Value = CE->getValue();
899 return ARM_AM::getSOImmVal(Value) != -1;
901 bool isARMSOImmNot() const {
902 if (!isImm()) return false;
903 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
904 if (!CE) return false;
905 int64_t Value = CE->getValue();
906 return ARM_AM::getSOImmVal(~Value) != -1;
908 bool isARMSOImmNeg() const {
909 if (!isImm()) return false;
910 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
911 if (!CE) return false;
912 int64_t Value = CE->getValue();
913 // Only use this when not representable as a plain so_imm.
914 return ARM_AM::getSOImmVal(Value) == -1 &&
915 ARM_AM::getSOImmVal(-Value) != -1;
917 bool isT2SOImm() const {
918 if (!isImm()) return false;
919 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
920 if (!CE) return false;
921 int64_t Value = CE->getValue();
922 return ARM_AM::getT2SOImmVal(Value) != -1;
924 bool isT2SOImmNot() const {
925 if (!isImm()) return false;
926 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
927 if (!CE) return false;
928 int64_t Value = CE->getValue();
929 return ARM_AM::getT2SOImmVal(~Value) != -1;
931 bool isT2SOImmNeg() const {
932 if (!isImm()) return false;
933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
934 if (!CE) return false;
935 int64_t Value = CE->getValue();
936 // Only use this when not representable as a plain so_imm.
937 return ARM_AM::getT2SOImmVal(Value) == -1 &&
938 ARM_AM::getT2SOImmVal(-Value) != -1;
940 bool isSetEndImm() const {
941 if (!isImm()) return false;
942 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
943 if (!CE) return false;
944 int64_t Value = CE->getValue();
945 return Value == 1 || Value == 0;
947 bool isReg() const { return Kind == k_Register; }
948 bool isRegList() const { return Kind == k_RegisterList; }
949 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
950 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
951 bool isToken() const { return Kind == k_Token; }
952 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
953 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
954 bool isMem() const { return Kind == k_Memory; }
955 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
956 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
957 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
958 bool isRotImm() const { return Kind == k_RotateImmediate; }
959 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
960 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
961 bool isPostIdxReg() const {
962 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
964 bool isMemNoOffset(bool alignOK = false) const {
967 // No offset of any kind.
968 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
969 (alignOK || Memory.Alignment == 0);
971 bool isMemPCRelImm12() const {
972 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
974 // Base register must be PC.
975 if (Memory.BaseRegNum != ARM::PC)
977 // Immediate offset in range [-4095, 4095].
978 if (!Memory.OffsetImm) return true;
979 int64_t Val = Memory.OffsetImm->getValue();
980 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
982 bool isAlignedMemory() const {
983 return isMemNoOffset(true);
985 bool isAddrMode2() const {
986 if (!isMem() || Memory.Alignment != 0) return false;
987 // Check for register offset.
988 if (Memory.OffsetRegNum) return true;
989 // Immediate offset in range [-4095, 4095].
990 if (!Memory.OffsetImm) return true;
991 int64_t Val = Memory.OffsetImm->getValue();
992 return Val > -4096 && Val < 4096;
994 bool isAM2OffsetImm() const {
995 if (!isImm()) return false;
996 // Immediate offset in range [-4095, 4095].
997 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
998 if (!CE) return false;
999 int64_t Val = CE->getValue();
1000 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1002 bool isAddrMode3() const {
1003 // If we have an immediate that's not a constant, treat it as a label
1004 // reference needing a fixup. If it is a constant, it's something else
1005 // and we reject it.
1006 if (isImm() && !isa<MCConstantExpr>(getImm()))
1008 if (!isMem() || Memory.Alignment != 0) return false;
1009 // No shifts are legal for AM3.
1010 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1011 // Check for register offset.
1012 if (Memory.OffsetRegNum) return true;
1013 // Immediate offset in range [-255, 255].
1014 if (!Memory.OffsetImm) return true;
1015 int64_t Val = Memory.OffsetImm->getValue();
1016 // The #-0 offset is encoded as INT32_MIN, and we have to check
1018 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1020 bool isAM3Offset() const {
1021 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1023 if (Kind == k_PostIndexRegister)
1024 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1025 // Immediate offset in range [-255, 255].
1026 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1027 if (!CE) return false;
1028 int64_t Val = CE->getValue();
1029 // Special case, #-0 is INT32_MIN.
1030 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1032 bool isAddrMode5() const {
1033 // If we have an immediate that's not a constant, treat it as a label
1034 // reference needing a fixup. If it is a constant, it's something else
1035 // and we reject it.
1036 if (isImm() && !isa<MCConstantExpr>(getImm()))
1038 if (!isMem() || Memory.Alignment != 0) return false;
1039 // Check for register offset.
1040 if (Memory.OffsetRegNum) return false;
1041 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1042 if (!Memory.OffsetImm) return true;
1043 int64_t Val = Memory.OffsetImm->getValue();
1044 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1047 bool isMemTBB() const {
1048 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1049 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1053 bool isMemTBH() const {
1054 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1055 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1056 Memory.Alignment != 0 )
1060 bool isMemRegOffset() const {
1061 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1065 bool isT2MemRegOffset() const {
1066 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1067 Memory.Alignment != 0)
1069 // Only lsl #{0, 1, 2, 3} allowed.
1070 if (Memory.ShiftType == ARM_AM::no_shift)
1072 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1076 bool isMemThumbRR() const {
1077 // Thumb reg+reg addressing is simple. Just two registers, a base and
1078 // an offset. No shifts, negations or any other complicating factors.
1079 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1080 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1082 return isARMLowRegister(Memory.BaseRegNum) &&
1083 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1085 bool isMemThumbRIs4() const {
1086 if (!isMem() || Memory.OffsetRegNum != 0 ||
1087 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1089 // Immediate offset, multiple of 4 in range [0, 124].
1090 if (!Memory.OffsetImm) return true;
1091 int64_t Val = Memory.OffsetImm->getValue();
1092 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1094 bool isMemThumbRIs2() const {
1095 if (!isMem() || Memory.OffsetRegNum != 0 ||
1096 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1098 // Immediate offset, multiple of 4 in range [0, 62].
1099 if (!Memory.OffsetImm) return true;
1100 int64_t Val = Memory.OffsetImm->getValue();
1101 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1103 bool isMemThumbRIs1() const {
1104 if (!isMem() || Memory.OffsetRegNum != 0 ||
1105 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1107 // Immediate offset in range [0, 31].
1108 if (!Memory.OffsetImm) return true;
1109 int64_t Val = Memory.OffsetImm->getValue();
1110 return Val >= 0 && Val <= 31;
1112 bool isMemThumbSPI() const {
1113 if (!isMem() || Memory.OffsetRegNum != 0 ||
1114 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1116 // Immediate offset, multiple of 4 in range [0, 1020].
1117 if (!Memory.OffsetImm) return true;
1118 int64_t Val = Memory.OffsetImm->getValue();
1119 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1121 bool isMemImm8s4Offset() const {
1122 // If we have an immediate that's not a constant, treat it as a label
1123 // reference needing a fixup. If it is a constant, it's something else
1124 // and we reject it.
1125 if (isImm() && !isa<MCConstantExpr>(getImm()))
1127 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1129 // Immediate offset a multiple of 4 in range [-1020, 1020].
1130 if (!Memory.OffsetImm) return true;
1131 int64_t Val = Memory.OffsetImm->getValue();
1132 // Special case, #-0 is INT32_MIN.
1133 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1135 bool isMemImm0_1020s4Offset() const {
1136 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1138 // Immediate offset a multiple of 4 in range [0, 1020].
1139 if (!Memory.OffsetImm) return true;
1140 int64_t Val = Memory.OffsetImm->getValue();
1141 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1143 bool isMemImm8Offset() const {
1144 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1146 // Base reg of PC isn't allowed for these encodings.
1147 if (Memory.BaseRegNum == ARM::PC) return false;
1148 // Immediate offset in range [-255, 255].
1149 if (!Memory.OffsetImm) return true;
1150 int64_t Val = Memory.OffsetImm->getValue();
1151 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1153 bool isMemPosImm8Offset() const {
1154 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1156 // Immediate offset in range [0, 255].
1157 if (!Memory.OffsetImm) return true;
1158 int64_t Val = Memory.OffsetImm->getValue();
1159 return Val >= 0 && Val < 256;
1161 bool isMemNegImm8Offset() const {
1162 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1164 // Base reg of PC isn't allowed for these encodings.
1165 if (Memory.BaseRegNum == ARM::PC) return false;
1166 // Immediate offset in range [-255, -1].
1167 if (!Memory.OffsetImm) return false;
1168 int64_t Val = Memory.OffsetImm->getValue();
1169 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1171 bool isMemUImm12Offset() const {
1172 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1174 // Immediate offset in range [0, 4095].
1175 if (!Memory.OffsetImm) return true;
1176 int64_t Val = Memory.OffsetImm->getValue();
1177 return (Val >= 0 && Val < 4096);
1179 bool isMemImm12Offset() const {
1180 // If we have an immediate that's not a constant, treat it as a label
1181 // reference needing a fixup. If it is a constant, it's something else
1182 // and we reject it.
1183 if (isImm() && !isa<MCConstantExpr>(getImm()))
1186 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1188 // Immediate offset in range [-4095, 4095].
1189 if (!Memory.OffsetImm) return true;
1190 int64_t Val = Memory.OffsetImm->getValue();
1191 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1193 bool isPostIdxImm8() const {
1194 if (!isImm()) return false;
1195 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1196 if (!CE) return false;
1197 int64_t Val = CE->getValue();
1198 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1200 bool isPostIdxImm8s4() const {
1201 if (!isImm()) return false;
1202 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1203 if (!CE) return false;
1204 int64_t Val = CE->getValue();
1205 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1209 bool isMSRMask() const { return Kind == k_MSRMask; }
1210 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1213 bool isSingleSpacedVectorList() const {
1214 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1216 bool isDoubleSpacedVectorList() const {
1217 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1219 bool isVecListOneD() const {
1220 if (!isSingleSpacedVectorList()) return false;
1221 return VectorList.Count == 1;
1224 bool isVecListDPair() const {
1225 if (!isSingleSpacedVectorList()) return false;
1226 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1227 .contains(VectorList.RegNum));
1230 bool isVecListThreeD() const {
1231 if (!isSingleSpacedVectorList()) return false;
1232 return VectorList.Count == 3;
1235 bool isVecListFourD() const {
1236 if (!isSingleSpacedVectorList()) return false;
1237 return VectorList.Count == 4;
1240 bool isVecListDPairSpaced() const {
1241 if (isSingleSpacedVectorList()) return false;
1242 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1243 .contains(VectorList.RegNum));
1246 bool isVecListThreeQ() const {
1247 if (!isDoubleSpacedVectorList()) return false;
1248 return VectorList.Count == 3;
1251 bool isVecListFourQ() const {
1252 if (!isDoubleSpacedVectorList()) return false;
1253 return VectorList.Count == 4;
1256 bool isSingleSpacedVectorAllLanes() const {
1257 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1259 bool isDoubleSpacedVectorAllLanes() const {
1260 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1262 bool isVecListOneDAllLanes() const {
1263 if (!isSingleSpacedVectorAllLanes()) return false;
1264 return VectorList.Count == 1;
1267 bool isVecListDPairAllLanes() const {
1268 if (!isSingleSpacedVectorAllLanes()) return false;
1269 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1270 .contains(VectorList.RegNum));
1273 bool isVecListDPairSpacedAllLanes() const {
1274 if (!isDoubleSpacedVectorAllLanes()) return false;
1275 return VectorList.Count == 2;
1278 bool isVecListThreeDAllLanes() const {
1279 if (!isSingleSpacedVectorAllLanes()) return false;
1280 return VectorList.Count == 3;
1283 bool isVecListThreeQAllLanes() const {
1284 if (!isDoubleSpacedVectorAllLanes()) return false;
1285 return VectorList.Count == 3;
1288 bool isVecListFourDAllLanes() const {
1289 if (!isSingleSpacedVectorAllLanes()) return false;
1290 return VectorList.Count == 4;
1293 bool isVecListFourQAllLanes() const {
1294 if (!isDoubleSpacedVectorAllLanes()) return false;
1295 return VectorList.Count == 4;
1298 bool isSingleSpacedVectorIndexed() const {
1299 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1301 bool isDoubleSpacedVectorIndexed() const {
1302 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1304 bool isVecListOneDByteIndexed() const {
1305 if (!isSingleSpacedVectorIndexed()) return false;
1306 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1309 bool isVecListOneDHWordIndexed() const {
1310 if (!isSingleSpacedVectorIndexed()) return false;
1311 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1314 bool isVecListOneDWordIndexed() const {
1315 if (!isSingleSpacedVectorIndexed()) return false;
1316 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1319 bool isVecListTwoDByteIndexed() const {
1320 if (!isSingleSpacedVectorIndexed()) return false;
1321 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1324 bool isVecListTwoDHWordIndexed() const {
1325 if (!isSingleSpacedVectorIndexed()) return false;
1326 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1329 bool isVecListTwoQWordIndexed() const {
1330 if (!isDoubleSpacedVectorIndexed()) return false;
1331 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1334 bool isVecListTwoQHWordIndexed() const {
1335 if (!isDoubleSpacedVectorIndexed()) return false;
1336 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1339 bool isVecListTwoDWordIndexed() const {
1340 if (!isSingleSpacedVectorIndexed()) return false;
1341 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1344 bool isVecListThreeDByteIndexed() const {
1345 if (!isSingleSpacedVectorIndexed()) return false;
1346 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1349 bool isVecListThreeDHWordIndexed() const {
1350 if (!isSingleSpacedVectorIndexed()) return false;
1351 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1354 bool isVecListThreeQWordIndexed() const {
1355 if (!isDoubleSpacedVectorIndexed()) return false;
1356 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1359 bool isVecListThreeQHWordIndexed() const {
1360 if (!isDoubleSpacedVectorIndexed()) return false;
1361 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1364 bool isVecListThreeDWordIndexed() const {
1365 if (!isSingleSpacedVectorIndexed()) return false;
1366 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1369 bool isVecListFourDByteIndexed() const {
1370 if (!isSingleSpacedVectorIndexed()) return false;
1371 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1374 bool isVecListFourDHWordIndexed() const {
1375 if (!isSingleSpacedVectorIndexed()) return false;
1376 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1379 bool isVecListFourQWordIndexed() const {
1380 if (!isDoubleSpacedVectorIndexed()) return false;
1381 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1384 bool isVecListFourQHWordIndexed() const {
1385 if (!isDoubleSpacedVectorIndexed()) return false;
1386 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1389 bool isVecListFourDWordIndexed() const {
1390 if (!isSingleSpacedVectorIndexed()) return false;
1391 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1394 bool isVectorIndex8() const {
1395 if (Kind != k_VectorIndex) return false;
1396 return VectorIndex.Val < 8;
1398 bool isVectorIndex16() const {
1399 if (Kind != k_VectorIndex) return false;
1400 return VectorIndex.Val < 4;
1402 bool isVectorIndex32() const {
1403 if (Kind != k_VectorIndex) return false;
1404 return VectorIndex.Val < 2;
1407 bool isNEONi8splat() const {
1408 if (!isImm()) return false;
1409 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1410 // Must be a constant.
1411 if (!CE) return false;
1412 int64_t Value = CE->getValue();
1413 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1415 return Value >= 0 && Value < 256;
1418 bool isNEONi16splat() 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 // i16 value in the range [0,255] or [0x0100, 0xff00]
1425 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1428 bool isNEONi32splat() const {
1429 if (!isImm()) return false;
1430 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1431 // Must be a constant.
1432 if (!CE) return false;
1433 int64_t Value = CE->getValue();
1434 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1435 return (Value >= 0 && Value < 256) ||
1436 (Value >= 0x0100 && Value <= 0xff00) ||
1437 (Value >= 0x010000 && Value <= 0xff0000) ||
1438 (Value >= 0x01000000 && Value <= 0xff000000);
1441 bool isNEONi32vmov() const {
1442 if (!isImm()) return false;
1443 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1444 // Must be a constant.
1445 if (!CE) return false;
1446 int64_t Value = CE->getValue();
1447 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1448 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1449 return (Value >= 0 && Value < 256) ||
1450 (Value >= 0x0100 && Value <= 0xff00) ||
1451 (Value >= 0x010000 && Value <= 0xff0000) ||
1452 (Value >= 0x01000000 && Value <= 0xff000000) ||
1453 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1454 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1456 bool isNEONi32vmovNeg() const {
1457 if (!isImm()) return false;
1458 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1459 // Must be a constant.
1460 if (!CE) return false;
1461 int64_t Value = ~CE->getValue();
1462 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1463 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1464 return (Value >= 0 && Value < 256) ||
1465 (Value >= 0x0100 && Value <= 0xff00) ||
1466 (Value >= 0x010000 && Value <= 0xff0000) ||
1467 (Value >= 0x01000000 && Value <= 0xff000000) ||
1468 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1469 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1472 bool isNEONi64splat() const {
1473 if (!isImm()) return false;
1474 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1475 // Must be a constant.
1476 if (!CE) return false;
1477 uint64_t Value = CE->getValue();
1478 // i64 value with each byte being either 0 or 0xff.
1479 for (unsigned i = 0; i < 8; ++i)
1480 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1484 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1485 // Add as immediates when possible. Null MCExpr = 0.
1487 Inst.addOperand(MCOperand::CreateImm(0));
1488 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1489 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1491 Inst.addOperand(MCOperand::CreateExpr(Expr));
1494 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1495 assert(N == 2 && "Invalid number of operands!");
1496 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1497 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1498 Inst.addOperand(MCOperand::CreateReg(RegNum));
1501 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1502 assert(N == 1 && "Invalid number of operands!");
1503 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1506 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1507 assert(N == 1 && "Invalid number of operands!");
1508 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1511 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1512 assert(N == 1 && "Invalid number of operands!");
1513 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1516 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1517 assert(N == 1 && "Invalid number of operands!");
1518 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1521 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1522 assert(N == 1 && "Invalid number of operands!");
1523 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1526 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1527 assert(N == 1 && "Invalid number of operands!");
1528 Inst.addOperand(MCOperand::CreateReg(getReg()));
1531 void addRegOperands(MCInst &Inst, unsigned N) const {
1532 assert(N == 1 && "Invalid number of operands!");
1533 Inst.addOperand(MCOperand::CreateReg(getReg()));
1536 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1537 assert(N == 3 && "Invalid number of operands!");
1538 assert(isRegShiftedReg() &&
1539 "addRegShiftedRegOperands() on non RegShiftedReg!");
1540 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1541 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1542 Inst.addOperand(MCOperand::CreateImm(
1543 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1546 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1547 assert(N == 2 && "Invalid number of operands!");
1548 assert(isRegShiftedImm() &&
1549 "addRegShiftedImmOperands() on non RegShiftedImm!");
1550 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1551 // Shift of #32 is encoded as 0 where permitted
1552 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1553 Inst.addOperand(MCOperand::CreateImm(
1554 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1557 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1558 assert(N == 1 && "Invalid number of operands!");
1559 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1563 void addRegListOperands(MCInst &Inst, unsigned N) const {
1564 assert(N == 1 && "Invalid number of operands!");
1565 const SmallVectorImpl<unsigned> &RegList = getRegList();
1566 for (SmallVectorImpl<unsigned>::const_iterator
1567 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1568 Inst.addOperand(MCOperand::CreateReg(*I));
1571 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1572 addRegListOperands(Inst, N);
1575 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1576 addRegListOperands(Inst, N);
1579 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1580 assert(N == 1 && "Invalid number of operands!");
1581 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1582 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1585 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1586 assert(N == 1 && "Invalid number of operands!");
1587 // Munge the lsb/width into a bitfield mask.
1588 unsigned lsb = Bitfield.LSB;
1589 unsigned width = Bitfield.Width;
1590 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1591 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1592 (32 - (lsb + width)));
1593 Inst.addOperand(MCOperand::CreateImm(Mask));
1596 void addImmOperands(MCInst &Inst, unsigned N) const {
1597 assert(N == 1 && "Invalid number of operands!");
1598 addExpr(Inst, getImm());
1601 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1602 assert(N == 1 && "Invalid number of operands!");
1603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1604 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1607 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1608 assert(N == 1 && "Invalid number of operands!");
1609 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1610 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1613 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1614 assert(N == 1 && "Invalid number of operands!");
1615 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1616 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1617 Inst.addOperand(MCOperand::CreateImm(Val));
1620 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1621 assert(N == 1 && "Invalid number of operands!");
1622 // FIXME: We really want to scale the value here, but the LDRD/STRD
1623 // instruction don't encode operands that way yet.
1624 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1625 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1628 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1629 assert(N == 1 && "Invalid number of operands!");
1630 // The immediate is scaled by four in the encoding and is stored
1631 // in the MCInst as such. Lop off the low two bits here.
1632 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1633 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1636 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1637 assert(N == 1 && "Invalid number of operands!");
1638 // The immediate is scaled by four in the encoding and is stored
1639 // in the MCInst as such. Lop off the low two bits here.
1640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1641 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1644 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1645 assert(N == 1 && "Invalid number of operands!");
1646 // The immediate is scaled by four in the encoding and is stored
1647 // in the MCInst as such. Lop off the low two bits here.
1648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1649 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1652 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1653 assert(N == 1 && "Invalid number of operands!");
1654 // The constant encodes as the immediate-1, and we store in the instruction
1655 // the bits as encoded, so subtract off one here.
1656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1657 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1660 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1661 assert(N == 1 && "Invalid number of operands!");
1662 // The constant encodes as the immediate-1, and we store in the instruction
1663 // the bits as encoded, so subtract off one here.
1664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1665 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1668 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1669 assert(N == 1 && "Invalid number of operands!");
1670 // The constant encodes as the immediate, except for 32, which encodes as
1672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1673 unsigned Imm = CE->getValue();
1674 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1677 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1678 assert(N == 1 && "Invalid number of operands!");
1679 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1680 // the instruction as well.
1681 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1682 int Val = CE->getValue();
1683 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1686 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1687 assert(N == 1 && "Invalid number of operands!");
1688 // The operand is actually a t2_so_imm, but we have its bitwise
1689 // negation in the assembly source, so twiddle it here.
1690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1691 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1694 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1695 assert(N == 1 && "Invalid number of operands!");
1696 // The operand is actually a t2_so_imm, but we have its
1697 // negation in the assembly source, so twiddle it here.
1698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1699 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1702 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1703 assert(N == 1 && "Invalid number of operands!");
1704 // The operand is actually an imm0_4095, but we have its
1705 // negation in the assembly source, so twiddle it here.
1706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1707 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1710 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1711 assert(N == 1 && "Invalid number of operands!");
1712 // The operand is actually a so_imm, but we have its bitwise
1713 // negation in the assembly source, so twiddle it here.
1714 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1715 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1718 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1719 assert(N == 1 && "Invalid number of operands!");
1720 // The operand is actually a so_imm, but we have its
1721 // negation in the assembly source, so twiddle it here.
1722 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1723 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1726 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1727 assert(N == 1 && "Invalid number of operands!");
1728 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1731 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1732 assert(N == 1 && "Invalid number of operands!");
1733 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1736 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1737 assert(N == 1 && "Invalid number of operands!");
1738 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1741 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1742 assert(N == 1 && "Invalid number of operands!");
1743 int32_t Imm = Memory.OffsetImm->getValue();
1744 // FIXME: Handle #-0
1745 if (Imm == INT32_MIN) Imm = 0;
1746 Inst.addOperand(MCOperand::CreateImm(Imm));
1749 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1750 assert(N == 1 && "Invalid number of operands!");
1751 assert(isImm() && "Not an immediate!");
1753 // If we have an immediate that's not a constant, treat it as a label
1754 // reference needing a fixup.
1755 if (!isa<MCConstantExpr>(getImm())) {
1756 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1761 int Val = CE->getValue();
1762 Inst.addOperand(MCOperand::CreateImm(Val));
1765 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1766 assert(N == 2 && "Invalid number of operands!");
1767 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1768 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1771 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1772 assert(N == 3 && "Invalid number of operands!");
1773 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1774 if (!Memory.OffsetRegNum) {
1775 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1776 // Special case for #-0
1777 if (Val == INT32_MIN) Val = 0;
1778 if (Val < 0) Val = -Val;
1779 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1781 // For register offset, we encode the shift type and negation flag
1783 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1784 Memory.ShiftImm, Memory.ShiftType);
1786 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1787 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1788 Inst.addOperand(MCOperand::CreateImm(Val));
1791 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1792 assert(N == 2 && "Invalid number of operands!");
1793 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1794 assert(CE && "non-constant AM2OffsetImm operand!");
1795 int32_t Val = CE->getValue();
1796 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1797 // Special case for #-0
1798 if (Val == INT32_MIN) Val = 0;
1799 if (Val < 0) Val = -Val;
1800 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1801 Inst.addOperand(MCOperand::CreateReg(0));
1802 Inst.addOperand(MCOperand::CreateImm(Val));
1805 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1806 assert(N == 3 && "Invalid number of operands!");
1807 // If we have an immediate that's not a constant, treat it as a label
1808 // reference needing a fixup. If it is a constant, it's something else
1809 // and we reject it.
1811 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1812 Inst.addOperand(MCOperand::CreateReg(0));
1813 Inst.addOperand(MCOperand::CreateImm(0));
1817 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1818 if (!Memory.OffsetRegNum) {
1819 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1820 // Special case for #-0
1821 if (Val == INT32_MIN) Val = 0;
1822 if (Val < 0) Val = -Val;
1823 Val = ARM_AM::getAM3Opc(AddSub, Val);
1825 // For register offset, we encode the shift type and negation flag
1827 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1829 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1830 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1831 Inst.addOperand(MCOperand::CreateImm(Val));
1834 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1835 assert(N == 2 && "Invalid number of operands!");
1836 if (Kind == k_PostIndexRegister) {
1838 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1839 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1840 Inst.addOperand(MCOperand::CreateImm(Val));
1845 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1846 int32_t Val = CE->getValue();
1847 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1848 // Special case for #-0
1849 if (Val == INT32_MIN) Val = 0;
1850 if (Val < 0) Val = -Val;
1851 Val = ARM_AM::getAM3Opc(AddSub, Val);
1852 Inst.addOperand(MCOperand::CreateReg(0));
1853 Inst.addOperand(MCOperand::CreateImm(Val));
1856 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1857 assert(N == 2 && "Invalid number of operands!");
1858 // If we have an immediate that's not a constant, treat it as a label
1859 // reference needing a fixup. If it is a constant, it's something else
1860 // and we reject it.
1862 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1863 Inst.addOperand(MCOperand::CreateImm(0));
1867 // The lower two bits are always zero and as such are not encoded.
1868 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1869 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1870 // Special case for #-0
1871 if (Val == INT32_MIN) Val = 0;
1872 if (Val < 0) Val = -Val;
1873 Val = ARM_AM::getAM5Opc(AddSub, Val);
1874 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1875 Inst.addOperand(MCOperand::CreateImm(Val));
1878 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1879 assert(N == 2 && "Invalid number of operands!");
1880 // If we have an immediate that's not a constant, treat it as a label
1881 // reference needing a fixup. If it is a constant, it's something else
1882 // and we reject it.
1884 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1885 Inst.addOperand(MCOperand::CreateImm(0));
1889 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1890 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1891 Inst.addOperand(MCOperand::CreateImm(Val));
1894 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1895 assert(N == 2 && "Invalid number of operands!");
1896 // The lower two bits are always zero and as such are not encoded.
1897 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1898 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1899 Inst.addOperand(MCOperand::CreateImm(Val));
1902 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1903 assert(N == 2 && "Invalid number of operands!");
1904 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1905 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1906 Inst.addOperand(MCOperand::CreateImm(Val));
1909 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1910 addMemImm8OffsetOperands(Inst, N);
1913 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1914 addMemImm8OffsetOperands(Inst, N);
1917 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1918 assert(N == 2 && "Invalid number of operands!");
1919 // If this is an immediate, it's a label reference.
1921 addExpr(Inst, getImm());
1922 Inst.addOperand(MCOperand::CreateImm(0));
1926 // Otherwise, it's a normal memory reg+offset.
1927 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1928 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1929 Inst.addOperand(MCOperand::CreateImm(Val));
1932 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1933 assert(N == 2 && "Invalid number of operands!");
1934 // If this is an immediate, it's a label reference.
1936 addExpr(Inst, getImm());
1937 Inst.addOperand(MCOperand::CreateImm(0));
1941 // Otherwise, it's a normal memory reg+offset.
1942 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1943 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1944 Inst.addOperand(MCOperand::CreateImm(Val));
1947 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1948 assert(N == 2 && "Invalid number of operands!");
1949 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1950 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1953 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1954 assert(N == 2 && "Invalid number of operands!");
1955 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1956 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1959 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1960 assert(N == 3 && "Invalid number of operands!");
1962 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1963 Memory.ShiftImm, Memory.ShiftType);
1964 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1965 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1966 Inst.addOperand(MCOperand::CreateImm(Val));
1969 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1970 assert(N == 3 && "Invalid number of operands!");
1971 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1972 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1973 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
1976 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1977 assert(N == 2 && "Invalid number of operands!");
1978 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1979 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1982 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1983 assert(N == 2 && "Invalid number of operands!");
1984 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1985 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1986 Inst.addOperand(MCOperand::CreateImm(Val));
1989 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1990 assert(N == 2 && "Invalid number of operands!");
1991 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1992 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1993 Inst.addOperand(MCOperand::CreateImm(Val));
1996 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1997 assert(N == 2 && "Invalid number of operands!");
1998 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1999 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2000 Inst.addOperand(MCOperand::CreateImm(Val));
2003 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2004 assert(N == 2 && "Invalid number of operands!");
2005 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2006 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2007 Inst.addOperand(MCOperand::CreateImm(Val));
2010 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2011 assert(N == 1 && "Invalid number of operands!");
2012 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2013 assert(CE && "non-constant post-idx-imm8 operand!");
2014 int Imm = CE->getValue();
2015 bool isAdd = Imm >= 0;
2016 if (Imm == INT32_MIN) Imm = 0;
2017 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2018 Inst.addOperand(MCOperand::CreateImm(Imm));
2021 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2022 assert(N == 1 && "Invalid number of operands!");
2023 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2024 assert(CE && "non-constant post-idx-imm8s4 operand!");
2025 int Imm = CE->getValue();
2026 bool isAdd = Imm >= 0;
2027 if (Imm == INT32_MIN) Imm = 0;
2028 // Immediate is scaled by 4.
2029 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2030 Inst.addOperand(MCOperand::CreateImm(Imm));
2033 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2034 assert(N == 2 && "Invalid number of operands!");
2035 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2036 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2039 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2040 assert(N == 2 && "Invalid number of operands!");
2041 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2042 // The sign, shift type, and shift amount are encoded in a single operand
2043 // using the AM2 encoding helpers.
2044 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2045 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2046 PostIdxReg.ShiftTy);
2047 Inst.addOperand(MCOperand::CreateImm(Imm));
2050 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2051 assert(N == 1 && "Invalid number of operands!");
2052 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2055 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2056 assert(N == 1 && "Invalid number of operands!");
2057 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2060 void addVecListOperands(MCInst &Inst, unsigned N) const {
2061 assert(N == 1 && "Invalid number of operands!");
2062 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2065 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2066 assert(N == 2 && "Invalid number of operands!");
2067 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2068 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2071 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2072 assert(N == 1 && "Invalid number of operands!");
2073 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2076 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2077 assert(N == 1 && "Invalid number of operands!");
2078 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2081 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2082 assert(N == 1 && "Invalid number of operands!");
2083 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2086 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2087 assert(N == 1 && "Invalid number of operands!");
2088 // The immediate encodes the type of constant as well as the value.
2089 // Mask in that this is an i8 splat.
2090 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2091 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2094 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2095 assert(N == 1 && "Invalid number of operands!");
2096 // The immediate encodes the type of constant as well as the value.
2097 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2098 unsigned Value = CE->getValue();
2100 Value = (Value >> 8) | 0xa00;
2103 Inst.addOperand(MCOperand::CreateImm(Value));
2106 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2107 assert(N == 1 && "Invalid number of operands!");
2108 // The immediate encodes the type of constant as well as the value.
2109 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2110 unsigned Value = CE->getValue();
2111 if (Value >= 256 && Value <= 0xff00)
2112 Value = (Value >> 8) | 0x200;
2113 else if (Value > 0xffff && Value <= 0xff0000)
2114 Value = (Value >> 16) | 0x400;
2115 else if (Value > 0xffffff)
2116 Value = (Value >> 24) | 0x600;
2117 Inst.addOperand(MCOperand::CreateImm(Value));
2120 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2121 assert(N == 1 && "Invalid number of operands!");
2122 // The immediate encodes the type of constant as well as the value.
2123 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2124 unsigned Value = CE->getValue();
2125 if (Value >= 256 && Value <= 0xffff)
2126 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2127 else if (Value > 0xffff && Value <= 0xffffff)
2128 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2129 else if (Value > 0xffffff)
2130 Value = (Value >> 24) | 0x600;
2131 Inst.addOperand(MCOperand::CreateImm(Value));
2134 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2135 assert(N == 1 && "Invalid number of operands!");
2136 // The immediate encodes the type of constant as well as the value.
2137 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2138 unsigned Value = ~CE->getValue();
2139 if (Value >= 256 && Value <= 0xffff)
2140 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2141 else if (Value > 0xffff && Value <= 0xffffff)
2142 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2143 else if (Value > 0xffffff)
2144 Value = (Value >> 24) | 0x600;
2145 Inst.addOperand(MCOperand::CreateImm(Value));
2148 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2149 assert(N == 1 && "Invalid number of operands!");
2150 // The immediate encodes the type of constant as well as the value.
2151 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2152 uint64_t Value = CE->getValue();
2154 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2155 Imm |= (Value & 1) << i;
2157 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2160 virtual void print(raw_ostream &OS) const;
2162 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2163 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2164 Op->ITMask.Mask = Mask;
2170 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2171 ARMOperand *Op = new ARMOperand(k_CondCode);
2178 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2179 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2180 Op->Cop.Val = CopVal;
2186 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2187 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2188 Op->Cop.Val = CopVal;
2194 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2195 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2202 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2203 ARMOperand *Op = new ARMOperand(k_CCOut);
2204 Op->Reg.RegNum = RegNum;
2210 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2211 ARMOperand *Op = new ARMOperand(k_Token);
2212 Op->Tok.Data = Str.data();
2213 Op->Tok.Length = Str.size();
2219 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2220 ARMOperand *Op = new ARMOperand(k_Register);
2221 Op->Reg.RegNum = RegNum;
2227 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2232 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2233 Op->RegShiftedReg.ShiftTy = ShTy;
2234 Op->RegShiftedReg.SrcReg = SrcReg;
2235 Op->RegShiftedReg.ShiftReg = ShiftReg;
2236 Op->RegShiftedReg.ShiftImm = ShiftImm;
2242 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2246 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2247 Op->RegShiftedImm.ShiftTy = ShTy;
2248 Op->RegShiftedImm.SrcReg = SrcReg;
2249 Op->RegShiftedImm.ShiftImm = ShiftImm;
2255 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2257 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2258 Op->ShifterImm.isASR = isASR;
2259 Op->ShifterImm.Imm = Imm;
2265 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2266 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2267 Op->RotImm.Imm = Imm;
2273 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2275 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2276 Op->Bitfield.LSB = LSB;
2277 Op->Bitfield.Width = Width;
2284 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2285 SMLoc StartLoc, SMLoc EndLoc) {
2286 assert (Regs.size() > 0 && "RegList contains no registers?");
2287 KindTy Kind = k_RegisterList;
2289 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2290 Kind = k_DPRRegisterList;
2291 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2292 contains(Regs.front().second))
2293 Kind = k_SPRRegisterList;
2295 // Sort based on the register encoding values.
2296 array_pod_sort(Regs.begin(), Regs.end());
2298 ARMOperand *Op = new ARMOperand(Kind);
2299 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2300 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2301 Op->Registers.push_back(I->second);
2302 Op->StartLoc = StartLoc;
2303 Op->EndLoc = EndLoc;
2307 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2308 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2309 ARMOperand *Op = new ARMOperand(k_VectorList);
2310 Op->VectorList.RegNum = RegNum;
2311 Op->VectorList.Count = Count;
2312 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2318 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2319 bool isDoubleSpaced,
2321 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2322 Op->VectorList.RegNum = RegNum;
2323 Op->VectorList.Count = Count;
2324 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2330 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2332 bool isDoubleSpaced,
2334 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2335 Op->VectorList.RegNum = RegNum;
2336 Op->VectorList.Count = Count;
2337 Op->VectorList.LaneIndex = Index;
2338 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2344 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2346 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2347 Op->VectorIndex.Val = Idx;
2353 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2354 ARMOperand *Op = new ARMOperand(k_Immediate);
2361 static ARMOperand *CreateMem(unsigned BaseRegNum,
2362 const MCConstantExpr *OffsetImm,
2363 unsigned OffsetRegNum,
2364 ARM_AM::ShiftOpc ShiftType,
2369 ARMOperand *Op = new ARMOperand(k_Memory);
2370 Op->Memory.BaseRegNum = BaseRegNum;
2371 Op->Memory.OffsetImm = OffsetImm;
2372 Op->Memory.OffsetRegNum = OffsetRegNum;
2373 Op->Memory.ShiftType = ShiftType;
2374 Op->Memory.ShiftImm = ShiftImm;
2375 Op->Memory.Alignment = Alignment;
2376 Op->Memory.isNegative = isNegative;
2382 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2383 ARM_AM::ShiftOpc ShiftTy,
2386 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2387 Op->PostIdxReg.RegNum = RegNum;
2388 Op->PostIdxReg.isAdd = isAdd;
2389 Op->PostIdxReg.ShiftTy = ShiftTy;
2390 Op->PostIdxReg.ShiftImm = ShiftImm;
2396 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2397 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2398 Op->MBOpt.Val = Opt;
2404 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2406 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2407 Op->ISBOpt.Val = Opt;
2413 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2414 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2415 Op->IFlags.Val = IFlags;
2421 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2422 ARMOperand *Op = new ARMOperand(k_MSRMask);
2423 Op->MMask.Val = MMask;
2430 } // end anonymous namespace.
2432 void ARMOperand::print(raw_ostream &OS) const {
2435 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2438 OS << "<ccout " << getReg() << ">";
2440 case k_ITCondMask: {
2441 static const char *const MaskStr[] = {
2442 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2443 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2445 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2446 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2450 OS << "<coprocessor number: " << getCoproc() << ">";
2453 OS << "<coprocessor register: " << getCoproc() << ">";
2455 case k_CoprocOption:
2456 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2459 OS << "<mask: " << getMSRMask() << ">";
2462 getImm()->print(OS);
2464 case k_MemBarrierOpt:
2465 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2467 case k_InstSyncBarrierOpt:
2468 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2472 << " base:" << Memory.BaseRegNum;
2475 case k_PostIndexRegister:
2476 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2477 << PostIdxReg.RegNum;
2478 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2479 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2480 << PostIdxReg.ShiftImm;
2483 case k_ProcIFlags: {
2484 OS << "<ARM_PROC::";
2485 unsigned IFlags = getProcIFlags();
2486 for (int i=2; i >= 0; --i)
2487 if (IFlags & (1 << i))
2488 OS << ARM_PROC::IFlagsToString(1 << i);
2493 OS << "<register " << getReg() << ">";
2495 case k_ShifterImmediate:
2496 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2497 << " #" << ShifterImm.Imm << ">";
2499 case k_ShiftedRegister:
2500 OS << "<so_reg_reg "
2501 << RegShiftedReg.SrcReg << " "
2502 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2503 << " " << RegShiftedReg.ShiftReg << ">";
2505 case k_ShiftedImmediate:
2506 OS << "<so_reg_imm "
2507 << RegShiftedImm.SrcReg << " "
2508 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2509 << " #" << RegShiftedImm.ShiftImm << ">";
2511 case k_RotateImmediate:
2512 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2514 case k_BitfieldDescriptor:
2515 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2516 << ", width: " << Bitfield.Width << ">";
2518 case k_RegisterList:
2519 case k_DPRRegisterList:
2520 case k_SPRRegisterList: {
2521 OS << "<register_list ";
2523 const SmallVectorImpl<unsigned> &RegList = getRegList();
2524 for (SmallVectorImpl<unsigned>::const_iterator
2525 I = RegList.begin(), E = RegList.end(); I != E; ) {
2527 if (++I < E) OS << ", ";
2534 OS << "<vector_list " << VectorList.Count << " * "
2535 << VectorList.RegNum << ">";
2537 case k_VectorListAllLanes:
2538 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2539 << VectorList.RegNum << ">";
2541 case k_VectorListIndexed:
2542 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2543 << VectorList.Count << " * " << VectorList.RegNum << ">";
2546 OS << "'" << getToken() << "'";
2549 OS << "<vectorindex " << getVectorIndex() << ">";
2554 /// @name Auto-generated Match Functions
2557 static unsigned MatchRegisterName(StringRef Name);
2561 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2562 SMLoc &StartLoc, SMLoc &EndLoc) {
2563 StartLoc = Parser.getTok().getLoc();
2564 EndLoc = Parser.getTok().getEndLoc();
2565 RegNo = tryParseRegister();
2567 return (RegNo == (unsigned)-1);
2570 /// Try to parse a register name. The token must be an Identifier when called,
2571 /// and if it is a register name the token is eaten and the register number is
2572 /// returned. Otherwise return -1.
2574 int ARMAsmParser::tryParseRegister() {
2575 const AsmToken &Tok = Parser.getTok();
2576 if (Tok.isNot(AsmToken::Identifier)) return -1;
2578 std::string lowerCase = Tok.getString().lower();
2579 unsigned RegNum = MatchRegisterName(lowerCase);
2581 RegNum = StringSwitch<unsigned>(lowerCase)
2582 .Case("r13", ARM::SP)
2583 .Case("r14", ARM::LR)
2584 .Case("r15", ARM::PC)
2585 .Case("ip", ARM::R12)
2586 // Additional register name aliases for 'gas' compatibility.
2587 .Case("a1", ARM::R0)
2588 .Case("a2", ARM::R1)
2589 .Case("a3", ARM::R2)
2590 .Case("a4", ARM::R3)
2591 .Case("v1", ARM::R4)
2592 .Case("v2", ARM::R5)
2593 .Case("v3", ARM::R6)
2594 .Case("v4", ARM::R7)
2595 .Case("v5", ARM::R8)
2596 .Case("v6", ARM::R9)
2597 .Case("v7", ARM::R10)
2598 .Case("v8", ARM::R11)
2599 .Case("sb", ARM::R9)
2600 .Case("sl", ARM::R10)
2601 .Case("fp", ARM::R11)
2605 // Check for aliases registered via .req. Canonicalize to lower case.
2606 // That's more consistent since register names are case insensitive, and
2607 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2608 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2609 // If no match, return failure.
2610 if (Entry == RegisterReqs.end())
2612 Parser.Lex(); // Eat identifier token.
2613 return Entry->getValue();
2616 Parser.Lex(); // Eat identifier token.
2621 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2622 // If a recoverable error occurs, return 1. If an irrecoverable error
2623 // occurs, return -1. An irrecoverable error is one where tokens have been
2624 // consumed in the process of trying to parse the shifter (i.e., when it is
2625 // indeed a shifter operand, but malformed).
2626 int ARMAsmParser::tryParseShiftRegister(
2627 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2628 SMLoc S = Parser.getTok().getLoc();
2629 const AsmToken &Tok = Parser.getTok();
2630 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2632 std::string lowerCase = Tok.getString().lower();
2633 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2634 .Case("asl", ARM_AM::lsl)
2635 .Case("lsl", ARM_AM::lsl)
2636 .Case("lsr", ARM_AM::lsr)
2637 .Case("asr", ARM_AM::asr)
2638 .Case("ror", ARM_AM::ror)
2639 .Case("rrx", ARM_AM::rrx)
2640 .Default(ARM_AM::no_shift);
2642 if (ShiftTy == ARM_AM::no_shift)
2645 Parser.Lex(); // Eat the operator.
2647 // The source register for the shift has already been added to the
2648 // operand list, so we need to pop it off and combine it into the shifted
2649 // register operand instead.
2650 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2651 if (!PrevOp->isReg())
2652 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2653 int SrcReg = PrevOp->getReg();
2658 if (ShiftTy == ARM_AM::rrx) {
2659 // RRX Doesn't have an explicit shift amount. The encoder expects
2660 // the shift register to be the same as the source register. Seems odd,
2664 // Figure out if this is shifted by a constant or a register (for non-RRX).
2665 if (Parser.getTok().is(AsmToken::Hash) ||
2666 Parser.getTok().is(AsmToken::Dollar)) {
2667 Parser.Lex(); // Eat hash.
2668 SMLoc ImmLoc = Parser.getTok().getLoc();
2669 const MCExpr *ShiftExpr = 0;
2670 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2671 Error(ImmLoc, "invalid immediate shift value");
2674 // The expression must be evaluatable as an immediate.
2675 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2677 Error(ImmLoc, "invalid immediate shift value");
2680 // Range check the immediate.
2681 // lsl, ror: 0 <= imm <= 31
2682 // lsr, asr: 0 <= imm <= 32
2683 Imm = CE->getValue();
2685 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2686 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2687 Error(ImmLoc, "immediate shift value out of range");
2690 // shift by zero is a nop. Always send it through as lsl.
2691 // ('as' compatibility)
2693 ShiftTy = ARM_AM::lsl;
2694 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2695 SMLoc L = Parser.getTok().getLoc();
2696 EndLoc = Parser.getTok().getEndLoc();
2697 ShiftReg = tryParseRegister();
2698 if (ShiftReg == -1) {
2699 Error (L, "expected immediate or register in shift operand");
2703 Error (Parser.getTok().getLoc(),
2704 "expected immediate or register in shift operand");
2709 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2710 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2714 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2721 /// Try to parse a register name. The token must be an Identifier when called.
2722 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2723 /// if there is a "writeback". 'true' if it's not a register.
2725 /// TODO this is likely to change to allow different register types and or to
2726 /// parse for a specific register type.
2728 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2729 const AsmToken &RegTok = Parser.getTok();
2730 int RegNo = tryParseRegister();
2734 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2735 RegTok.getEndLoc()));
2737 const AsmToken &ExclaimTok = Parser.getTok();
2738 if (ExclaimTok.is(AsmToken::Exclaim)) {
2739 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2740 ExclaimTok.getLoc()));
2741 Parser.Lex(); // Eat exclaim token
2745 // Also check for an index operand. This is only legal for vector registers,
2746 // but that'll get caught OK in operand matching, so we don't need to
2747 // explicitly filter everything else out here.
2748 if (Parser.getTok().is(AsmToken::LBrac)) {
2749 SMLoc SIdx = Parser.getTok().getLoc();
2750 Parser.Lex(); // Eat left bracket token.
2752 const MCExpr *ImmVal;
2753 if (getParser().parseExpression(ImmVal))
2755 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2757 return TokError("immediate value expected for vector index");
2759 if (Parser.getTok().isNot(AsmToken::RBrac))
2760 return Error(Parser.getTok().getLoc(), "']' expected");
2762 SMLoc E = Parser.getTok().getEndLoc();
2763 Parser.Lex(); // Eat right bracket token.
2765 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2773 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2774 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2776 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2777 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2779 switch (Name.size()) {
2782 if (Name[0] != CoprocOp)
2798 if (Name[0] != CoprocOp || Name[1] != '1')
2802 case '0': return 10;
2803 case '1': return 11;
2804 case '2': return 12;
2805 case '3': return 13;
2806 case '4': return 14;
2807 case '5': return 15;
2812 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2813 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2814 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2815 SMLoc S = Parser.getTok().getLoc();
2816 const AsmToken &Tok = Parser.getTok();
2817 if (!Tok.is(AsmToken::Identifier))
2818 return MatchOperand_NoMatch;
2819 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2820 .Case("eq", ARMCC::EQ)
2821 .Case("ne", ARMCC::NE)
2822 .Case("hs", ARMCC::HS)
2823 .Case("cs", ARMCC::HS)
2824 .Case("lo", ARMCC::LO)
2825 .Case("cc", ARMCC::LO)
2826 .Case("mi", ARMCC::MI)
2827 .Case("pl", ARMCC::PL)
2828 .Case("vs", ARMCC::VS)
2829 .Case("vc", ARMCC::VC)
2830 .Case("hi", ARMCC::HI)
2831 .Case("ls", ARMCC::LS)
2832 .Case("ge", ARMCC::GE)
2833 .Case("lt", ARMCC::LT)
2834 .Case("gt", ARMCC::GT)
2835 .Case("le", ARMCC::LE)
2836 .Case("al", ARMCC::AL)
2839 return MatchOperand_NoMatch;
2840 Parser.Lex(); // Eat the token.
2842 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2844 return MatchOperand_Success;
2847 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2848 /// token must be an Identifier when called, and if it is a coprocessor
2849 /// number, the token is eaten and the operand is added to the operand list.
2850 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2851 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2852 SMLoc S = Parser.getTok().getLoc();
2853 const AsmToken &Tok = Parser.getTok();
2854 if (Tok.isNot(AsmToken::Identifier))
2855 return MatchOperand_NoMatch;
2857 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2859 return MatchOperand_NoMatch;
2861 Parser.Lex(); // Eat identifier token.
2862 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2863 return MatchOperand_Success;
2866 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2867 /// token must be an Identifier when called, and if it is a coprocessor
2868 /// number, the token is eaten and the operand is added to the operand list.
2869 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2870 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2871 SMLoc S = Parser.getTok().getLoc();
2872 const AsmToken &Tok = Parser.getTok();
2873 if (Tok.isNot(AsmToken::Identifier))
2874 return MatchOperand_NoMatch;
2876 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2878 return MatchOperand_NoMatch;
2880 Parser.Lex(); // Eat identifier token.
2881 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2882 return MatchOperand_Success;
2885 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2886 /// coproc_option : '{' imm0_255 '}'
2887 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2888 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2889 SMLoc S = Parser.getTok().getLoc();
2891 // If this isn't a '{', this isn't a coprocessor immediate operand.
2892 if (Parser.getTok().isNot(AsmToken::LCurly))
2893 return MatchOperand_NoMatch;
2894 Parser.Lex(); // Eat the '{'
2897 SMLoc Loc = Parser.getTok().getLoc();
2898 if (getParser().parseExpression(Expr)) {
2899 Error(Loc, "illegal expression");
2900 return MatchOperand_ParseFail;
2902 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2903 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2904 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2905 return MatchOperand_ParseFail;
2907 int Val = CE->getValue();
2909 // Check for and consume the closing '}'
2910 if (Parser.getTok().isNot(AsmToken::RCurly))
2911 return MatchOperand_ParseFail;
2912 SMLoc E = Parser.getTok().getEndLoc();
2913 Parser.Lex(); // Eat the '}'
2915 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2916 return MatchOperand_Success;
2919 // For register list parsing, we need to map from raw GPR register numbering
2920 // to the enumeration values. The enumeration values aren't sorted by
2921 // register number due to our using "sp", "lr" and "pc" as canonical names.
2922 static unsigned getNextRegister(unsigned Reg) {
2923 // If this is a GPR, we need to do it manually, otherwise we can rely
2924 // on the sort ordering of the enumeration since the other reg-classes
2926 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2929 default: llvm_unreachable("Invalid GPR number!");
2930 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2931 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2932 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2933 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2934 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2935 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2936 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2937 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2941 // Return the low-subreg of a given Q register.
2942 static unsigned getDRegFromQReg(unsigned QReg) {
2944 default: llvm_unreachable("expected a Q register!");
2945 case ARM::Q0: return ARM::D0;
2946 case ARM::Q1: return ARM::D2;
2947 case ARM::Q2: return ARM::D4;
2948 case ARM::Q3: return ARM::D6;
2949 case ARM::Q4: return ARM::D8;
2950 case ARM::Q5: return ARM::D10;
2951 case ARM::Q6: return ARM::D12;
2952 case ARM::Q7: return ARM::D14;
2953 case ARM::Q8: return ARM::D16;
2954 case ARM::Q9: return ARM::D18;
2955 case ARM::Q10: return ARM::D20;
2956 case ARM::Q11: return ARM::D22;
2957 case ARM::Q12: return ARM::D24;
2958 case ARM::Q13: return ARM::D26;
2959 case ARM::Q14: return ARM::D28;
2960 case ARM::Q15: return ARM::D30;
2964 /// Parse a register list.
2966 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2967 assert(Parser.getTok().is(AsmToken::LCurly) &&
2968 "Token is not a Left Curly Brace");
2969 SMLoc S = Parser.getTok().getLoc();
2970 Parser.Lex(); // Eat '{' token.
2971 SMLoc RegLoc = Parser.getTok().getLoc();
2973 // Check the first register in the list to see what register class
2974 // this is a list of.
2975 int Reg = tryParseRegister();
2977 return Error(RegLoc, "register expected");
2979 // The reglist instructions have at most 16 registers, so reserve
2980 // space for that many.
2982 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
2984 // Allow Q regs and just interpret them as the two D sub-registers.
2985 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2986 Reg = getDRegFromQReg(Reg);
2987 EReg = MRI->getEncodingValue(Reg);
2988 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
2991 const MCRegisterClass *RC;
2992 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2993 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2994 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2995 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2996 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2997 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2999 return Error(RegLoc, "invalid register in register list");
3001 // Store the register.
3002 EReg = MRI->getEncodingValue(Reg);
3003 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3005 // This starts immediately after the first register token in the list,
3006 // so we can see either a comma or a minus (range separator) as a legal
3008 while (Parser.getTok().is(AsmToken::Comma) ||
3009 Parser.getTok().is(AsmToken::Minus)) {
3010 if (Parser.getTok().is(AsmToken::Minus)) {
3011 Parser.Lex(); // Eat the minus.
3012 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3013 int EndReg = tryParseRegister();
3015 return Error(AfterMinusLoc, "register expected");
3016 // Allow Q regs and just interpret them as the two D sub-registers.
3017 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3018 EndReg = getDRegFromQReg(EndReg) + 1;
3019 // If the register is the same as the start reg, there's nothing
3023 // The register must be in the same register class as the first.
3024 if (!RC->contains(EndReg))
3025 return Error(AfterMinusLoc, "invalid register in register list");
3026 // Ranges must go from low to high.
3027 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3028 return Error(AfterMinusLoc, "bad range in register list");
3030 // Add all the registers in the range to the register list.
3031 while (Reg != EndReg) {
3032 Reg = getNextRegister(Reg);
3033 EReg = MRI->getEncodingValue(Reg);
3034 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3038 Parser.Lex(); // Eat the comma.
3039 RegLoc = Parser.getTok().getLoc();
3041 const AsmToken RegTok = Parser.getTok();
3042 Reg = tryParseRegister();
3044 return Error(RegLoc, "register expected");
3045 // Allow Q regs and just interpret them as the two D sub-registers.
3046 bool isQReg = false;
3047 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3048 Reg = getDRegFromQReg(Reg);
3051 // The register must be in the same register class as the first.
3052 if (!RC->contains(Reg))
3053 return Error(RegLoc, "invalid register in register list");
3054 // List must be monotonically increasing.
3055 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3056 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3057 Warning(RegLoc, "register list not in ascending order");
3059 return Error(RegLoc, "register list not in ascending order");
3061 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3062 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3063 ") in register list");
3066 // VFP register lists must also be contiguous.
3067 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3069 return Error(RegLoc, "non-contiguous register range");
3070 EReg = MRI->getEncodingValue(Reg);
3071 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3073 EReg = MRI->getEncodingValue(++Reg);
3074 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3078 if (Parser.getTok().isNot(AsmToken::RCurly))
3079 return Error(Parser.getTok().getLoc(), "'}' expected");
3080 SMLoc E = Parser.getTok().getEndLoc();
3081 Parser.Lex(); // Eat '}' token.
3083 // Push the register list operand.
3084 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3086 // The ARM system instruction variants for LDM/STM have a '^' token here.
3087 if (Parser.getTok().is(AsmToken::Caret)) {
3088 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3089 Parser.Lex(); // Eat '^' token.
3095 // Helper function to parse the lane index for vector lists.
3096 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3097 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3098 Index = 0; // Always return a defined index value.
3099 if (Parser.getTok().is(AsmToken::LBrac)) {
3100 Parser.Lex(); // Eat the '['.
3101 if (Parser.getTok().is(AsmToken::RBrac)) {
3102 // "Dn[]" is the 'all lanes' syntax.
3103 LaneKind = AllLanes;
3104 EndLoc = Parser.getTok().getEndLoc();
3105 Parser.Lex(); // Eat the ']'.
3106 return MatchOperand_Success;
3109 // There's an optional '#' token here. Normally there wouldn't be, but
3110 // inline assemble puts one in, and it's friendly to accept that.
3111 if (Parser.getTok().is(AsmToken::Hash))
3112 Parser.Lex(); // Eat '#' or '$'.
3114 const MCExpr *LaneIndex;
3115 SMLoc Loc = Parser.getTok().getLoc();
3116 if (getParser().parseExpression(LaneIndex)) {
3117 Error(Loc, "illegal expression");
3118 return MatchOperand_ParseFail;
3120 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3122 Error(Loc, "lane index must be empty or an integer");
3123 return MatchOperand_ParseFail;
3125 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3126 Error(Parser.getTok().getLoc(), "']' expected");
3127 return MatchOperand_ParseFail;
3129 EndLoc = Parser.getTok().getEndLoc();
3130 Parser.Lex(); // Eat the ']'.
3131 int64_t Val = CE->getValue();
3133 // FIXME: Make this range check context sensitive for .8, .16, .32.
3134 if (Val < 0 || Val > 7) {
3135 Error(Parser.getTok().getLoc(), "lane index out of range");
3136 return MatchOperand_ParseFail;
3139 LaneKind = IndexedLane;
3140 return MatchOperand_Success;
3143 return MatchOperand_Success;
3146 // parse a vector register list
3147 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3148 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3149 VectorLaneTy LaneKind;
3151 SMLoc S = Parser.getTok().getLoc();
3152 // As an extension (to match gas), support a plain D register or Q register
3153 // (without encosing curly braces) as a single or double entry list,
3155 if (Parser.getTok().is(AsmToken::Identifier)) {
3156 SMLoc E = Parser.getTok().getEndLoc();
3157 int Reg = tryParseRegister();
3159 return MatchOperand_NoMatch;
3160 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3161 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3162 if (Res != MatchOperand_Success)
3166 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3169 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3173 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3178 return MatchOperand_Success;
3180 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3181 Reg = getDRegFromQReg(Reg);
3182 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3183 if (Res != MatchOperand_Success)
3187 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3188 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3189 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3192 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3193 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3194 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3198 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3203 return MatchOperand_Success;
3205 Error(S, "vector register expected");
3206 return MatchOperand_ParseFail;
3209 if (Parser.getTok().isNot(AsmToken::LCurly))
3210 return MatchOperand_NoMatch;
3212 Parser.Lex(); // Eat '{' token.
3213 SMLoc RegLoc = Parser.getTok().getLoc();
3215 int Reg = tryParseRegister();
3217 Error(RegLoc, "register expected");
3218 return MatchOperand_ParseFail;
3222 unsigned FirstReg = Reg;
3223 // The list is of D registers, but we also allow Q regs and just interpret
3224 // them as the two D sub-registers.
3225 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3226 FirstReg = Reg = getDRegFromQReg(Reg);
3227 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3228 // it's ambiguous with four-register single spaced.
3234 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3235 return MatchOperand_ParseFail;
3237 while (Parser.getTok().is(AsmToken::Comma) ||
3238 Parser.getTok().is(AsmToken::Minus)) {
3239 if (Parser.getTok().is(AsmToken::Minus)) {
3241 Spacing = 1; // Register range implies a single spaced list.
3242 else if (Spacing == 2) {
3243 Error(Parser.getTok().getLoc(),
3244 "sequential registers in double spaced list");
3245 return MatchOperand_ParseFail;
3247 Parser.Lex(); // Eat the minus.
3248 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3249 int EndReg = tryParseRegister();
3251 Error(AfterMinusLoc, "register expected");
3252 return MatchOperand_ParseFail;
3254 // Allow Q regs and just interpret them as the two D sub-registers.
3255 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3256 EndReg = getDRegFromQReg(EndReg) + 1;
3257 // If the register is the same as the start reg, there's nothing
3261 // The register must be in the same register class as the first.
3262 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3263 Error(AfterMinusLoc, "invalid register in register list");
3264 return MatchOperand_ParseFail;
3266 // Ranges must go from low to high.
3268 Error(AfterMinusLoc, "bad range in register list");
3269 return MatchOperand_ParseFail;
3271 // Parse the lane specifier if present.
3272 VectorLaneTy NextLaneKind;
3273 unsigned NextLaneIndex;
3274 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3275 MatchOperand_Success)
3276 return MatchOperand_ParseFail;
3277 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3278 Error(AfterMinusLoc, "mismatched lane index in register list");
3279 return MatchOperand_ParseFail;
3282 // Add all the registers in the range to the register list.
3283 Count += EndReg - Reg;
3287 Parser.Lex(); // Eat the comma.
3288 RegLoc = Parser.getTok().getLoc();
3290 Reg = tryParseRegister();
3292 Error(RegLoc, "register expected");
3293 return MatchOperand_ParseFail;
3295 // vector register lists must be contiguous.
3296 // It's OK to use the enumeration values directly here rather, as the
3297 // VFP register classes have the enum sorted properly.
3299 // The list is of D registers, but we also allow Q regs and just interpret
3300 // them as the two D sub-registers.
3301 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3303 Spacing = 1; // Register range implies a single spaced list.
3304 else if (Spacing == 2) {
3306 "invalid register in double-spaced list (must be 'D' register')");
3307 return MatchOperand_ParseFail;
3309 Reg = getDRegFromQReg(Reg);
3310 if (Reg != OldReg + 1) {
3311 Error(RegLoc, "non-contiguous register range");
3312 return MatchOperand_ParseFail;
3316 // Parse the lane specifier if present.
3317 VectorLaneTy NextLaneKind;
3318 unsigned NextLaneIndex;
3319 SMLoc LaneLoc = Parser.getTok().getLoc();
3320 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3321 MatchOperand_Success)
3322 return MatchOperand_ParseFail;
3323 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3324 Error(LaneLoc, "mismatched lane index in register list");
3325 return MatchOperand_ParseFail;
3329 // Normal D register.
3330 // Figure out the register spacing (single or double) of the list if
3331 // we don't know it already.
3333 Spacing = 1 + (Reg == OldReg + 2);
3335 // Just check that it's contiguous and keep going.
3336 if (Reg != OldReg + Spacing) {
3337 Error(RegLoc, "non-contiguous register range");
3338 return MatchOperand_ParseFail;
3341 // Parse the lane specifier if present.
3342 VectorLaneTy NextLaneKind;
3343 unsigned NextLaneIndex;
3344 SMLoc EndLoc = Parser.getTok().getLoc();
3345 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3346 return MatchOperand_ParseFail;
3347 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3348 Error(EndLoc, "mismatched lane index in register list");
3349 return MatchOperand_ParseFail;
3353 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3354 Error(Parser.getTok().getLoc(), "'}' expected");
3355 return MatchOperand_ParseFail;
3357 E = Parser.getTok().getEndLoc();
3358 Parser.Lex(); // Eat '}' token.
3362 // Two-register operands have been converted to the
3363 // composite register classes.
3365 const MCRegisterClass *RC = (Spacing == 1) ?
3366 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3367 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3368 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3371 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3372 (Spacing == 2), S, E));
3375 // Two-register operands have been converted to the
3376 // composite register classes.
3378 const MCRegisterClass *RC = (Spacing == 1) ?
3379 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3380 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3381 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3383 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3388 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3394 return MatchOperand_Success;
3397 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3398 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3399 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3400 SMLoc S = Parser.getTok().getLoc();
3401 const AsmToken &Tok = Parser.getTok();
3404 if (Tok.is(AsmToken::Identifier)) {
3405 StringRef OptStr = Tok.getString();
3407 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3408 .Case("sy", ARM_MB::SY)
3409 .Case("st", ARM_MB::ST)
3410 .Case("sh", ARM_MB::ISH)
3411 .Case("ish", ARM_MB::ISH)
3412 .Case("shst", ARM_MB::ISHST)
3413 .Case("ishst", ARM_MB::ISHST)
3414 .Case("nsh", ARM_MB::NSH)
3415 .Case("un", ARM_MB::NSH)
3416 .Case("nshst", ARM_MB::NSHST)
3417 .Case("unst", ARM_MB::NSHST)
3418 .Case("osh", ARM_MB::OSH)
3419 .Case("oshst", ARM_MB::OSHST)
3423 return MatchOperand_NoMatch;
3425 Parser.Lex(); // Eat identifier token.
3426 } else if (Tok.is(AsmToken::Hash) ||
3427 Tok.is(AsmToken::Dollar) ||
3428 Tok.is(AsmToken::Integer)) {
3429 if (Parser.getTok().isNot(AsmToken::Integer))
3430 Parser.Lex(); // Eat '#' or '$'.
3431 SMLoc Loc = Parser.getTok().getLoc();
3433 const MCExpr *MemBarrierID;
3434 if (getParser().parseExpression(MemBarrierID)) {
3435 Error(Loc, "illegal expression");
3436 return MatchOperand_ParseFail;
3439 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3441 Error(Loc, "constant expression expected");
3442 return MatchOperand_ParseFail;
3445 int Val = CE->getValue();
3447 Error(Loc, "immediate value out of range");
3448 return MatchOperand_ParseFail;
3451 Opt = ARM_MB::RESERVED_0 + Val;
3453 return MatchOperand_ParseFail;
3455 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3456 return MatchOperand_Success;
3459 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3460 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3461 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3462 SMLoc S = Parser.getTok().getLoc();
3463 const AsmToken &Tok = Parser.getTok();
3466 if (Tok.is(AsmToken::Identifier)) {
3467 StringRef OptStr = Tok.getString();
3469 if (OptStr.lower() == "sy")
3472 return MatchOperand_NoMatch;
3474 Parser.Lex(); // Eat identifier token.
3475 } else if (Tok.is(AsmToken::Hash) ||
3476 Tok.is(AsmToken::Dollar) ||
3477 Tok.is(AsmToken::Integer)) {
3478 if (Parser.getTok().isNot(AsmToken::Integer))
3479 Parser.Lex(); // Eat '#' or '$'.
3480 SMLoc Loc = Parser.getTok().getLoc();
3482 const MCExpr *ISBarrierID;
3483 if (getParser().parseExpression(ISBarrierID)) {
3484 Error(Loc, "illegal expression");
3485 return MatchOperand_ParseFail;
3488 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3490 Error(Loc, "constant expression expected");
3491 return MatchOperand_ParseFail;
3494 int Val = CE->getValue();
3496 Error(Loc, "immediate value out of range");
3497 return MatchOperand_ParseFail;
3500 Opt = ARM_ISB::RESERVED_0 + Val;
3502 return MatchOperand_ParseFail;
3504 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3505 (ARM_ISB::InstSyncBOpt)Opt, S));
3506 return MatchOperand_Success;
3510 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3511 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3512 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3513 SMLoc S = Parser.getTok().getLoc();
3514 const AsmToken &Tok = Parser.getTok();
3515 if (!Tok.is(AsmToken::Identifier))
3516 return MatchOperand_NoMatch;
3517 StringRef IFlagsStr = Tok.getString();
3519 // An iflags string of "none" is interpreted to mean that none of the AIF
3520 // bits are set. Not a terribly useful instruction, but a valid encoding.
3521 unsigned IFlags = 0;
3522 if (IFlagsStr != "none") {
3523 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3524 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3525 .Case("a", ARM_PROC::A)
3526 .Case("i", ARM_PROC::I)
3527 .Case("f", ARM_PROC::F)
3530 // If some specific iflag is already set, it means that some letter is
3531 // present more than once, this is not acceptable.
3532 if (Flag == ~0U || (IFlags & Flag))
3533 return MatchOperand_NoMatch;
3539 Parser.Lex(); // Eat identifier token.
3540 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3541 return MatchOperand_Success;
3544 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3545 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3546 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3547 SMLoc S = Parser.getTok().getLoc();
3548 const AsmToken &Tok = Parser.getTok();
3549 if (!Tok.is(AsmToken::Identifier))
3550 return MatchOperand_NoMatch;
3551 StringRef Mask = Tok.getString();
3554 // See ARMv6-M 10.1.1
3555 std::string Name = Mask.lower();
3556 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3557 // Note: in the documentation:
3558 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3559 // for MSR APSR_nzcvq.
3560 // but we do make it an alias here. This is so to get the "mask encoding"
3561 // bits correct on MSR APSR writes.
3563 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3564 // should really only be allowed when writing a special register. Note
3565 // they get dropped in the MRS instruction reading a special register as
3566 // the SYSm field is only 8 bits.
3568 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3569 // includes the DSP extension but that is not checked.
3570 .Case("apsr", 0x800)
3571 .Case("apsr_nzcvq", 0x800)
3572 .Case("apsr_g", 0x400)
3573 .Case("apsr_nzcvqg", 0xc00)
3574 .Case("iapsr", 0x801)
3575 .Case("iapsr_nzcvq", 0x801)
3576 .Case("iapsr_g", 0x401)
3577 .Case("iapsr_nzcvqg", 0xc01)
3578 .Case("eapsr", 0x802)
3579 .Case("eapsr_nzcvq", 0x802)
3580 .Case("eapsr_g", 0x402)
3581 .Case("eapsr_nzcvqg", 0xc02)
3582 .Case("xpsr", 0x803)
3583 .Case("xpsr_nzcvq", 0x803)
3584 .Case("xpsr_g", 0x403)
3585 .Case("xpsr_nzcvqg", 0xc03)
3586 .Case("ipsr", 0x805)
3587 .Case("epsr", 0x806)
3588 .Case("iepsr", 0x807)
3591 .Case("primask", 0x810)
3592 .Case("basepri", 0x811)
3593 .Case("basepri_max", 0x812)
3594 .Case("faultmask", 0x813)
3595 .Case("control", 0x814)
3598 if (FlagsVal == ~0U)
3599 return MatchOperand_NoMatch;
3601 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3602 // basepri, basepri_max and faultmask only valid for V7m.
3603 return MatchOperand_NoMatch;
3605 Parser.Lex(); // Eat identifier token.
3606 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3607 return MatchOperand_Success;
3610 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3611 size_t Start = 0, Next = Mask.find('_');
3612 StringRef Flags = "";
3613 std::string SpecReg = Mask.slice(Start, Next).lower();
3614 if (Next != StringRef::npos)
3615 Flags = Mask.slice(Next+1, Mask.size());
3617 // FlagsVal contains the complete mask:
3619 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3620 unsigned FlagsVal = 0;
3622 if (SpecReg == "apsr") {
3623 FlagsVal = StringSwitch<unsigned>(Flags)
3624 .Case("nzcvq", 0x8) // same as CPSR_f
3625 .Case("g", 0x4) // same as CPSR_s
3626 .Case("nzcvqg", 0xc) // same as CPSR_fs
3629 if (FlagsVal == ~0U) {
3631 return MatchOperand_NoMatch;
3633 FlagsVal = 8; // No flag
3635 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3636 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3637 if (Flags == "all" || Flags == "")
3639 for (int i = 0, e = Flags.size(); i != e; ++i) {
3640 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3647 // If some specific flag is already set, it means that some letter is
3648 // present more than once, this is not acceptable.
3649 if (FlagsVal == ~0U || (FlagsVal & Flag))
3650 return MatchOperand_NoMatch;
3653 } else // No match for special register.
3654 return MatchOperand_NoMatch;
3656 // Special register without flags is NOT equivalent to "fc" flags.
3657 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3658 // two lines would enable gas compatibility at the expense of breaking
3664 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3665 if (SpecReg == "spsr")
3668 Parser.Lex(); // Eat identifier token.
3669 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3670 return MatchOperand_Success;
3673 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3674 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3675 int Low, int High) {
3676 const AsmToken &Tok = Parser.getTok();
3677 if (Tok.isNot(AsmToken::Identifier)) {
3678 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3679 return MatchOperand_ParseFail;
3681 StringRef ShiftName = Tok.getString();
3682 std::string LowerOp = Op.lower();
3683 std::string UpperOp = Op.upper();
3684 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3685 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3686 return MatchOperand_ParseFail;
3688 Parser.Lex(); // Eat shift type token.
3690 // There must be a '#' and a shift amount.
3691 if (Parser.getTok().isNot(AsmToken::Hash) &&
3692 Parser.getTok().isNot(AsmToken::Dollar)) {
3693 Error(Parser.getTok().getLoc(), "'#' expected");
3694 return MatchOperand_ParseFail;
3696 Parser.Lex(); // Eat hash token.
3698 const MCExpr *ShiftAmount;
3699 SMLoc Loc = Parser.getTok().getLoc();
3701 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3702 Error(Loc, "illegal expression");
3703 return MatchOperand_ParseFail;
3705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3707 Error(Loc, "constant expression expected");
3708 return MatchOperand_ParseFail;
3710 int Val = CE->getValue();
3711 if (Val < Low || Val > High) {
3712 Error(Loc, "immediate value out of range");
3713 return MatchOperand_ParseFail;
3716 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3718 return MatchOperand_Success;
3721 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3722 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3723 const AsmToken &Tok = Parser.getTok();
3724 SMLoc S = Tok.getLoc();
3725 if (Tok.isNot(AsmToken::Identifier)) {
3726 Error(S, "'be' or 'le' operand expected");
3727 return MatchOperand_ParseFail;
3729 int Val = StringSwitch<int>(Tok.getString().lower())
3733 Parser.Lex(); // Eat the token.
3736 Error(S, "'be' or 'le' operand expected");
3737 return MatchOperand_ParseFail;
3739 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3741 S, Tok.getEndLoc()));
3742 return MatchOperand_Success;
3745 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3746 /// instructions. Legal values are:
3747 /// lsl #n 'n' in [0,31]
3748 /// asr #n 'n' in [1,32]
3749 /// n == 32 encoded as n == 0.
3750 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3751 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3752 const AsmToken &Tok = Parser.getTok();
3753 SMLoc S = Tok.getLoc();
3754 if (Tok.isNot(AsmToken::Identifier)) {
3755 Error(S, "shift operator 'asr' or 'lsl' expected");
3756 return MatchOperand_ParseFail;
3758 StringRef ShiftName = Tok.getString();
3760 if (ShiftName == "lsl" || ShiftName == "LSL")
3762 else if (ShiftName == "asr" || ShiftName == "ASR")
3765 Error(S, "shift operator 'asr' or 'lsl' expected");
3766 return MatchOperand_ParseFail;
3768 Parser.Lex(); // Eat the operator.
3770 // A '#' and a shift amount.
3771 if (Parser.getTok().isNot(AsmToken::Hash) &&
3772 Parser.getTok().isNot(AsmToken::Dollar)) {
3773 Error(Parser.getTok().getLoc(), "'#' expected");
3774 return MatchOperand_ParseFail;
3776 Parser.Lex(); // Eat hash token.
3777 SMLoc ExLoc = Parser.getTok().getLoc();
3779 const MCExpr *ShiftAmount;
3781 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3782 Error(ExLoc, "malformed shift expression");
3783 return MatchOperand_ParseFail;
3785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3787 Error(ExLoc, "shift amount must be an immediate");
3788 return MatchOperand_ParseFail;
3791 int64_t Val = CE->getValue();
3793 // Shift amount must be in [1,32]
3794 if (Val < 1 || Val > 32) {
3795 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3796 return MatchOperand_ParseFail;
3798 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3799 if (isThumb() && Val == 32) {
3800 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3801 return MatchOperand_ParseFail;
3803 if (Val == 32) Val = 0;
3805 // Shift amount must be in [1,32]
3806 if (Val < 0 || Val > 31) {
3807 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3808 return MatchOperand_ParseFail;
3812 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3814 return MatchOperand_Success;
3817 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3818 /// of instructions. Legal values are:
3819 /// ror #n 'n' in {0, 8, 16, 24}
3820 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3821 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3822 const AsmToken &Tok = Parser.getTok();
3823 SMLoc S = Tok.getLoc();
3824 if (Tok.isNot(AsmToken::Identifier))
3825 return MatchOperand_NoMatch;
3826 StringRef ShiftName = Tok.getString();
3827 if (ShiftName != "ror" && ShiftName != "ROR")
3828 return MatchOperand_NoMatch;
3829 Parser.Lex(); // Eat the operator.
3831 // A '#' and a rotate amount.
3832 if (Parser.getTok().isNot(AsmToken::Hash) &&
3833 Parser.getTok().isNot(AsmToken::Dollar)) {
3834 Error(Parser.getTok().getLoc(), "'#' expected");
3835 return MatchOperand_ParseFail;
3837 Parser.Lex(); // Eat hash token.
3838 SMLoc ExLoc = Parser.getTok().getLoc();
3840 const MCExpr *ShiftAmount;
3842 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3843 Error(ExLoc, "malformed rotate expression");
3844 return MatchOperand_ParseFail;
3846 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3848 Error(ExLoc, "rotate amount must be an immediate");
3849 return MatchOperand_ParseFail;
3852 int64_t Val = CE->getValue();
3853 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3854 // normally, zero is represented in asm by omitting the rotate operand
3856 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3857 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
3858 return MatchOperand_ParseFail;
3861 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
3863 return MatchOperand_Success;
3866 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3867 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3868 SMLoc S = Parser.getTok().getLoc();
3869 // The bitfield descriptor is really two operands, the LSB and the width.
3870 if (Parser.getTok().isNot(AsmToken::Hash) &&
3871 Parser.getTok().isNot(AsmToken::Dollar)) {
3872 Error(Parser.getTok().getLoc(), "'#' expected");
3873 return MatchOperand_ParseFail;
3875 Parser.Lex(); // Eat hash token.
3877 const MCExpr *LSBExpr;
3878 SMLoc E = Parser.getTok().getLoc();
3879 if (getParser().parseExpression(LSBExpr)) {
3880 Error(E, "malformed immediate expression");
3881 return MatchOperand_ParseFail;
3883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3885 Error(E, "'lsb' operand must be an immediate");
3886 return MatchOperand_ParseFail;
3889 int64_t LSB = CE->getValue();
3890 // The LSB must be in the range [0,31]
3891 if (LSB < 0 || LSB > 31) {
3892 Error(E, "'lsb' operand must be in the range [0,31]");
3893 return MatchOperand_ParseFail;
3895 E = Parser.getTok().getLoc();
3897 // Expect another immediate operand.
3898 if (Parser.getTok().isNot(AsmToken::Comma)) {
3899 Error(Parser.getTok().getLoc(), "too few operands");
3900 return MatchOperand_ParseFail;
3902 Parser.Lex(); // Eat hash token.
3903 if (Parser.getTok().isNot(AsmToken::Hash) &&
3904 Parser.getTok().isNot(AsmToken::Dollar)) {
3905 Error(Parser.getTok().getLoc(), "'#' expected");
3906 return MatchOperand_ParseFail;
3908 Parser.Lex(); // Eat hash token.
3910 const MCExpr *WidthExpr;
3912 if (getParser().parseExpression(WidthExpr, EndLoc)) {
3913 Error(E, "malformed immediate expression");
3914 return MatchOperand_ParseFail;
3916 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3918 Error(E, "'width' operand must be an immediate");
3919 return MatchOperand_ParseFail;
3922 int64_t Width = CE->getValue();
3923 // The LSB must be in the range [1,32-lsb]
3924 if (Width < 1 || Width > 32 - LSB) {
3925 Error(E, "'width' operand must be in the range [1,32-lsb]");
3926 return MatchOperand_ParseFail;
3929 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
3931 return MatchOperand_Success;
3934 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3935 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3936 // Check for a post-index addressing register operand. Specifically:
3937 // postidx_reg := '+' register {, shift}
3938 // | '-' register {, shift}
3939 // | register {, shift}
3941 // This method must return MatchOperand_NoMatch without consuming any tokens
3942 // in the case where there is no match, as other alternatives take other
3944 AsmToken Tok = Parser.getTok();
3945 SMLoc S = Tok.getLoc();
3946 bool haveEaten = false;
3948 if (Tok.is(AsmToken::Plus)) {
3949 Parser.Lex(); // Eat the '+' token.
3951 } else if (Tok.is(AsmToken::Minus)) {
3952 Parser.Lex(); // Eat the '-' token.
3957 SMLoc E = Parser.getTok().getEndLoc();
3958 int Reg = tryParseRegister();
3961 return MatchOperand_NoMatch;
3962 Error(Parser.getTok().getLoc(), "register expected");
3963 return MatchOperand_ParseFail;
3966 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3967 unsigned ShiftImm = 0;
3968 if (Parser.getTok().is(AsmToken::Comma)) {
3969 Parser.Lex(); // Eat the ','.
3970 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3971 return MatchOperand_ParseFail;
3973 // FIXME: Only approximates end...may include intervening whitespace.
3974 E = Parser.getTok().getLoc();
3977 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3980 return MatchOperand_Success;
3983 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3984 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3985 // Check for a post-index addressing register operand. Specifically:
3986 // am3offset := '+' register
3993 // This method must return MatchOperand_NoMatch without consuming any tokens
3994 // in the case where there is no match, as other alternatives take other
3996 AsmToken Tok = Parser.getTok();
3997 SMLoc S = Tok.getLoc();
3999 // Do immediates first, as we always parse those if we have a '#'.
4000 if (Parser.getTok().is(AsmToken::Hash) ||
4001 Parser.getTok().is(AsmToken::Dollar)) {
4002 Parser.Lex(); // Eat '#' or '$'.
4003 // Explicitly look for a '-', as we need to encode negative zero
4005 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4006 const MCExpr *Offset;
4008 if (getParser().parseExpression(Offset, E))
4009 return MatchOperand_ParseFail;
4010 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4012 Error(S, "constant expression expected");
4013 return MatchOperand_ParseFail;
4015 // Negative zero is encoded as the flag value INT32_MIN.
4016 int32_t Val = CE->getValue();
4017 if (isNegative && Val == 0)
4021 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4023 return MatchOperand_Success;
4027 bool haveEaten = false;
4029 if (Tok.is(AsmToken::Plus)) {
4030 Parser.Lex(); // Eat the '+' token.
4032 } else if (Tok.is(AsmToken::Minus)) {
4033 Parser.Lex(); // Eat the '-' token.
4038 Tok = Parser.getTok();
4039 int Reg = tryParseRegister();
4042 return MatchOperand_NoMatch;
4043 Error(Tok.getLoc(), "register expected");
4044 return MatchOperand_ParseFail;
4047 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4048 0, S, Tok.getEndLoc()));
4050 return MatchOperand_Success;
4053 /// cvtT2LdrdPre - Convert parsed operands to MCInst.
4054 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4055 /// when they refer multiple MIOperands inside a single one.
4057 cvtT2LdrdPre(MCInst &Inst,
4058 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4060 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4061 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4062 // Create a writeback register dummy placeholder.
4063 Inst.addOperand(MCOperand::CreateReg(0));
4065 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4067 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4070 /// cvtT2StrdPre - Convert parsed operands to MCInst.
4071 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4072 /// when they refer multiple MIOperands inside a single one.
4074 cvtT2StrdPre(MCInst &Inst,
4075 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4076 // Create a writeback register dummy placeholder.
4077 Inst.addOperand(MCOperand::CreateReg(0));
4079 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4080 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4082 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4084 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4087 /// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4088 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4089 /// when they refer multiple MIOperands inside a single one.
4091 cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
4092 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4093 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4095 // Create a writeback register dummy placeholder.
4096 Inst.addOperand(MCOperand::CreateImm(0));
4098 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4099 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4102 /// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4103 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4104 /// when they refer multiple MIOperands inside a single one.
4106 cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
4107 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4108 // Create a writeback register dummy placeholder.
4109 Inst.addOperand(MCOperand::CreateImm(0));
4110 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4111 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4112 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4115 /// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
4116 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4117 /// when they refer multiple MIOperands inside a single one.
4119 cvtLdWriteBackRegAddrMode2(MCInst &Inst,
4120 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4121 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4123 // Create a writeback register dummy placeholder.
4124 Inst.addOperand(MCOperand::CreateImm(0));
4126 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4127 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4130 /// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4131 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4132 /// when they refer multiple MIOperands inside a single one.
4134 cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
4135 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4136 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4138 // Create a writeback register dummy placeholder.
4139 Inst.addOperand(MCOperand::CreateImm(0));
4141 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4142 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4146 /// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4147 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4148 /// when they refer multiple MIOperands inside a single one.
4150 cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
4151 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4152 // Create a writeback register dummy placeholder.
4153 Inst.addOperand(MCOperand::CreateImm(0));
4154 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4155 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4156 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4159 /// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
4160 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4161 /// when they refer multiple MIOperands inside a single one.
4163 cvtStWriteBackRegAddrMode2(MCInst &Inst,
4164 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4165 // Create a writeback register dummy placeholder.
4166 Inst.addOperand(MCOperand::CreateImm(0));
4167 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4168 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4169 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4172 /// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4173 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4174 /// when they refer multiple MIOperands inside a single one.
4176 cvtStWriteBackRegAddrMode3(MCInst &Inst,
4177 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4178 // Create a writeback register dummy placeholder.
4179 Inst.addOperand(MCOperand::CreateImm(0));
4180 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4181 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4182 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4185 /// cvtLdExtTWriteBackImm - 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 cvtLdExtTWriteBackImm(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])->addPostIdxImm8Operands(Inst, 1);
4200 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4203 /// cvtLdExtTWriteBackReg - 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 cvtLdExtTWriteBackReg(MCInst &Inst,
4208 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4210 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4211 // Create a writeback register dummy placeholder.
4212 Inst.addOperand(MCOperand::CreateImm(0));
4214 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4216 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4218 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4221 /// cvtStExtTWriteBackImm - 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 cvtStExtTWriteBackImm(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])->addPostIdxImm8Operands(Inst, 1);
4236 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4239 /// cvtStExtTWriteBackReg - 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 cvtStExtTWriteBackReg(MCInst &Inst,
4244 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4245 // Create a writeback register dummy placeholder.
4246 Inst.addOperand(MCOperand::CreateImm(0));
4248 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4250 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4252 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4254 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4257 /// cvtLdrdPre - Convert parsed operands to MCInst.
4258 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4259 /// when they refer multiple MIOperands inside a single one.
4261 cvtLdrdPre(MCInst &Inst,
4262 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4264 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4265 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4266 // Create a writeback register dummy placeholder.
4267 Inst.addOperand(MCOperand::CreateImm(0));
4269 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4271 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4274 /// cvtStrdPre - Convert parsed operands to MCInst.
4275 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4276 /// when they refer multiple MIOperands inside a single one.
4278 cvtStrdPre(MCInst &Inst,
4279 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4280 // Create a writeback register dummy placeholder.
4281 Inst.addOperand(MCOperand::CreateImm(0));
4283 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4284 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4286 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4288 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4291 /// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4292 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4293 /// when they refer multiple MIOperands inside a single one.
4295 cvtLdWriteBackRegAddrMode3(MCInst &Inst,
4296 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4297 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4298 // Create a writeback register dummy placeholder.
4299 Inst.addOperand(MCOperand::CreateImm(0));
4300 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4301 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4304 /// cvtThumbMultiply - Convert parsed operands to MCInst.
4305 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4306 /// when they refer multiple MIOperands inside a single one.
4308 cvtThumbMultiply(MCInst &Inst,
4309 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4310 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4311 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4312 // If we have a three-operand form, make sure to set Rn to be the operand
4313 // that isn't the same as Rd.
4315 if (Operands.size() == 6 &&
4316 ((ARMOperand*)Operands[4])->getReg() ==
4317 ((ARMOperand*)Operands[3])->getReg())
4319 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4320 Inst.addOperand(Inst.getOperand(0));
4321 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4325 cvtVLDwbFixed(MCInst &Inst,
4326 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4328 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4329 // Create a writeback register dummy placeholder.
4330 Inst.addOperand(MCOperand::CreateImm(0));
4332 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4334 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4338 cvtVLDwbRegister(MCInst &Inst,
4339 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4341 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4342 // Create a writeback register dummy placeholder.
4343 Inst.addOperand(MCOperand::CreateImm(0));
4345 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4347 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4349 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4353 cvtVSTwbFixed(MCInst &Inst,
4354 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4355 // Create a writeback register dummy placeholder.
4356 Inst.addOperand(MCOperand::CreateImm(0));
4358 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4360 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4362 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4366 cvtVSTwbRegister(MCInst &Inst,
4367 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4368 // Create a writeback register dummy placeholder.
4369 Inst.addOperand(MCOperand::CreateImm(0));
4371 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4373 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4375 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4377 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4380 /// Parse an ARM memory expression, return false if successful else return true
4381 /// or an error. The first token must be a '[' when called.
4383 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4385 assert(Parser.getTok().is(AsmToken::LBrac) &&
4386 "Token is not a Left Bracket");
4387 S = Parser.getTok().getLoc();
4388 Parser.Lex(); // Eat left bracket token.
4390 const AsmToken &BaseRegTok = Parser.getTok();
4391 int BaseRegNum = tryParseRegister();
4392 if (BaseRegNum == -1)
4393 return Error(BaseRegTok.getLoc(), "register expected");
4395 // The next token must either be a comma, a colon or a closing bracket.
4396 const AsmToken &Tok = Parser.getTok();
4397 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4398 !Tok.is(AsmToken::RBrac))
4399 return Error(Tok.getLoc(), "malformed memory operand");
4401 if (Tok.is(AsmToken::RBrac)) {
4402 E = Tok.getEndLoc();
4403 Parser.Lex(); // Eat right bracket token.
4405 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4406 0, 0, false, S, E));
4408 // If there's a pre-indexing writeback marker, '!', just add it as a token
4409 // operand. It's rather odd, but syntactically valid.
4410 if (Parser.getTok().is(AsmToken::Exclaim)) {
4411 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4412 Parser.Lex(); // Eat the '!'.
4418 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4419 "Lost colon or comma in memory operand?!");
4420 if (Tok.is(AsmToken::Comma)) {
4421 Parser.Lex(); // Eat the comma.
4424 // If we have a ':', it's an alignment specifier.
4425 if (Parser.getTok().is(AsmToken::Colon)) {
4426 Parser.Lex(); // Eat the ':'.
4427 E = Parser.getTok().getLoc();
4430 if (getParser().parseExpression(Expr))
4433 // The expression has to be a constant. Memory references with relocations
4434 // don't come through here, as they use the <label> forms of the relevant
4436 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4438 return Error (E, "constant expression expected");
4441 switch (CE->getValue()) {
4444 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4445 case 16: Align = 2; break;
4446 case 32: Align = 4; break;
4447 case 64: Align = 8; break;
4448 case 128: Align = 16; break;
4449 case 256: Align = 32; break;
4452 // Now we should have the closing ']'
4453 if (Parser.getTok().isNot(AsmToken::RBrac))
4454 return Error(Parser.getTok().getLoc(), "']' expected");
4455 E = Parser.getTok().getEndLoc();
4456 Parser.Lex(); // Eat right bracket token.
4458 // Don't worry about range checking the value here. That's handled by
4459 // the is*() predicates.
4460 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4461 ARM_AM::no_shift, 0, Align,
4464 // If there's a pre-indexing writeback marker, '!', just add it as a token
4466 if (Parser.getTok().is(AsmToken::Exclaim)) {
4467 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4468 Parser.Lex(); // Eat the '!'.
4474 // If we have a '#', it's an immediate offset, else assume it's a register
4475 // offset. Be friendly and also accept a plain integer (without a leading
4476 // hash) for gas compatibility.
4477 if (Parser.getTok().is(AsmToken::Hash) ||
4478 Parser.getTok().is(AsmToken::Dollar) ||
4479 Parser.getTok().is(AsmToken::Integer)) {
4480 if (Parser.getTok().isNot(AsmToken::Integer))
4481 Parser.Lex(); // Eat '#' or '$'.
4482 E = Parser.getTok().getLoc();
4484 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4485 const MCExpr *Offset;
4486 if (getParser().parseExpression(Offset))
4489 // The expression has to be a constant. Memory references with relocations
4490 // don't come through here, as they use the <label> forms of the relevant
4492 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4494 return Error (E, "constant expression expected");
4496 // If the constant was #-0, represent it as INT32_MIN.
4497 int32_t Val = CE->getValue();
4498 if (isNegative && Val == 0)
4499 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4501 // Now we should have the closing ']'
4502 if (Parser.getTok().isNot(AsmToken::RBrac))
4503 return Error(Parser.getTok().getLoc(), "']' expected");
4504 E = Parser.getTok().getEndLoc();
4505 Parser.Lex(); // Eat right bracket token.
4507 // Don't worry about range checking the value here. That's handled by
4508 // the is*() predicates.
4509 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4510 ARM_AM::no_shift, 0, 0,
4513 // If there's a pre-indexing writeback marker, '!', just add it as a token
4515 if (Parser.getTok().is(AsmToken::Exclaim)) {
4516 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4517 Parser.Lex(); // Eat the '!'.
4523 // The register offset is optionally preceded by a '+' or '-'
4524 bool isNegative = false;
4525 if (Parser.getTok().is(AsmToken::Minus)) {
4527 Parser.Lex(); // Eat the '-'.
4528 } else if (Parser.getTok().is(AsmToken::Plus)) {
4530 Parser.Lex(); // Eat the '+'.
4533 E = Parser.getTok().getLoc();
4534 int OffsetRegNum = tryParseRegister();
4535 if (OffsetRegNum == -1)
4536 return Error(E, "register expected");
4538 // If there's a shift operator, handle it.
4539 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4540 unsigned ShiftImm = 0;
4541 if (Parser.getTok().is(AsmToken::Comma)) {
4542 Parser.Lex(); // Eat the ','.
4543 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4547 // Now we should have the closing ']'
4548 if (Parser.getTok().isNot(AsmToken::RBrac))
4549 return Error(Parser.getTok().getLoc(), "']' expected");
4550 E = Parser.getTok().getEndLoc();
4551 Parser.Lex(); // Eat right bracket token.
4553 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4554 ShiftType, ShiftImm, 0, isNegative,
4557 // If there's a pre-indexing writeback marker, '!', just add it as a token
4559 if (Parser.getTok().is(AsmToken::Exclaim)) {
4560 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4561 Parser.Lex(); // Eat the '!'.
4567 /// parseMemRegOffsetShift - one of these two:
4568 /// ( lsl | lsr | asr | ror ) , # shift_amount
4570 /// return true if it parses a shift otherwise it returns false.
4571 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4573 SMLoc Loc = Parser.getTok().getLoc();
4574 const AsmToken &Tok = Parser.getTok();
4575 if (Tok.isNot(AsmToken::Identifier))
4577 StringRef ShiftName = Tok.getString();
4578 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4579 ShiftName == "asl" || ShiftName == "ASL")
4581 else if (ShiftName == "lsr" || ShiftName == "LSR")
4583 else if (ShiftName == "asr" || ShiftName == "ASR")
4585 else if (ShiftName == "ror" || ShiftName == "ROR")
4587 else if (ShiftName == "rrx" || ShiftName == "RRX")
4590 return Error(Loc, "illegal shift operator");
4591 Parser.Lex(); // Eat shift type token.
4593 // rrx stands alone.
4595 if (St != ARM_AM::rrx) {
4596 Loc = Parser.getTok().getLoc();
4597 // A '#' and a shift amount.
4598 const AsmToken &HashTok = Parser.getTok();
4599 if (HashTok.isNot(AsmToken::Hash) &&
4600 HashTok.isNot(AsmToken::Dollar))
4601 return Error(HashTok.getLoc(), "'#' expected");
4602 Parser.Lex(); // Eat hash token.
4605 if (getParser().parseExpression(Expr))
4607 // Range check the immediate.
4608 // lsl, ror: 0 <= imm <= 31
4609 // lsr, asr: 0 <= imm <= 32
4610 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4612 return Error(Loc, "shift amount must be an immediate");
4613 int64_t Imm = CE->getValue();
4615 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4616 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4617 return Error(Loc, "immediate shift value out of range");
4618 // If <ShiftTy> #0, turn it into a no_shift.
4621 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4630 /// parseFPImm - A floating point immediate expression operand.
4631 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4632 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4633 // Anything that can accept a floating point constant as an operand
4634 // needs to go through here, as the regular parseExpression is
4637 // This routine still creates a generic Immediate operand, containing
4638 // a bitcast of the 64-bit floating point value. The various operands
4639 // that accept floats can check whether the value is valid for them
4640 // via the standard is*() predicates.
4642 SMLoc S = Parser.getTok().getLoc();
4644 if (Parser.getTok().isNot(AsmToken::Hash) &&
4645 Parser.getTok().isNot(AsmToken::Dollar))
4646 return MatchOperand_NoMatch;
4648 // Disambiguate the VMOV forms that can accept an FP immediate.
4649 // vmov.f32 <sreg>, #imm
4650 // vmov.f64 <dreg>, #imm
4651 // vmov.f32 <dreg>, #imm @ vector f32x2
4652 // vmov.f32 <qreg>, #imm @ vector f32x4
4654 // There are also the NEON VMOV instructions which expect an
4655 // integer constant. Make sure we don't try to parse an FPImm
4657 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4658 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4659 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4660 TyOp->getToken() != ".f64"))
4661 return MatchOperand_NoMatch;
4663 Parser.Lex(); // Eat '#' or '$'.
4665 // Handle negation, as that still comes through as a separate token.
4666 bool isNegative = false;
4667 if (Parser.getTok().is(AsmToken::Minus)) {
4671 const AsmToken &Tok = Parser.getTok();
4672 SMLoc Loc = Tok.getLoc();
4673 if (Tok.is(AsmToken::Real)) {
4674 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4675 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4676 // If we had a '-' in front, toggle the sign bit.
4677 IntVal ^= (uint64_t)isNegative << 31;
4678 Parser.Lex(); // Eat the token.
4679 Operands.push_back(ARMOperand::CreateImm(
4680 MCConstantExpr::Create(IntVal, getContext()),
4681 S, Parser.getTok().getLoc()));
4682 return MatchOperand_Success;
4684 // Also handle plain integers. Instructions which allow floating point
4685 // immediates also allow a raw encoded 8-bit value.
4686 if (Tok.is(AsmToken::Integer)) {
4687 int64_t Val = Tok.getIntVal();
4688 Parser.Lex(); // Eat the token.
4689 if (Val > 255 || Val < 0) {
4690 Error(Loc, "encoded floating point value out of range");
4691 return MatchOperand_ParseFail;
4693 double RealVal = ARM_AM::getFPImmFloat(Val);
4694 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4695 Operands.push_back(ARMOperand::CreateImm(
4696 MCConstantExpr::Create(Val, getContext()), S,
4697 Parser.getTok().getLoc()));
4698 return MatchOperand_Success;
4701 Error(Loc, "invalid floating point immediate");
4702 return MatchOperand_ParseFail;
4705 /// Parse a arm instruction operand. For now this parses the operand regardless
4706 /// of the mnemonic.
4707 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4708 StringRef Mnemonic) {
4711 // Check if the current operand has a custom associated parser, if so, try to
4712 // custom parse the operand, or fallback to the general approach.
4713 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4714 if (ResTy == MatchOperand_Success)
4716 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4717 // there was a match, but an error occurred, in which case, just return that
4718 // the operand parsing failed.
4719 if (ResTy == MatchOperand_ParseFail)
4722 switch (getLexer().getKind()) {
4724 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4726 case AsmToken::Identifier: {
4727 // If we've seen a branch mnemonic, the next operand must be a label. This
4728 // is true even if the label is a register name. So "br r1" means branch to
4730 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4732 if (!tryParseRegisterWithWriteBack(Operands))
4734 int Res = tryParseShiftRegister(Operands);
4735 if (Res == 0) // success
4737 else if (Res == -1) // irrecoverable error
4739 // If this is VMRS, check for the apsr_nzcv operand.
4740 if (Mnemonic == "vmrs" &&
4741 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4742 S = Parser.getTok().getLoc();
4744 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4749 // Fall though for the Identifier case that is not a register or a
4752 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4753 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4754 case AsmToken::String: // quoted label names.
4755 case AsmToken::Dot: { // . as a branch target
4756 // This was not a register so parse other operands that start with an
4757 // identifier (like labels) as expressions and create them as immediates.
4758 const MCExpr *IdVal;
4759 S = Parser.getTok().getLoc();
4760 if (getParser().parseExpression(IdVal))
4762 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4763 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4766 case AsmToken::LBrac:
4767 return parseMemory(Operands);
4768 case AsmToken::LCurly:
4769 return parseRegisterList(Operands);
4770 case AsmToken::Dollar:
4771 case AsmToken::Hash: {
4772 // #42 -> immediate.
4773 S = Parser.getTok().getLoc();
4776 if (Parser.getTok().isNot(AsmToken::Colon)) {
4777 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4778 const MCExpr *ImmVal;
4779 if (getParser().parseExpression(ImmVal))
4781 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4783 int32_t Val = CE->getValue();
4784 if (isNegative && Val == 0)
4785 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4787 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4788 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4790 // There can be a trailing '!' on operands that we want as a separate
4791 // '!' Token operand. Handle that here. For example, the compatibilty
4792 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4793 if (Parser.getTok().is(AsmToken::Exclaim)) {
4794 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4795 Parser.getTok().getLoc()));
4796 Parser.Lex(); // Eat exclaim token
4800 // w/ a ':' after the '#', it's just like a plain ':'.
4803 case AsmToken::Colon: {
4804 // ":lower16:" and ":upper16:" expression prefixes
4805 // FIXME: Check it's an expression prefix,
4806 // e.g. (FOO - :lower16:BAR) isn't legal.
4807 ARMMCExpr::VariantKind RefKind;
4808 if (parsePrefix(RefKind))
4811 const MCExpr *SubExprVal;
4812 if (getParser().parseExpression(SubExprVal))
4815 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4817 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4818 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4824 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4825 // :lower16: and :upper16:.
4826 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4827 RefKind = ARMMCExpr::VK_ARM_None;
4829 // :lower16: and :upper16: modifiers
4830 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4831 Parser.Lex(); // Eat ':'
4833 if (getLexer().isNot(AsmToken::Identifier)) {
4834 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4838 StringRef IDVal = Parser.getTok().getIdentifier();
4839 if (IDVal == "lower16") {
4840 RefKind = ARMMCExpr::VK_ARM_LO16;
4841 } else if (IDVal == "upper16") {
4842 RefKind = ARMMCExpr::VK_ARM_HI16;
4844 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4849 if (getLexer().isNot(AsmToken::Colon)) {
4850 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4853 Parser.Lex(); // Eat the last ':'
4857 /// \brief Given a mnemonic, split out possible predication code and carry
4858 /// setting letters to form a canonical mnemonic and flags.
4860 // FIXME: Would be nice to autogen this.
4861 // FIXME: This is a bit of a maze of special cases.
4862 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4863 unsigned &PredicationCode,
4865 unsigned &ProcessorIMod,
4866 StringRef &ITMask) {
4867 PredicationCode = ARMCC::AL;
4868 CarrySetting = false;
4871 // Ignore some mnemonics we know aren't predicated forms.
4873 // FIXME: Would be nice to autogen this.
4874 if ((Mnemonic == "movs" && isThumb()) ||
4875 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4876 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4877 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4878 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4879 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
4880 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4881 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4882 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4883 Mnemonic == "fmuls")
4886 // First, split out any predication code. Ignore mnemonics we know aren't
4887 // predicated but do have a carry-set and so weren't caught above.
4888 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4889 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4890 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4891 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4892 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4893 .Case("eq", ARMCC::EQ)
4894 .Case("ne", ARMCC::NE)
4895 .Case("hs", ARMCC::HS)
4896 .Case("cs", ARMCC::HS)
4897 .Case("lo", ARMCC::LO)
4898 .Case("cc", ARMCC::LO)
4899 .Case("mi", ARMCC::MI)
4900 .Case("pl", ARMCC::PL)
4901 .Case("vs", ARMCC::VS)
4902 .Case("vc", ARMCC::VC)
4903 .Case("hi", ARMCC::HI)
4904 .Case("ls", ARMCC::LS)
4905 .Case("ge", ARMCC::GE)
4906 .Case("lt", ARMCC::LT)
4907 .Case("gt", ARMCC::GT)
4908 .Case("le", ARMCC::LE)
4909 .Case("al", ARMCC::AL)
4912 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4913 PredicationCode = CC;
4917 // Next, determine if we have a carry setting bit. We explicitly ignore all
4918 // the instructions we know end in 's'.
4919 if (Mnemonic.endswith("s") &&
4920 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4921 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4922 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4923 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4924 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4925 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4926 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4927 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4928 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4929 (Mnemonic == "movs" && isThumb()))) {
4930 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4931 CarrySetting = true;
4934 // The "cps" instruction can have a interrupt mode operand which is glued into
4935 // the mnemonic. Check if this is the case, split it and parse the imod op
4936 if (Mnemonic.startswith("cps")) {
4937 // Split out any imod code.
4939 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4940 .Case("ie", ARM_PROC::IE)
4941 .Case("id", ARM_PROC::ID)
4944 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4945 ProcessorIMod = IMod;
4949 // The "it" instruction has the condition mask on the end of the mnemonic.
4950 if (Mnemonic.startswith("it")) {
4951 ITMask = Mnemonic.slice(2, Mnemonic.size());
4952 Mnemonic = Mnemonic.slice(0, 2);
4958 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4959 /// inclusion of carry set or predication code operands.
4961 // FIXME: It would be nice to autogen this.
4963 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
4964 bool &CanAcceptPredicationCode) {
4965 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4966 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4967 Mnemonic == "add" || Mnemonic == "adc" ||
4968 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4969 Mnemonic == "orr" || Mnemonic == "mvn" ||
4970 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4971 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4972 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4973 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4974 Mnemonic == "mla" || Mnemonic == "smlal" ||
4975 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4976 CanAcceptCarrySet = true;
4978 CanAcceptCarrySet = false;
4980 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4981 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4982 Mnemonic == "trap" || Mnemonic == "setend" ||
4983 Mnemonic.startswith("cps")) {
4984 // These mnemonics are never predicable
4985 CanAcceptPredicationCode = false;
4986 } else if (!isThumb()) {
4987 // Some instructions are only predicable in Thumb mode
4988 CanAcceptPredicationCode
4989 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4990 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4991 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4992 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4993 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4994 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4995 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4996 } else if (isThumbOne()) {
4997 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4999 CanAcceptPredicationCode = true;
5002 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
5003 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5004 // FIXME: This is all horribly hacky. We really need a better way to deal
5005 // with optional operands like this in the matcher table.
5007 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5008 // another does not. Specifically, the MOVW instruction does not. So we
5009 // special case it here and remove the defaulted (non-setting) cc_out
5010 // operand if that's the instruction we're trying to match.
5012 // We do this as post-processing of the explicit operands rather than just
5013 // conditionally adding the cc_out in the first place because we need
5014 // to check the type of the parsed immediate operand.
5015 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
5016 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
5017 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
5018 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5021 // Register-register 'add' for thumb does not have a cc_out operand
5022 // when there are only two register operands.
5023 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
5024 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5025 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5026 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5028 // Register-register 'add' for thumb does not have a cc_out operand
5029 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5030 // have to check the immediate range here since Thumb2 has a variant
5031 // that can handle a different range and has a cc_out operand.
5032 if (((isThumb() && Mnemonic == "add") ||
5033 (isThumbTwo() && Mnemonic == "sub")) &&
5034 Operands.size() == 6 &&
5035 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5036 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5037 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
5038 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5039 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
5040 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
5042 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5043 // imm0_4095 variant. That's the least-preferred variant when
5044 // selecting via the generic "add" mnemonic, so to know that we
5045 // should remove the cc_out operand, we have to explicitly check that
5046 // it's not one of the other variants. Ugh.
5047 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5048 Operands.size() == 6 &&
5049 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5050 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5051 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5052 // Nest conditions rather than one big 'if' statement for readability.
5054 // If either register is a high reg, it's either one of the SP
5055 // variants (handled above) or a 32-bit encoding, so we just
5056 // check against T3. If the second register is the PC, this is an
5057 // alternate form of ADR, which uses encoding T4, so check for that too.
5058 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5059 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
5060 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5061 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5063 // If both registers are low, we're in an IT block, and the immediate is
5064 // in range, we should use encoding T1 instead, which has a cc_out.
5066 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5067 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5068 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5071 // Otherwise, we use encoding T4, which does not have a cc_out
5076 // The thumb2 multiply instruction doesn't have a CCOut register, so
5077 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5078 // use the 16-bit encoding or not.
5079 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5080 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5081 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5082 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5083 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5084 // If the registers aren't low regs, the destination reg isn't the
5085 // same as one of the source regs, or the cc_out operand is zero
5086 // outside of an IT block, we have to use the 32-bit encoding, so
5087 // remove the cc_out operand.
5088 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5089 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5090 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
5092 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5093 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5094 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5095 static_cast<ARMOperand*>(Operands[4])->getReg())))
5098 // Also check the 'mul' syntax variant that doesn't specify an explicit
5099 // destination register.
5100 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5101 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5102 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5103 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5104 // If the registers aren't low regs or the cc_out operand is zero
5105 // outside of an IT block, we have to use the 32-bit encoding, so
5106 // remove the cc_out operand.
5107 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5108 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5114 // Register-register 'add/sub' for thumb does not have a cc_out operand
5115 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5116 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5117 // right, this will result in better diagnostics (which operand is off)
5119 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5120 (Operands.size() == 5 || Operands.size() == 6) &&
5121 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5122 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
5123 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5124 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5125 (Operands.size() == 6 &&
5126 static_cast<ARMOperand*>(Operands[5])->isImm())))
5132 static bool isDataTypeToken(StringRef Tok) {
5133 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5134 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5135 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5136 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5137 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5138 Tok == ".f" || Tok == ".d";
5141 // FIXME: This bit should probably be handled via an explicit match class
5142 // in the .td files that matches the suffix instead of having it be
5143 // a literal string token the way it is now.
5144 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5145 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5147 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5148 unsigned VariantID);
5149 /// Parse an arm instruction mnemonic followed by its operands.
5150 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5152 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5153 // Apply mnemonic aliases before doing anything else, as the destination
5154 // mnemnonic may include suffices and we want to handle them normally.
5155 // The generic tblgen'erated code does this later, at the start of
5156 // MatchInstructionImpl(), but that's too late for aliases that include
5157 // any sort of suffix.
5158 unsigned AvailableFeatures = getAvailableFeatures();
5159 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5160 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5162 // First check for the ARM-specific .req directive.
5163 if (Parser.getTok().is(AsmToken::Identifier) &&
5164 Parser.getTok().getIdentifier() == ".req") {
5165 parseDirectiveReq(Name, NameLoc);
5166 // We always return 'error' for this, as we're done with this
5167 // statement and don't need to match the 'instruction."
5171 // Create the leading tokens for the mnemonic, split by '.' characters.
5172 size_t Start = 0, Next = Name.find('.');
5173 StringRef Mnemonic = Name.slice(Start, Next);
5175 // Split out the predication code and carry setting flag from the mnemonic.
5176 unsigned PredicationCode;
5177 unsigned ProcessorIMod;
5180 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5181 ProcessorIMod, ITMask);
5183 // In Thumb1, only the branch (B) instruction can be predicated.
5184 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5185 Parser.eatToEndOfStatement();
5186 return Error(NameLoc, "conditional execution not supported in Thumb1");
5189 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5191 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5192 // is the mask as it will be for the IT encoding if the conditional
5193 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5194 // where the conditional bit0 is zero, the instruction post-processing
5195 // will adjust the mask accordingly.
5196 if (Mnemonic == "it") {
5197 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5198 if (ITMask.size() > 3) {
5199 Parser.eatToEndOfStatement();
5200 return Error(Loc, "too many conditions on IT instruction");
5203 for (unsigned i = ITMask.size(); i != 0; --i) {
5204 char pos = ITMask[i - 1];
5205 if (pos != 't' && pos != 'e') {
5206 Parser.eatToEndOfStatement();
5207 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5210 if (ITMask[i - 1] == 't')
5213 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5216 // FIXME: This is all a pretty gross hack. We should automatically handle
5217 // optional operands like this via tblgen.
5219 // Next, add the CCOut and ConditionCode operands, if needed.
5221 // For mnemonics which can ever incorporate a carry setting bit or predication
5222 // code, our matching model involves us always generating CCOut and
5223 // ConditionCode operands to match the mnemonic "as written" and then we let
5224 // the matcher deal with finding the right instruction or generating an
5225 // appropriate error.
5226 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5227 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
5229 // If we had a carry-set on an instruction that can't do that, issue an
5231 if (!CanAcceptCarrySet && CarrySetting) {
5232 Parser.eatToEndOfStatement();
5233 return Error(NameLoc, "instruction '" + Mnemonic +
5234 "' can not set flags, but 's' suffix specified");
5236 // If we had a predication code on an instruction that can't do that, issue an
5238 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5239 Parser.eatToEndOfStatement();
5240 return Error(NameLoc, "instruction '" + Mnemonic +
5241 "' is not predicable, but condition code specified");
5244 // Add the carry setting operand, if necessary.
5245 if (CanAcceptCarrySet) {
5246 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5247 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5251 // Add the predication code operand, if necessary.
5252 if (CanAcceptPredicationCode) {
5253 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5255 Operands.push_back(ARMOperand::CreateCondCode(
5256 ARMCC::CondCodes(PredicationCode), Loc));
5259 // Add the processor imod operand, if necessary.
5260 if (ProcessorIMod) {
5261 Operands.push_back(ARMOperand::CreateImm(
5262 MCConstantExpr::Create(ProcessorIMod, getContext()),
5266 // Add the remaining tokens in the mnemonic.
5267 while (Next != StringRef::npos) {
5269 Next = Name.find('.', Start + 1);
5270 StringRef ExtraToken = Name.slice(Start, Next);
5272 // Some NEON instructions have an optional datatype suffix that is
5273 // completely ignored. Check for that.
5274 if (isDataTypeToken(ExtraToken) &&
5275 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5278 // For for ARM mode generate an error if the .n qualifier is used.
5279 if (ExtraToken == ".n" && !isThumb()) {
5280 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5281 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5285 // The .n qualifier is always discarded as that is what the tables
5286 // and matcher expect. In ARM mode the .w qualifier has no effect,
5287 // so discard it to avoid errors that can be caused by the matcher.
5288 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5289 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5290 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5294 // Read the remaining operands.
5295 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5296 // Read the first operand.
5297 if (parseOperand(Operands, Mnemonic)) {
5298 Parser.eatToEndOfStatement();
5302 while (getLexer().is(AsmToken::Comma)) {
5303 Parser.Lex(); // Eat the comma.
5305 // Parse and remember the operand.
5306 if (parseOperand(Operands, Mnemonic)) {
5307 Parser.eatToEndOfStatement();
5313 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5314 SMLoc Loc = getLexer().getLoc();
5315 Parser.eatToEndOfStatement();
5316 return Error(Loc, "unexpected token in argument list");
5319 Parser.Lex(); // Consume the EndOfStatement
5321 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5322 // do and don't have a cc_out optional-def operand. With some spot-checks
5323 // of the operand list, we can figure out which variant we're trying to
5324 // parse and adjust accordingly before actually matching. We shouldn't ever
5325 // try to remove a cc_out operand that was explicitly set on the the
5326 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5327 // table driven matcher doesn't fit well with the ARM instruction set.
5328 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5329 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5330 Operands.erase(Operands.begin() + 1);
5334 // ARM mode 'blx' need special handling, as the register operand version
5335 // is predicable, but the label operand version is not. So, we can't rely
5336 // on the Mnemonic based checking to correctly figure out when to put
5337 // a k_CondCode operand in the list. If we're trying to match the label
5338 // version, remove the k_CondCode operand here.
5339 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5340 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5341 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5342 Operands.erase(Operands.begin() + 1);
5346 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5347 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5348 // a single GPRPair reg operand is used in the .td file to replace the two
5349 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5350 // expressed as a GPRPair, so we have to manually merge them.
5351 // FIXME: We would really like to be able to tablegen'erate this.
5352 if (!isThumb() && Operands.size() > 4 &&
5353 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5354 bool isLoad = (Mnemonic == "ldrexd");
5355 unsigned Idx = isLoad ? 2 : 3;
5356 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5357 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5359 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5360 // Adjust only if Op1 and Op2 are GPRs.
5361 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5362 MRC.contains(Op2->getReg())) {
5363 unsigned Reg1 = Op1->getReg();
5364 unsigned Reg2 = Op2->getReg();
5365 unsigned Rt = MRI->getEncodingValue(Reg1);
5366 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5368 // Rt2 must be Rt + 1 and Rt must be even.
5369 if (Rt + 1 != Rt2 || (Rt & 1)) {
5370 Error(Op2->getStartLoc(), isLoad ?
5371 "destination operands must be sequential" :
5372 "source operands must be sequential");
5375 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5376 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5377 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5378 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5379 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5388 // Validate context-sensitive operand constraints.
5390 // return 'true' if register list contains non-low GPR registers,
5391 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5392 // 'containsReg' to true.
5393 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5394 unsigned HiReg, bool &containsReg) {
5395 containsReg = false;
5396 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5397 unsigned OpReg = Inst.getOperand(i).getReg();
5400 // Anything other than a low register isn't legal here.
5401 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5407 // Check if the specified regisgter is in the register list of the inst,
5408 // starting at the indicated operand number.
5409 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5410 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5411 unsigned OpReg = Inst.getOperand(i).getReg();
5418 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5419 // the ARMInsts array) instead. Getting that here requires awkward
5420 // API changes, though. Better way?
5422 extern const MCInstrDesc ARMInsts[];
5424 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
5425 return ARMInsts[Opcode];
5428 // FIXME: We would really like to be able to tablegen'erate this.
5430 validateInstruction(MCInst &Inst,
5431 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5432 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
5433 SMLoc Loc = Operands[0]->getStartLoc();
5434 // Check the IT block state first.
5435 // NOTE: BKPT instruction has the interesting property of being
5436 // allowed in IT blocks, but not being predicable. It just always
5438 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5439 Inst.getOpcode() != ARM::BKPT) {
5441 if (ITState.FirstCond)
5442 ITState.FirstCond = false;
5444 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5445 // The instruction must be predicable.
5446 if (!MCID.isPredicable())
5447 return Error(Loc, "instructions in IT block must be predicable");
5448 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5449 unsigned ITCond = bit ? ITState.Cond :
5450 ARMCC::getOppositeCondition(ITState.Cond);
5451 if (Cond != ITCond) {
5452 // Find the condition code Operand to get its SMLoc information.
5454 for (unsigned i = 1; i < Operands.size(); ++i)
5455 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5456 CondLoc = Operands[i]->getStartLoc();
5457 return Error(CondLoc, "incorrect condition in IT block; got '" +
5458 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5459 "', but expected '" +
5460 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5462 // Check for non-'al' condition codes outside of the IT block.
5463 } else if (isThumbTwo() && MCID.isPredicable() &&
5464 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5465 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5466 Inst.getOpcode() != ARM::t2B)
5467 return Error(Loc, "predicated instructions must be in IT block");
5469 switch (Inst.getOpcode()) {
5472 case ARM::LDRD_POST: {
5473 // Rt2 must be Rt + 1.
5474 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5475 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5477 return Error(Operands[3]->getStartLoc(),
5478 "destination operands must be sequential");
5482 // Rt2 must be Rt + 1.
5483 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5484 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5486 return Error(Operands[3]->getStartLoc(),
5487 "source operands must be sequential");
5491 case ARM::STRD_POST: {
5492 // Rt2 must be Rt + 1.
5493 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5494 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5496 return Error(Operands[3]->getStartLoc(),
5497 "source operands must be sequential");
5502 // width must be in range [1, 32-lsb]
5503 unsigned lsb = Inst.getOperand(2).getImm();
5504 unsigned widthm1 = Inst.getOperand(3).getImm();
5505 if (widthm1 >= 32 - lsb)
5506 return Error(Operands[5]->getStartLoc(),
5507 "bitfield width must be in range [1,32-lsb]");
5511 // If we're parsing Thumb2, the .w variant is available and handles
5512 // most cases that are normally illegal for a Thumb1 LDM
5513 // instruction. We'll make the transformation in processInstruction()
5516 // Thumb LDM instructions are writeback iff the base register is not
5517 // in the register list.
5518 unsigned Rn = Inst.getOperand(0).getReg();
5519 bool hasWritebackToken =
5520 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5521 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5522 bool listContainsBase;
5523 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5524 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5525 "registers must be in range r0-r7");
5526 // If we should have writeback, then there should be a '!' token.
5527 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5528 return Error(Operands[2]->getStartLoc(),
5529 "writeback operator '!' expected");
5530 // If we should not have writeback, there must not be a '!'. This is
5531 // true even for the 32-bit wide encodings.
5532 if (listContainsBase && hasWritebackToken)
5533 return Error(Operands[3]->getStartLoc(),
5534 "writeback operator '!' not allowed when base register "
5535 "in register list");
5539 case ARM::t2LDMIA_UPD: {
5540 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5541 return Error(Operands[4]->getStartLoc(),
5542 "writeback operator '!' not allowed when base register "
5543 "in register list");
5547 // The second source operand must be the same register as the destination
5550 // In this case, we must directly check the parsed operands because the
5551 // cvtThumbMultiply() function is written in such a way that it guarantees
5552 // this first statement is always true for the new Inst. Essentially, the
5553 // destination is unconditionally copied into the second source operand
5554 // without checking to see if it matches what we actually parsed.
5555 if (Operands.size() == 6 &&
5556 (((ARMOperand*)Operands[3])->getReg() !=
5557 ((ARMOperand*)Operands[5])->getReg()) &&
5558 (((ARMOperand*)Operands[3])->getReg() !=
5559 ((ARMOperand*)Operands[4])->getReg())) {
5560 return Error(Operands[3]->getStartLoc(),
5561 "destination register must match source register");
5565 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5566 // so only issue a diagnostic for thumb1. The instructions will be
5567 // switched to the t2 encodings in processInstruction() if necessary.
5569 bool listContainsBase;
5570 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5572 return Error(Operands[2]->getStartLoc(),
5573 "registers must be in range r0-r7 or pc");
5577 bool listContainsBase;
5578 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5580 return Error(Operands[2]->getStartLoc(),
5581 "registers must be in range r0-r7 or lr");
5584 case ARM::tSTMIA_UPD: {
5585 bool listContainsBase;
5586 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5587 return Error(Operands[4]->getStartLoc(),
5588 "registers must be in range r0-r7");
5591 case ARM::tADDrSP: {
5592 // If the non-SP source operand and the destination operand are not the
5593 // same, we need thumb2 (for the wide encoding), or we have an error.
5594 if (!isThumbTwo() &&
5595 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5596 return Error(Operands[4]->getStartLoc(),
5597 "source register must be the same as destination");
5606 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5608 default: llvm_unreachable("unexpected opcode!");
5610 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5611 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5612 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5613 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5614 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5615 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5616 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5617 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5618 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5621 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5622 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5623 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5624 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5625 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5627 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5628 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5629 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5630 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5631 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5633 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5634 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5635 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5636 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5637 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5640 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5641 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5642 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5643 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5644 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5645 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5646 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5647 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5648 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5649 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5650 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5651 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5652 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5653 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5654 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5657 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5658 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5659 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5660 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5661 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5662 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5663 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5664 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5665 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5666 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5667 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5668 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5669 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5670 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5671 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5672 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5673 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5674 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5677 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5678 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5679 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5680 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5681 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5682 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5683 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5684 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5685 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5686 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5687 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5688 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5689 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5690 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5691 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5694 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5695 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5696 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5697 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5698 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5699 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5700 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5701 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5702 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5703 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5704 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5705 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5706 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5707 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5708 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5709 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5710 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5711 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5715 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5717 default: llvm_unreachable("unexpected opcode!");
5719 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5720 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5721 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5722 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5723 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5724 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5725 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5726 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5727 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5730 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5731 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5732 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5733 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5734 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5735 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5736 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5737 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5738 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5739 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5740 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5741 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5742 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5743 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5744 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5747 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5748 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5749 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5750 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5751 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5752 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5753 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5754 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5755 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5756 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5757 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5758 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5759 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5760 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5761 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5762 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5763 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5764 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5767 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5768 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5769 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5770 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5771 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5772 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5773 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5774 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5775 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5776 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5777 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5778 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5779 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5780 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5781 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5784 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5785 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5786 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5787 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5788 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5789 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5790 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5791 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5792 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5793 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5794 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5795 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5796 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5797 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5798 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5799 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5800 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5801 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5804 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5805 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5806 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5807 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5808 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5809 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5810 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5811 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5812 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5813 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5814 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5815 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5816 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5817 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5818 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5821 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5822 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5823 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5824 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5825 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5826 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5827 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5828 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5829 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5830 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5831 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5832 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5833 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5834 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5835 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5836 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5837 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5838 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5841 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5842 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5843 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5844 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5845 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5846 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5847 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5848 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5849 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5850 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5851 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5852 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5853 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5854 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5855 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5856 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5857 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5858 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5863 processInstruction(MCInst &Inst,
5864 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5865 switch (Inst.getOpcode()) {
5866 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5868 if (Inst.getOperand(1).getReg() != ARM::PC ||
5869 Inst.getOperand(5).getReg() != 0)
5872 TmpInst.setOpcode(ARM::ADR);
5873 TmpInst.addOperand(Inst.getOperand(0));
5874 TmpInst.addOperand(Inst.getOperand(2));
5875 TmpInst.addOperand(Inst.getOperand(3));
5876 TmpInst.addOperand(Inst.getOperand(4));
5880 // Aliases for alternate PC+imm syntax of LDR instructions.
5881 case ARM::t2LDRpcrel:
5882 // Select the narrow version if the immediate will fit.
5883 if (Inst.getOperand(1).getImm() > 0 &&
5884 Inst.getOperand(1).getImm() <= 0xff &&
5885 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5886 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
5887 Inst.setOpcode(ARM::tLDRpci);
5889 Inst.setOpcode(ARM::t2LDRpci);
5891 case ARM::t2LDRBpcrel:
5892 Inst.setOpcode(ARM::t2LDRBpci);
5894 case ARM::t2LDRHpcrel:
5895 Inst.setOpcode(ARM::t2LDRHpci);
5897 case ARM::t2LDRSBpcrel:
5898 Inst.setOpcode(ARM::t2LDRSBpci);
5900 case ARM::t2LDRSHpcrel:
5901 Inst.setOpcode(ARM::t2LDRSHpci);
5903 // Handle NEON VST complex aliases.
5904 case ARM::VST1LNdWB_register_Asm_8:
5905 case ARM::VST1LNdWB_register_Asm_16:
5906 case ARM::VST1LNdWB_register_Asm_32: {
5908 // Shuffle the operands around so the lane index operand is in the
5911 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5912 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5913 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5914 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5915 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5916 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5917 TmpInst.addOperand(Inst.getOperand(1)); // lane
5918 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5919 TmpInst.addOperand(Inst.getOperand(6));
5924 case ARM::VST2LNdWB_register_Asm_8:
5925 case ARM::VST2LNdWB_register_Asm_16:
5926 case ARM::VST2LNdWB_register_Asm_32:
5927 case ARM::VST2LNqWB_register_Asm_16:
5928 case ARM::VST2LNqWB_register_Asm_32: {
5930 // Shuffle the operands around so the lane index operand is in the
5933 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5934 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5935 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5936 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5937 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5938 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5939 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5941 TmpInst.addOperand(Inst.getOperand(1)); // lane
5942 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5943 TmpInst.addOperand(Inst.getOperand(6));
5948 case ARM::VST3LNdWB_register_Asm_8:
5949 case ARM::VST3LNdWB_register_Asm_16:
5950 case ARM::VST3LNdWB_register_Asm_32:
5951 case ARM::VST3LNqWB_register_Asm_16:
5952 case ARM::VST3LNqWB_register_Asm_32: {
5954 // Shuffle the operands around so the lane index operand is in the
5957 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5958 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5959 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5960 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5961 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5962 TmpInst.addOperand(Inst.getOperand(0)); // Vd
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::VST4LNdWB_register_Asm_8:
5975 case ARM::VST4LNdWB_register_Asm_16:
5976 case ARM::VST4LNdWB_register_Asm_32:
5977 case ARM::VST4LNqWB_register_Asm_16:
5978 case ARM::VST4LNqWB_register_Asm_32: {
5980 // Shuffle the operands around so the lane index operand is in the
5983 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5984 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5985 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5986 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5987 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5988 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5989 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5991 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5993 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5995 TmpInst.addOperand(Inst.getOperand(1)); // lane
5996 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5997 TmpInst.addOperand(Inst.getOperand(6));
6002 case ARM::VST1LNdWB_fixed_Asm_8:
6003 case ARM::VST1LNdWB_fixed_Asm_16:
6004 case ARM::VST1LNdWB_fixed_Asm_32: {
6006 // Shuffle the operands around so the lane index operand is in the
6009 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6010 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6011 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6012 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6013 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6014 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6015 TmpInst.addOperand(Inst.getOperand(1)); // lane
6016 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6017 TmpInst.addOperand(Inst.getOperand(5));
6022 case ARM::VST2LNdWB_fixed_Asm_8:
6023 case ARM::VST2LNdWB_fixed_Asm_16:
6024 case ARM::VST2LNdWB_fixed_Asm_32:
6025 case ARM::VST2LNqWB_fixed_Asm_16:
6026 case ARM::VST2LNqWB_fixed_Asm_32: {
6028 // Shuffle the operands around so the lane index operand is in the
6031 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6032 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6033 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6034 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6035 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6036 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6037 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6039 TmpInst.addOperand(Inst.getOperand(1)); // lane
6040 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6041 TmpInst.addOperand(Inst.getOperand(5));
6046 case ARM::VST3LNdWB_fixed_Asm_8:
6047 case ARM::VST3LNdWB_fixed_Asm_16:
6048 case ARM::VST3LNdWB_fixed_Asm_32:
6049 case ARM::VST3LNqWB_fixed_Asm_16:
6050 case ARM::VST3LNqWB_fixed_Asm_32: {
6052 // Shuffle the operands around so the lane index operand is in the
6055 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6056 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6057 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6058 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6059 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6060 TmpInst.addOperand(Inst.getOperand(0)); // Vd
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::VST4LNdWB_fixed_Asm_8:
6073 case ARM::VST4LNdWB_fixed_Asm_16:
6074 case ARM::VST4LNdWB_fixed_Asm_32:
6075 case ARM::VST4LNqWB_fixed_Asm_16:
6076 case ARM::VST4LNqWB_fixed_Asm_32: {
6078 // Shuffle the operands around so the lane index operand is in the
6081 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6082 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6083 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6084 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6085 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6086 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6087 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6089 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6091 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6093 TmpInst.addOperand(Inst.getOperand(1)); // lane
6094 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6095 TmpInst.addOperand(Inst.getOperand(5));
6100 case ARM::VST1LNdAsm_8:
6101 case ARM::VST1LNdAsm_16:
6102 case ARM::VST1LNdAsm_32: {
6104 // Shuffle the operands around so the lane index operand is in the
6107 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6108 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6109 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6110 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6111 TmpInst.addOperand(Inst.getOperand(1)); // lane
6112 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6113 TmpInst.addOperand(Inst.getOperand(5));
6118 case ARM::VST2LNdAsm_8:
6119 case ARM::VST2LNdAsm_16:
6120 case ARM::VST2LNdAsm_32:
6121 case ARM::VST2LNqAsm_16:
6122 case ARM::VST2LNqAsm_32: {
6124 // Shuffle the operands around so the lane index operand is in the
6127 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6128 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6129 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6130 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6131 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6133 TmpInst.addOperand(Inst.getOperand(1)); // lane
6134 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6135 TmpInst.addOperand(Inst.getOperand(5));
6140 case ARM::VST3LNdAsm_8:
6141 case ARM::VST3LNdAsm_16:
6142 case ARM::VST3LNdAsm_32:
6143 case ARM::VST3LNqAsm_16:
6144 case ARM::VST3LNqAsm_32: {
6146 // Shuffle the operands around so the lane index operand is in the
6149 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6150 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6151 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6152 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6153 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6155 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6157 TmpInst.addOperand(Inst.getOperand(1)); // lane
6158 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6159 TmpInst.addOperand(Inst.getOperand(5));
6164 case ARM::VST4LNdAsm_8:
6165 case ARM::VST4LNdAsm_16:
6166 case ARM::VST4LNdAsm_32:
6167 case ARM::VST4LNqAsm_16:
6168 case ARM::VST4LNqAsm_32: {
6170 // Shuffle the operands around so the lane index operand is in the
6173 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6174 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6175 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6176 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6177 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6179 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6181 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6183 TmpInst.addOperand(Inst.getOperand(1)); // lane
6184 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6185 TmpInst.addOperand(Inst.getOperand(5));
6190 // Handle NEON VLD complex aliases.
6191 case ARM::VLD1LNdWB_register_Asm_8:
6192 case ARM::VLD1LNdWB_register_Asm_16:
6193 case ARM::VLD1LNdWB_register_Asm_32: {
6195 // Shuffle the operands around so the lane index operand is in the
6198 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6199 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6200 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6201 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6202 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6203 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6204 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6205 TmpInst.addOperand(Inst.getOperand(1)); // lane
6206 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6207 TmpInst.addOperand(Inst.getOperand(6));
6212 case ARM::VLD2LNdWB_register_Asm_8:
6213 case ARM::VLD2LNdWB_register_Asm_16:
6214 case ARM::VLD2LNdWB_register_Asm_32:
6215 case ARM::VLD2LNqWB_register_Asm_16:
6216 case ARM::VLD2LNqWB_register_Asm_32: {
6218 // Shuffle the operands around so the lane index operand is in the
6221 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6222 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6223 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6225 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6226 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6227 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6228 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6229 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6230 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6232 TmpInst.addOperand(Inst.getOperand(1)); // lane
6233 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6234 TmpInst.addOperand(Inst.getOperand(6));
6239 case ARM::VLD3LNdWB_register_Asm_8:
6240 case ARM::VLD3LNdWB_register_Asm_16:
6241 case ARM::VLD3LNdWB_register_Asm_32:
6242 case ARM::VLD3LNqWB_register_Asm_16:
6243 case ARM::VLD3LNqWB_register_Asm_32: {
6245 // Shuffle the operands around so the lane index operand is in the
6248 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6249 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6250 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6252 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6254 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6255 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6256 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6257 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6258 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6259 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6261 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6263 TmpInst.addOperand(Inst.getOperand(1)); // lane
6264 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6265 TmpInst.addOperand(Inst.getOperand(6));
6270 case ARM::VLD4LNdWB_register_Asm_8:
6271 case ARM::VLD4LNdWB_register_Asm_16:
6272 case ARM::VLD4LNdWB_register_Asm_32:
6273 case ARM::VLD4LNqWB_register_Asm_16:
6274 case ARM::VLD4LNqWB_register_Asm_32: {
6276 // Shuffle the operands around so the lane index operand is in the
6279 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6280 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6281 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6283 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6285 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6287 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6288 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6289 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6290 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6291 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6292 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6298 TmpInst.addOperand(Inst.getOperand(1)); // lane
6299 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6300 TmpInst.addOperand(Inst.getOperand(6));
6305 case ARM::VLD1LNdWB_fixed_Asm_8:
6306 case ARM::VLD1LNdWB_fixed_Asm_16:
6307 case ARM::VLD1LNdWB_fixed_Asm_32: {
6309 // Shuffle the operands around so the lane index operand is in the
6312 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6313 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6314 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6315 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6316 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6317 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6318 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6319 TmpInst.addOperand(Inst.getOperand(1)); // lane
6320 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6321 TmpInst.addOperand(Inst.getOperand(5));
6326 case ARM::VLD2LNdWB_fixed_Asm_8:
6327 case ARM::VLD2LNdWB_fixed_Asm_16:
6328 case ARM::VLD2LNdWB_fixed_Asm_32:
6329 case ARM::VLD2LNqWB_fixed_Asm_16:
6330 case ARM::VLD2LNqWB_fixed_Asm_32: {
6332 // Shuffle the operands around so the lane index operand is in the
6335 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6336 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6337 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6339 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6340 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6341 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6342 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6343 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6344 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6346 TmpInst.addOperand(Inst.getOperand(1)); // lane
6347 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6348 TmpInst.addOperand(Inst.getOperand(5));
6353 case ARM::VLD3LNdWB_fixed_Asm_8:
6354 case ARM::VLD3LNdWB_fixed_Asm_16:
6355 case ARM::VLD3LNdWB_fixed_Asm_32:
6356 case ARM::VLD3LNqWB_fixed_Asm_16:
6357 case ARM::VLD3LNqWB_fixed_Asm_32: {
6359 // Shuffle the operands around so the lane index operand is in the
6362 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6363 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6368 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6369 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6370 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6371 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6372 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6375 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6377 TmpInst.addOperand(Inst.getOperand(1)); // lane
6378 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6379 TmpInst.addOperand(Inst.getOperand(5));
6384 case ARM::VLD4LNdWB_fixed_Asm_8:
6385 case ARM::VLD4LNdWB_fixed_Asm_16:
6386 case ARM::VLD4LNdWB_fixed_Asm_32:
6387 case ARM::VLD4LNqWB_fixed_Asm_16:
6388 case ARM::VLD4LNqWB_fixed_Asm_32: {
6390 // Shuffle the operands around so the lane index operand is in the
6393 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6394 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6395 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6397 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6399 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6401 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6402 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6403 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6404 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6405 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6408 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6410 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6412 TmpInst.addOperand(Inst.getOperand(1)); // lane
6413 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6414 TmpInst.addOperand(Inst.getOperand(5));
6419 case ARM::VLD1LNdAsm_8:
6420 case ARM::VLD1LNdAsm_16:
6421 case ARM::VLD1LNdAsm_32: {
6423 // Shuffle the operands around so the lane index operand is in the
6426 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6427 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6428 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6429 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6430 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6431 TmpInst.addOperand(Inst.getOperand(1)); // lane
6432 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6433 TmpInst.addOperand(Inst.getOperand(5));
6438 case ARM::VLD2LNdAsm_8:
6439 case ARM::VLD2LNdAsm_16:
6440 case ARM::VLD2LNdAsm_32:
6441 case ARM::VLD2LNqAsm_16:
6442 case ARM::VLD2LNqAsm_32: {
6444 // Shuffle the operands around so the lane index operand is in the
6447 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6448 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6449 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6451 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6452 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6453 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6454 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6456 TmpInst.addOperand(Inst.getOperand(1)); // lane
6457 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6458 TmpInst.addOperand(Inst.getOperand(5));
6463 case ARM::VLD3LNdAsm_8:
6464 case ARM::VLD3LNdAsm_16:
6465 case ARM::VLD3LNdAsm_32:
6466 case ARM::VLD3LNqAsm_16:
6467 case ARM::VLD3LNqAsm_32: {
6469 // Shuffle the operands around so the lane index operand is in the
6472 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6473 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6474 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6476 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6478 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6479 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6480 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6481 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6483 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6485 TmpInst.addOperand(Inst.getOperand(1)); // lane
6486 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6487 TmpInst.addOperand(Inst.getOperand(5));
6492 case ARM::VLD4LNdAsm_8:
6493 case ARM::VLD4LNdAsm_16:
6494 case ARM::VLD4LNdAsm_32:
6495 case ARM::VLD4LNqAsm_16:
6496 case ARM::VLD4LNqAsm_32: {
6498 // Shuffle the operands around so the lane index operand is in the
6501 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6502 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6503 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6505 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6507 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6509 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6510 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6511 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6512 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6514 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6516 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6518 TmpInst.addOperand(Inst.getOperand(1)); // lane
6519 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6520 TmpInst.addOperand(Inst.getOperand(5));
6525 // VLD3DUP single 3-element structure to all lanes instructions.
6526 case ARM::VLD3DUPdAsm_8:
6527 case ARM::VLD3DUPdAsm_16:
6528 case ARM::VLD3DUPdAsm_32:
6529 case ARM::VLD3DUPqAsm_8:
6530 case ARM::VLD3DUPqAsm_16:
6531 case ARM::VLD3DUPqAsm_32: {
6534 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6535 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6536 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6540 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6541 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6542 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6543 TmpInst.addOperand(Inst.getOperand(4));
6548 case ARM::VLD3DUPdWB_fixed_Asm_8:
6549 case ARM::VLD3DUPdWB_fixed_Asm_16:
6550 case ARM::VLD3DUPdWB_fixed_Asm_32:
6551 case ARM::VLD3DUPqWB_fixed_Asm_8:
6552 case ARM::VLD3DUPqWB_fixed_Asm_16:
6553 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6556 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6557 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6558 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6560 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6562 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6563 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6564 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6565 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6566 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6567 TmpInst.addOperand(Inst.getOperand(4));
6572 case ARM::VLD3DUPdWB_register_Asm_8:
6573 case ARM::VLD3DUPdWB_register_Asm_16:
6574 case ARM::VLD3DUPdWB_register_Asm_32:
6575 case ARM::VLD3DUPqWB_register_Asm_8:
6576 case ARM::VLD3DUPqWB_register_Asm_16:
6577 case ARM::VLD3DUPqWB_register_Asm_32: {
6580 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6581 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6582 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6584 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6586 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6587 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6588 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6589 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6590 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6591 TmpInst.addOperand(Inst.getOperand(5));
6596 // VLD3 multiple 3-element structure instructions.
6597 case ARM::VLD3dAsm_8:
6598 case ARM::VLD3dAsm_16:
6599 case ARM::VLD3dAsm_32:
6600 case ARM::VLD3qAsm_8:
6601 case ARM::VLD3qAsm_16:
6602 case ARM::VLD3qAsm_32: {
6605 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6606 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6607 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6609 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6611 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6612 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6613 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6614 TmpInst.addOperand(Inst.getOperand(4));
6619 case ARM::VLD3dWB_fixed_Asm_8:
6620 case ARM::VLD3dWB_fixed_Asm_16:
6621 case ARM::VLD3dWB_fixed_Asm_32:
6622 case ARM::VLD3qWB_fixed_Asm_8:
6623 case ARM::VLD3qWB_fixed_Asm_16:
6624 case ARM::VLD3qWB_fixed_Asm_32: {
6627 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6628 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6629 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6631 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6634 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6635 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6636 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6637 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6638 TmpInst.addOperand(Inst.getOperand(4));
6643 case ARM::VLD3dWB_register_Asm_8:
6644 case ARM::VLD3dWB_register_Asm_16:
6645 case ARM::VLD3dWB_register_Asm_32:
6646 case ARM::VLD3qWB_register_Asm_8:
6647 case ARM::VLD3qWB_register_Asm_16:
6648 case ARM::VLD3qWB_register_Asm_32: {
6651 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6652 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6653 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6655 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6657 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6658 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6659 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6660 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6661 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6662 TmpInst.addOperand(Inst.getOperand(5));
6667 // VLD4DUP single 3-element structure to all lanes instructions.
6668 case ARM::VLD4DUPdAsm_8:
6669 case ARM::VLD4DUPdAsm_16:
6670 case ARM::VLD4DUPdAsm_32:
6671 case ARM::VLD4DUPqAsm_8:
6672 case ARM::VLD4DUPqAsm_16:
6673 case ARM::VLD4DUPqAsm_32: {
6676 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6677 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6678 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6680 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6682 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6684 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6685 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6686 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6687 TmpInst.addOperand(Inst.getOperand(4));
6692 case ARM::VLD4DUPdWB_fixed_Asm_8:
6693 case ARM::VLD4DUPdWB_fixed_Asm_16:
6694 case ARM::VLD4DUPdWB_fixed_Asm_32:
6695 case ARM::VLD4DUPqWB_fixed_Asm_8:
6696 case ARM::VLD4DUPqWB_fixed_Asm_16:
6697 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6700 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6701 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6702 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6704 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6706 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6708 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6709 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6710 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6711 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6712 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6713 TmpInst.addOperand(Inst.getOperand(4));
6718 case ARM::VLD4DUPdWB_register_Asm_8:
6719 case ARM::VLD4DUPdWB_register_Asm_16:
6720 case ARM::VLD4DUPdWB_register_Asm_32:
6721 case ARM::VLD4DUPqWB_register_Asm_8:
6722 case ARM::VLD4DUPqWB_register_Asm_16:
6723 case ARM::VLD4DUPqWB_register_Asm_32: {
6726 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6727 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6728 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6730 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6732 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6734 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6735 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6736 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6737 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6738 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6739 TmpInst.addOperand(Inst.getOperand(5));
6744 // VLD4 multiple 4-element structure instructions.
6745 case ARM::VLD4dAsm_8:
6746 case ARM::VLD4dAsm_16:
6747 case ARM::VLD4dAsm_32:
6748 case ARM::VLD4qAsm_8:
6749 case ARM::VLD4qAsm_16:
6750 case ARM::VLD4qAsm_32: {
6753 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6754 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6755 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6759 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6761 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6762 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6763 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6764 TmpInst.addOperand(Inst.getOperand(4));
6769 case ARM::VLD4dWB_fixed_Asm_8:
6770 case ARM::VLD4dWB_fixed_Asm_16:
6771 case ARM::VLD4dWB_fixed_Asm_32:
6772 case ARM::VLD4qWB_fixed_Asm_8:
6773 case ARM::VLD4qWB_fixed_Asm_16:
6774 case ARM::VLD4qWB_fixed_Asm_32: {
6777 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6778 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6783 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6785 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6786 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6787 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6788 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6789 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6790 TmpInst.addOperand(Inst.getOperand(4));
6795 case ARM::VLD4dWB_register_Asm_8:
6796 case ARM::VLD4dWB_register_Asm_16:
6797 case ARM::VLD4dWB_register_Asm_32:
6798 case ARM::VLD4qWB_register_Asm_8:
6799 case ARM::VLD4qWB_register_Asm_16:
6800 case ARM::VLD4qWB_register_Asm_32: {
6803 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6804 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6805 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6807 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6809 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6811 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6812 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6813 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6814 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6815 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6816 TmpInst.addOperand(Inst.getOperand(5));
6821 // VST3 multiple 3-element structure instructions.
6822 case ARM::VST3dAsm_8:
6823 case ARM::VST3dAsm_16:
6824 case ARM::VST3dAsm_32:
6825 case ARM::VST3qAsm_8:
6826 case ARM::VST3qAsm_16:
6827 case ARM::VST3qAsm_32: {
6830 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6831 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6832 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6833 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6834 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6836 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6838 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6839 TmpInst.addOperand(Inst.getOperand(4));
6844 case ARM::VST3dWB_fixed_Asm_8:
6845 case ARM::VST3dWB_fixed_Asm_16:
6846 case ARM::VST3dWB_fixed_Asm_32:
6847 case ARM::VST3qWB_fixed_Asm_8:
6848 case ARM::VST3qWB_fixed_Asm_16:
6849 case ARM::VST3qWB_fixed_Asm_32: {
6852 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6853 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6854 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6855 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6856 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6857 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6860 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6862 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6863 TmpInst.addOperand(Inst.getOperand(4));
6868 case ARM::VST3dWB_register_Asm_8:
6869 case ARM::VST3dWB_register_Asm_16:
6870 case ARM::VST3dWB_register_Asm_32:
6871 case ARM::VST3qWB_register_Asm_8:
6872 case ARM::VST3qWB_register_Asm_16:
6873 case ARM::VST3qWB_register_Asm_32: {
6876 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6877 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6878 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6879 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6880 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6881 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6886 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6887 TmpInst.addOperand(Inst.getOperand(5));
6892 // VST4 multiple 3-element structure instructions.
6893 case ARM::VST4dAsm_8:
6894 case ARM::VST4dAsm_16:
6895 case ARM::VST4dAsm_32:
6896 case ARM::VST4qAsm_8:
6897 case ARM::VST4qAsm_16:
6898 case ARM::VST4qAsm_32: {
6901 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6902 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6903 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6904 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6905 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6907 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6909 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6911 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6912 TmpInst.addOperand(Inst.getOperand(4));
6917 case ARM::VST4dWB_fixed_Asm_8:
6918 case ARM::VST4dWB_fixed_Asm_16:
6919 case ARM::VST4dWB_fixed_Asm_32:
6920 case ARM::VST4qWB_fixed_Asm_8:
6921 case ARM::VST4qWB_fixed_Asm_16:
6922 case ARM::VST4qWB_fixed_Asm_32: {
6925 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6926 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6927 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6928 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6929 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6930 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6931 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6933 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6935 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6937 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6938 TmpInst.addOperand(Inst.getOperand(4));
6943 case ARM::VST4dWB_register_Asm_8:
6944 case ARM::VST4dWB_register_Asm_16:
6945 case ARM::VST4dWB_register_Asm_32:
6946 case ARM::VST4qWB_register_Asm_8:
6947 case ARM::VST4qWB_register_Asm_16:
6948 case ARM::VST4qWB_register_Asm_32: {
6951 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6952 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6953 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6954 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6955 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6956 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6957 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6959 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6961 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6963 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6964 TmpInst.addOperand(Inst.getOperand(5));
6969 // Handle encoding choice for the shift-immediate instructions.
6972 case ARM::t2ASRri: {
6973 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6974 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6975 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6976 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6977 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6979 switch (Inst.getOpcode()) {
6980 default: llvm_unreachable("unexpected opcode");
6981 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6982 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6983 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6985 // The Thumb1 operands aren't in the same order. Awesome, eh?
6987 TmpInst.setOpcode(NewOpc);
6988 TmpInst.addOperand(Inst.getOperand(0));
6989 TmpInst.addOperand(Inst.getOperand(5));
6990 TmpInst.addOperand(Inst.getOperand(1));
6991 TmpInst.addOperand(Inst.getOperand(2));
6992 TmpInst.addOperand(Inst.getOperand(3));
6993 TmpInst.addOperand(Inst.getOperand(4));
7000 // Handle the Thumb2 mode MOV complex aliases.
7002 case ARM::t2MOVSsr: {
7003 // Which instruction to expand to depends on the CCOut operand and
7004 // whether we're in an IT block if the register operands are low
7006 bool isNarrow = false;
7007 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7008 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7009 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7010 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7011 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7015 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7016 default: llvm_unreachable("unexpected opcode!");
7017 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7018 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7019 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7020 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7022 TmpInst.setOpcode(newOpc);
7023 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7025 TmpInst.addOperand(MCOperand::CreateReg(
7026 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7027 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7028 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7029 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7030 TmpInst.addOperand(Inst.getOperand(5));
7032 TmpInst.addOperand(MCOperand::CreateReg(
7033 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7038 case ARM::t2MOVSsi: {
7039 // Which instruction to expand to depends on the CCOut operand and
7040 // whether we're in an IT block if the register operands are low
7042 bool isNarrow = false;
7043 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7044 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7045 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7049 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7050 default: llvm_unreachable("unexpected opcode!");
7051 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7052 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7053 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7054 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7055 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7057 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7058 if (Amount == 32) Amount = 0;
7059 TmpInst.setOpcode(newOpc);
7060 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7062 TmpInst.addOperand(MCOperand::CreateReg(
7063 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7064 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7065 if (newOpc != ARM::t2RRX)
7066 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7067 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7068 TmpInst.addOperand(Inst.getOperand(4));
7070 TmpInst.addOperand(MCOperand::CreateReg(
7071 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7075 // Handle the ARM mode MOV complex aliases.
7080 ARM_AM::ShiftOpc ShiftTy;
7081 switch(Inst.getOpcode()) {
7082 default: llvm_unreachable("unexpected opcode!");
7083 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7084 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7085 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7086 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7088 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7090 TmpInst.setOpcode(ARM::MOVsr);
7091 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7092 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7093 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7094 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7095 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7096 TmpInst.addOperand(Inst.getOperand(4));
7097 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7105 ARM_AM::ShiftOpc ShiftTy;
7106 switch(Inst.getOpcode()) {
7107 default: llvm_unreachable("unexpected opcode!");
7108 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7109 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7110 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7111 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7113 // A shift by zero is a plain MOVr, not a MOVsi.
7114 unsigned Amt = Inst.getOperand(2).getImm();
7115 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7116 // A shift by 32 should be encoded as 0 when permitted
7117 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7119 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7121 TmpInst.setOpcode(Opc);
7122 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7123 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7124 if (Opc == ARM::MOVsi)
7125 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7126 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7127 TmpInst.addOperand(Inst.getOperand(4));
7128 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7133 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7135 TmpInst.setOpcode(ARM::MOVsi);
7136 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7137 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7138 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7139 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7140 TmpInst.addOperand(Inst.getOperand(3));
7141 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7145 case ARM::t2LDMIA_UPD: {
7146 // If this is a load of a single register, then we should use
7147 // a post-indexed LDR instruction instead, per the ARM ARM.
7148 if (Inst.getNumOperands() != 5)
7151 TmpInst.setOpcode(ARM::t2LDR_POST);
7152 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7153 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7154 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7155 TmpInst.addOperand(MCOperand::CreateImm(4));
7156 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7157 TmpInst.addOperand(Inst.getOperand(3));
7161 case ARM::t2STMDB_UPD: {
7162 // If this is a store of a single register, then we should use
7163 // a pre-indexed STR instruction instead, per the ARM ARM.
7164 if (Inst.getNumOperands() != 5)
7167 TmpInst.setOpcode(ARM::t2STR_PRE);
7168 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7169 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7170 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7171 TmpInst.addOperand(MCOperand::CreateImm(-4));
7172 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7173 TmpInst.addOperand(Inst.getOperand(3));
7177 case ARM::LDMIA_UPD:
7178 // If this is a load of a single register via a 'pop', then we should use
7179 // a post-indexed LDR instruction instead, per the ARM ARM.
7180 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7181 Inst.getNumOperands() == 5) {
7183 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7184 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7185 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7186 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7187 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7188 TmpInst.addOperand(MCOperand::CreateImm(4));
7189 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7190 TmpInst.addOperand(Inst.getOperand(3));
7195 case ARM::STMDB_UPD:
7196 // If this is a store of a single register via a 'push', then we should use
7197 // a pre-indexed STR instruction instead, per the ARM ARM.
7198 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7199 Inst.getNumOperands() == 5) {
7201 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7202 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7203 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7204 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7205 TmpInst.addOperand(MCOperand::CreateImm(-4));
7206 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7207 TmpInst.addOperand(Inst.getOperand(3));
7211 case ARM::t2ADDri12:
7212 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7213 // mnemonic was used (not "addw"), encoding T3 is preferred.
7214 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7215 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7217 Inst.setOpcode(ARM::t2ADDri);
7218 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7220 case ARM::t2SUBri12:
7221 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7222 // mnemonic was used (not "subw"), encoding T3 is preferred.
7223 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7224 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7226 Inst.setOpcode(ARM::t2SUBri);
7227 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7230 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7231 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7232 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7233 // to encoding T1 if <Rd> is omitted."
7234 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7235 Inst.setOpcode(ARM::tADDi3);
7240 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7241 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7242 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7243 // to encoding T1 if <Rd> is omitted."
7244 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7245 Inst.setOpcode(ARM::tSUBi3);
7250 case ARM::t2SUBri: {
7251 // If the destination and first source operand are the same, and
7252 // the flags are compatible with the current IT status, use encoding T2
7253 // instead of T3. For compatibility with the system 'as'. Make sure the
7254 // wide encoding wasn't explicit.
7255 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7256 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7257 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7258 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7259 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7260 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7261 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7264 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7265 ARM::tADDi8 : ARM::tSUBi8);
7266 TmpInst.addOperand(Inst.getOperand(0));
7267 TmpInst.addOperand(Inst.getOperand(5));
7268 TmpInst.addOperand(Inst.getOperand(0));
7269 TmpInst.addOperand(Inst.getOperand(2));
7270 TmpInst.addOperand(Inst.getOperand(3));
7271 TmpInst.addOperand(Inst.getOperand(4));
7275 case ARM::t2ADDrr: {
7276 // If the destination and first source operand are the same, and
7277 // there's no setting of the flags, use encoding T2 instead of T3.
7278 // Note that this is only for ADD, not SUB. This mirrors the system
7279 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7280 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7281 Inst.getOperand(5).getReg() != 0 ||
7282 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7283 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7286 TmpInst.setOpcode(ARM::tADDhirr);
7287 TmpInst.addOperand(Inst.getOperand(0));
7288 TmpInst.addOperand(Inst.getOperand(0));
7289 TmpInst.addOperand(Inst.getOperand(2));
7290 TmpInst.addOperand(Inst.getOperand(3));
7291 TmpInst.addOperand(Inst.getOperand(4));
7295 case ARM::tADDrSP: {
7296 // If the non-SP source operand and the destination operand are not the
7297 // same, we need to use the 32-bit encoding if it's available.
7298 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7299 Inst.setOpcode(ARM::t2ADDrr);
7300 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7306 // A Thumb conditional branch outside of an IT block is a tBcc.
7307 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7308 Inst.setOpcode(ARM::tBcc);
7313 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7314 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7315 Inst.setOpcode(ARM::t2Bcc);
7320 // If the conditional is AL or we're in an IT block, we really want t2B.
7321 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7322 Inst.setOpcode(ARM::t2B);
7327 // If the conditional is AL, we really want tB.
7328 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7329 Inst.setOpcode(ARM::tB);
7334 // If the register list contains any high registers, or if the writeback
7335 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7336 // instead if we're in Thumb2. Otherwise, this should have generated
7337 // an error in validateInstruction().
7338 unsigned Rn = Inst.getOperand(0).getReg();
7339 bool hasWritebackToken =
7340 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7341 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7342 bool listContainsBase;
7343 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7344 (!listContainsBase && !hasWritebackToken) ||
7345 (listContainsBase && hasWritebackToken)) {
7346 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7347 assert (isThumbTwo());
7348 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7349 // If we're switching to the updating version, we need to insert
7350 // the writeback tied operand.
7351 if (hasWritebackToken)
7352 Inst.insert(Inst.begin(),
7353 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7358 case ARM::tSTMIA_UPD: {
7359 // If the register list contains any high registers, we need to use
7360 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7361 // should have generated an error in validateInstruction().
7362 unsigned Rn = Inst.getOperand(0).getReg();
7363 bool listContainsBase;
7364 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7365 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7366 assert (isThumbTwo());
7367 Inst.setOpcode(ARM::t2STMIA_UPD);
7373 bool listContainsBase;
7374 // If the register list contains any high registers, we need to use
7375 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7376 // should have generated an error in validateInstruction().
7377 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7379 assert (isThumbTwo());
7380 Inst.setOpcode(ARM::t2LDMIA_UPD);
7381 // Add the base register and writeback operands.
7382 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7383 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7387 bool listContainsBase;
7388 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7390 assert (isThumbTwo());
7391 Inst.setOpcode(ARM::t2STMDB_UPD);
7392 // Add the base register and writeback operands.
7393 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7394 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7398 // If we can use the 16-bit encoding and the user didn't explicitly
7399 // request the 32-bit variant, transform it here.
7400 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7401 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7402 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7403 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7404 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7405 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7406 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7407 // The operands aren't in the same order for tMOVi8...
7409 TmpInst.setOpcode(ARM::tMOVi8);
7410 TmpInst.addOperand(Inst.getOperand(0));
7411 TmpInst.addOperand(Inst.getOperand(4));
7412 TmpInst.addOperand(Inst.getOperand(1));
7413 TmpInst.addOperand(Inst.getOperand(2));
7414 TmpInst.addOperand(Inst.getOperand(3));
7421 // If we can use the 16-bit encoding and the user didn't explicitly
7422 // request the 32-bit variant, transform it here.
7423 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7424 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7425 Inst.getOperand(2).getImm() == ARMCC::AL &&
7426 Inst.getOperand(4).getReg() == ARM::CPSR &&
7427 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7428 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7429 // The operands aren't the same for tMOV[S]r... (no cc_out)
7431 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7432 TmpInst.addOperand(Inst.getOperand(0));
7433 TmpInst.addOperand(Inst.getOperand(1));
7434 TmpInst.addOperand(Inst.getOperand(2));
7435 TmpInst.addOperand(Inst.getOperand(3));
7445 // If we can use the 16-bit encoding and the user didn't explicitly
7446 // request the 32-bit variant, transform it here.
7447 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7448 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7449 Inst.getOperand(2).getImm() == 0 &&
7450 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7451 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7453 switch (Inst.getOpcode()) {
7454 default: llvm_unreachable("Illegal opcode!");
7455 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7456 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7457 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7458 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7460 // The operands aren't the same for thumb1 (no rotate operand).
7462 TmpInst.setOpcode(NewOpc);
7463 TmpInst.addOperand(Inst.getOperand(0));
7464 TmpInst.addOperand(Inst.getOperand(1));
7465 TmpInst.addOperand(Inst.getOperand(3));
7466 TmpInst.addOperand(Inst.getOperand(4));
7473 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7474 // rrx shifts and asr/lsr of #32 is encoded as 0
7475 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7477 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7478 // Shifting by zero is accepted as a vanilla 'MOVr'
7480 TmpInst.setOpcode(ARM::MOVr);
7481 TmpInst.addOperand(Inst.getOperand(0));
7482 TmpInst.addOperand(Inst.getOperand(1));
7483 TmpInst.addOperand(Inst.getOperand(3));
7484 TmpInst.addOperand(Inst.getOperand(4));
7485 TmpInst.addOperand(Inst.getOperand(5));
7498 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7499 if (SOpc == ARM_AM::rrx) return false;
7500 switch (Inst.getOpcode()) {
7501 default: llvm_unreachable("unexpected opcode!");
7502 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7503 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7504 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7505 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7506 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7507 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7509 // If the shift is by zero, use the non-shifted instruction definition.
7510 // The exception is for right shifts, where 0 == 32
7511 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7512 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7514 TmpInst.setOpcode(newOpc);
7515 TmpInst.addOperand(Inst.getOperand(0));
7516 TmpInst.addOperand(Inst.getOperand(1));
7517 TmpInst.addOperand(Inst.getOperand(2));
7518 TmpInst.addOperand(Inst.getOperand(4));
7519 TmpInst.addOperand(Inst.getOperand(5));
7520 TmpInst.addOperand(Inst.getOperand(6));
7528 // The mask bits for all but the first condition are represented as
7529 // the low bit of the condition code value implies 't'. We currently
7530 // always have 1 implies 't', so XOR toggle the bits if the low bit
7531 // of the condition code is zero.
7532 MCOperand &MO = Inst.getOperand(1);
7533 unsigned Mask = MO.getImm();
7534 unsigned OrigMask = Mask;
7535 unsigned TZ = countTrailingZeros(Mask);
7536 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7537 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7538 Mask ^= (0xE << TZ) & 0xF;
7542 // Set up the IT block state according to the IT instruction we just
7544 assert(!inITBlock() && "nested IT blocks?!");
7545 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7546 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7547 ITState.CurPosition = 0;
7548 ITState.FirstCond = true;
7558 // Assemblers should use the narrow encodings of these instructions when permissible.
7559 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7560 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7561 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7562 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7563 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7564 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7565 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7567 switch (Inst.getOpcode()) {
7568 default: llvm_unreachable("unexpected opcode");
7569 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7570 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7571 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7572 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7573 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7574 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7577 TmpInst.setOpcode(NewOpc);
7578 TmpInst.addOperand(Inst.getOperand(0));
7579 TmpInst.addOperand(Inst.getOperand(5));
7580 TmpInst.addOperand(Inst.getOperand(1));
7581 TmpInst.addOperand(Inst.getOperand(2));
7582 TmpInst.addOperand(Inst.getOperand(3));
7583 TmpInst.addOperand(Inst.getOperand(4));
7594 // Assemblers should use the narrow encodings of these instructions when permissible.
7595 // These instructions are special in that they are commutable, so shorter encodings
7596 // are available more often.
7597 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7598 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7599 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7600 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7601 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7602 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7603 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7604 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7606 switch (Inst.getOpcode()) {
7607 default: llvm_unreachable("unexpected opcode");
7608 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7609 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7610 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7611 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7614 TmpInst.setOpcode(NewOpc);
7615 TmpInst.addOperand(Inst.getOperand(0));
7616 TmpInst.addOperand(Inst.getOperand(5));
7617 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7618 TmpInst.addOperand(Inst.getOperand(1));
7619 TmpInst.addOperand(Inst.getOperand(2));
7621 TmpInst.addOperand(Inst.getOperand(2));
7622 TmpInst.addOperand(Inst.getOperand(1));
7624 TmpInst.addOperand(Inst.getOperand(3));
7625 TmpInst.addOperand(Inst.getOperand(4));
7635 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7636 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7637 // suffix depending on whether they're in an IT block or not.
7638 unsigned Opc = Inst.getOpcode();
7639 const MCInstrDesc &MCID = getInstDesc(Opc);
7640 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7641 assert(MCID.hasOptionalDef() &&
7642 "optionally flag setting instruction missing optional def operand");
7643 assert(MCID.NumOperands == Inst.getNumOperands() &&
7644 "operand count mismatch!");
7645 // Find the optional-def operand (cc_out).
7648 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7651 // If we're parsing Thumb1, reject it completely.
7652 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7653 return Match_MnemonicFail;
7654 // If we're parsing Thumb2, which form is legal depends on whether we're
7656 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7658 return Match_RequiresITBlock;
7659 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7661 return Match_RequiresNotITBlock;
7663 // Some high-register supporting Thumb1 encodings only allow both registers
7664 // to be from r0-r7 when in Thumb2.
7665 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7666 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7667 isARMLowRegister(Inst.getOperand(2).getReg()))
7668 return Match_RequiresThumb2;
7669 // Others only require ARMv6 or later.
7670 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7671 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7672 isARMLowRegister(Inst.getOperand(1).getReg()))
7673 return Match_RequiresV6;
7674 return Match_Success;
7677 static const char *getSubtargetFeatureName(unsigned Val);
7679 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7680 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7681 MCStreamer &Out, unsigned &ErrorInfo,
7682 bool MatchingInlineAsm) {
7684 unsigned MatchResult;
7686 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7688 switch (MatchResult) {
7691 // Context sensitive operand constraints aren't handled by the matcher,
7692 // so check them here.
7693 if (validateInstruction(Inst, Operands)) {
7694 // Still progress the IT block, otherwise one wrong condition causes
7695 // nasty cascading errors.
7696 forwardITPosition();
7700 // Some instructions need post-processing to, for example, tweak which
7701 // encoding is selected. Loop on it while changes happen so the
7702 // individual transformations can chain off each other. E.g.,
7703 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7704 while (processInstruction(Inst, Operands))
7707 // Only move forward at the very end so that everything in validate
7708 // and process gets a consistent answer about whether we're in an IT
7710 forwardITPosition();
7712 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7713 // doesn't actually encode.
7714 if (Inst.getOpcode() == ARM::ITasm)
7718 Out.EmitInstruction(Inst);
7720 case Match_MissingFeature: {
7721 assert(ErrorInfo && "Unknown missing feature!");
7722 // Special case the error message for the very common case where only
7723 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7724 std::string Msg = "instruction requires:";
7726 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7727 if (ErrorInfo & Mask) {
7729 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7733 return Error(IDLoc, Msg);
7735 case Match_InvalidOperand: {
7736 SMLoc ErrorLoc = IDLoc;
7737 if (ErrorInfo != ~0U) {
7738 if (ErrorInfo >= Operands.size())
7739 return Error(IDLoc, "too few operands for instruction");
7741 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7742 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7745 return Error(ErrorLoc, "invalid operand for instruction");
7747 case Match_MnemonicFail:
7748 return Error(IDLoc, "invalid instruction",
7749 ((ARMOperand*)Operands[0])->getLocRange());
7750 case Match_RequiresNotITBlock:
7751 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7752 case Match_RequiresITBlock:
7753 return Error(IDLoc, "instruction only valid inside IT block");
7754 case Match_RequiresV6:
7755 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7756 case Match_RequiresThumb2:
7757 return Error(IDLoc, "instruction variant requires Thumb2");
7758 case Match_ImmRange0_4: {
7759 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7760 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7761 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7763 case Match_ImmRange0_15: {
7764 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7765 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7766 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7770 llvm_unreachable("Implement any new match types added!");
7773 /// parseDirective parses the arm specific directives
7774 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7775 StringRef IDVal = DirectiveID.getIdentifier();
7776 if (IDVal == ".word")
7777 return parseDirectiveWord(4, DirectiveID.getLoc());
7778 else if (IDVal == ".thumb")
7779 return parseDirectiveThumb(DirectiveID.getLoc());
7780 else if (IDVal == ".arm")
7781 return parseDirectiveARM(DirectiveID.getLoc());
7782 else if (IDVal == ".thumb_func")
7783 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7784 else if (IDVal == ".code")
7785 return parseDirectiveCode(DirectiveID.getLoc());
7786 else if (IDVal == ".syntax")
7787 return parseDirectiveSyntax(DirectiveID.getLoc());
7788 else if (IDVal == ".unreq")
7789 return parseDirectiveUnreq(DirectiveID.getLoc());
7790 else if (IDVal == ".arch")
7791 return parseDirectiveArch(DirectiveID.getLoc());
7792 else if (IDVal == ".eabi_attribute")
7793 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7794 else if (IDVal == ".fnstart")
7795 return parseDirectiveFnStart(DirectiveID.getLoc());
7796 else if (IDVal == ".fnend")
7797 return parseDirectiveFnEnd(DirectiveID.getLoc());
7798 else if (IDVal == ".cantunwind")
7799 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7800 else if (IDVal == ".personality")
7801 return parseDirectivePersonality(DirectiveID.getLoc());
7802 else if (IDVal == ".handlerdata")
7803 return parseDirectiveHandlerData(DirectiveID.getLoc());
7804 else if (IDVal == ".setfp")
7805 return parseDirectiveSetFP(DirectiveID.getLoc());
7806 else if (IDVal == ".pad")
7807 return parseDirectivePad(DirectiveID.getLoc());
7808 else if (IDVal == ".save")
7809 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7810 else if (IDVal == ".vsave")
7811 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7815 /// parseDirectiveWord
7816 /// ::= .word [ expression (, expression)* ]
7817 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7818 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7820 const MCExpr *Value;
7821 if (getParser().parseExpression(Value))
7824 getParser().getStreamer().EmitValue(Value, Size);
7826 if (getLexer().is(AsmToken::EndOfStatement))
7829 // FIXME: Improve diagnostic.
7830 if (getLexer().isNot(AsmToken::Comma))
7831 return Error(L, "unexpected token in directive");
7840 /// parseDirectiveThumb
7842 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7843 if (getLexer().isNot(AsmToken::EndOfStatement))
7844 return Error(L, "unexpected token in directive");
7848 return Error(L, "target does not support Thumb mode");
7852 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7856 /// parseDirectiveARM
7858 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7859 if (getLexer().isNot(AsmToken::EndOfStatement))
7860 return Error(L, "unexpected token in directive");
7864 return Error(L, "target does not support ARM mode");
7868 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7872 /// parseDirectiveThumbFunc
7873 /// ::= .thumbfunc symbol_name
7874 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7875 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7876 bool isMachO = MAI->hasSubsectionsViaSymbols();
7878 bool needFuncName = true;
7880 // Darwin asm has (optionally) function name after .thumb_func direction
7883 const AsmToken &Tok = Parser.getTok();
7884 if (Tok.isNot(AsmToken::EndOfStatement)) {
7885 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7886 return Error(L, "unexpected token in .thumb_func directive");
7887 Name = Tok.getIdentifier();
7888 Parser.Lex(); // Consume the identifier token.
7889 needFuncName = false;
7893 if (getLexer().isNot(AsmToken::EndOfStatement))
7894 return Error(L, "unexpected token in directive");
7896 // Eat the end of statement and any blank lines that follow.
7897 while (getLexer().is(AsmToken::EndOfStatement))
7900 // FIXME: assuming function name will be the line following .thumb_func
7901 // We really should be checking the next symbol definition even if there's
7902 // stuff in between.
7904 Name = Parser.getTok().getIdentifier();
7907 // Mark symbol as a thumb symbol.
7908 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7909 getParser().getStreamer().EmitThumbFunc(Func);
7913 /// parseDirectiveSyntax
7914 /// ::= .syntax unified | divided
7915 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7916 const AsmToken &Tok = Parser.getTok();
7917 if (Tok.isNot(AsmToken::Identifier))
7918 return Error(L, "unexpected token in .syntax directive");
7919 StringRef Mode = Tok.getString();
7920 if (Mode == "unified" || Mode == "UNIFIED")
7922 else if (Mode == "divided" || Mode == "DIVIDED")
7923 return Error(L, "'.syntax divided' arm asssembly not supported");
7925 return Error(L, "unrecognized syntax mode in .syntax directive");
7927 if (getLexer().isNot(AsmToken::EndOfStatement))
7928 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7931 // TODO tell the MC streamer the mode
7932 // getParser().getStreamer().Emit???();
7936 /// parseDirectiveCode
7937 /// ::= .code 16 | 32
7938 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7939 const AsmToken &Tok = Parser.getTok();
7940 if (Tok.isNot(AsmToken::Integer))
7941 return Error(L, "unexpected token in .code directive");
7942 int64_t Val = Parser.getTok().getIntVal();
7948 return Error(L, "invalid operand to .code directive");
7950 if (getLexer().isNot(AsmToken::EndOfStatement))
7951 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7956 return Error(L, "target does not support Thumb mode");
7960 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7963 return Error(L, "target does not support ARM mode");
7967 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7973 /// parseDirectiveReq
7974 /// ::= name .req registername
7975 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7976 Parser.Lex(); // Eat the '.req' token.
7978 SMLoc SRegLoc, ERegLoc;
7979 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7980 Parser.eatToEndOfStatement();
7981 return Error(SRegLoc, "register name expected");
7984 // Shouldn't be anything else.
7985 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7986 Parser.eatToEndOfStatement();
7987 return Error(Parser.getTok().getLoc(),
7988 "unexpected input in .req directive.");
7991 Parser.Lex(); // Consume the EndOfStatement
7993 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7994 return Error(SRegLoc, "redefinition of '" + Name +
7995 "' does not match original.");
8000 /// parseDirectiveUneq
8001 /// ::= .unreq registername
8002 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8003 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8004 Parser.eatToEndOfStatement();
8005 return Error(L, "unexpected input in .unreq directive.");
8007 RegisterReqs.erase(Parser.getTok().getIdentifier());
8008 Parser.Lex(); // Eat the identifier.
8012 /// parseDirectiveArch
8014 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8018 /// parseDirectiveEabiAttr
8019 /// ::= .eabi_attribute int, int
8020 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8024 /// parseDirectiveFnStart
8026 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8027 if (FnStartLoc.isValid()) {
8028 Error(L, ".fnstart starts before the end of previous one");
8029 Error(FnStartLoc, "previous .fnstart starts here");
8034 getParser().getStreamer().EmitFnStart();
8038 /// parseDirectiveFnEnd
8040 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8041 // Check the ordering of unwind directives
8042 if (!FnStartLoc.isValid())
8043 return Error(L, ".fnstart must precede .fnend directive");
8045 // Reset the unwind directives parser state
8046 resetUnwindDirectiveParserState();
8048 getParser().getStreamer().EmitFnEnd();
8052 /// parseDirectiveCantUnwind
8054 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8055 // Check the ordering of unwind directives
8057 if (!FnStartLoc.isValid())
8058 return Error(L, ".fnstart must precede .cantunwind directive");
8059 if (HandlerDataLoc.isValid()) {
8060 Error(L, ".cantunwind can't be used with .handlerdata directive");
8061 Error(HandlerDataLoc, ".handlerdata was specified here");
8064 if (PersonalityLoc.isValid()) {
8065 Error(L, ".cantunwind can't be used with .personality directive");
8066 Error(PersonalityLoc, ".personality was specified here");
8070 getParser().getStreamer().EmitCantUnwind();
8074 /// parseDirectivePersonality
8075 /// ::= .personality name
8076 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8077 // Check the ordering of unwind directives
8079 if (!FnStartLoc.isValid())
8080 return Error(L, ".fnstart must precede .personality directive");
8081 if (CantUnwindLoc.isValid()) {
8082 Error(L, ".personality can't be used with .cantunwind directive");
8083 Error(CantUnwindLoc, ".cantunwind was specified here");
8086 if (HandlerDataLoc.isValid()) {
8087 Error(L, ".personality must precede .handlerdata directive");
8088 Error(HandlerDataLoc, ".handlerdata was specified here");
8092 // Parse the name of the personality routine
8093 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8094 Parser.eatToEndOfStatement();
8095 return Error(L, "unexpected input in .personality directive.");
8097 StringRef Name(Parser.getTok().getIdentifier());
8100 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8101 getParser().getStreamer().EmitPersonality(PR);
8105 /// parseDirectiveHandlerData
8106 /// ::= .handlerdata
8107 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8108 // Check the ordering of unwind directives
8110 if (!FnStartLoc.isValid())
8111 return Error(L, ".fnstart must precede .personality directive");
8112 if (CantUnwindLoc.isValid()) {
8113 Error(L, ".handlerdata can't be used with .cantunwind directive");
8114 Error(CantUnwindLoc, ".cantunwind was specified here");
8118 getParser().getStreamer().EmitHandlerData();
8122 /// parseDirectiveSetFP
8123 /// ::= .setfp fpreg, spreg [, offset]
8124 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8125 // Check the ordering of unwind directives
8126 if (!FnStartLoc.isValid())
8127 return Error(L, ".fnstart must precede .setfp directive");
8128 if (HandlerDataLoc.isValid())
8129 return Error(L, ".setfp must precede .handlerdata directive");
8132 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8133 int NewFPReg = tryParseRegister();
8135 return Error(NewFPRegLoc, "frame pointer register expected");
8138 if (!Parser.getTok().is(AsmToken::Comma))
8139 return Error(Parser.getTok().getLoc(), "comma expected");
8140 Parser.Lex(); // skip comma
8143 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8144 int NewSPReg = tryParseRegister();
8146 return Error(NewSPRegLoc, "stack pointer register expected");
8148 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8149 return Error(NewSPRegLoc,
8150 "register should be either $sp or the latest fp register");
8152 // Update the frame pointer register
8157 if (Parser.getTok().is(AsmToken::Comma)) {
8158 Parser.Lex(); // skip comma
8160 if (Parser.getTok().isNot(AsmToken::Hash) &&
8161 Parser.getTok().isNot(AsmToken::Dollar)) {
8162 return Error(Parser.getTok().getLoc(), "'#' expected");
8164 Parser.Lex(); // skip hash token.
8166 const MCExpr *OffsetExpr;
8167 SMLoc ExLoc = Parser.getTok().getLoc();
8169 if (getParser().parseExpression(OffsetExpr, EndLoc))
8170 return Error(ExLoc, "malformed setfp offset");
8171 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8173 return Error(ExLoc, "setfp offset must be an immediate");
8175 Offset = CE->getValue();
8178 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8179 static_cast<unsigned>(NewSPReg),
8186 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8187 // Check the ordering of unwind directives
8188 if (!FnStartLoc.isValid())
8189 return Error(L, ".fnstart must precede .pad directive");
8190 if (HandlerDataLoc.isValid())
8191 return Error(L, ".pad must precede .handlerdata directive");
8194 if (Parser.getTok().isNot(AsmToken::Hash) &&
8195 Parser.getTok().isNot(AsmToken::Dollar)) {
8196 return Error(Parser.getTok().getLoc(), "'#' expected");
8198 Parser.Lex(); // skip hash token.
8200 const MCExpr *OffsetExpr;
8201 SMLoc ExLoc = Parser.getTok().getLoc();
8203 if (getParser().parseExpression(OffsetExpr, EndLoc))
8204 return Error(ExLoc, "malformed pad offset");
8205 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8207 return Error(ExLoc, "pad offset must be an immediate");
8209 getParser().getStreamer().EmitPad(CE->getValue());
8213 /// parseDirectiveRegSave
8214 /// ::= .save { registers }
8215 /// ::= .vsave { registers }
8216 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8217 // Check the ordering of unwind directives
8218 if (!FnStartLoc.isValid())
8219 return Error(L, ".fnstart must precede .save or .vsave directives");
8220 if (HandlerDataLoc.isValid())
8221 return Error(L, ".save or .vsave must precede .handlerdata directive");
8223 // Parse the register list
8224 SmallVector<MCParsedAsmOperand*, 1> Operands;
8225 if (parseRegisterList(Operands))
8227 ARMOperand *Op = (ARMOperand*)Operands[0];
8228 if (!IsVector && !Op->isRegList())
8229 return Error(L, ".save expects GPR registers");
8230 if (IsVector && !Op->isDPRRegList())
8231 return Error(L, ".vsave expects DPR registers");
8233 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8237 /// Force static initialization.
8238 extern "C" void LLVMInitializeARMAsmParser() {
8239 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8240 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8243 #define GET_REGISTER_MATCHER
8244 #define GET_SUBTARGET_FEATURE_NAME
8245 #define GET_MATCHER_IMPLEMENTATION
8246 #include "ARMGenAsmMatcher.inc"
8248 // Define this matcher function after the auto-generated include so we
8249 // have the match class enum definitions.
8250 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8252 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8253 // If the kind is a token for a literal immediate, check if our asm
8254 // operand matches. This is for InstAliases which have a fixed-value
8255 // immediate in the syntax.
8256 if (Kind == MCK__35_0 && Op->isImm()) {
8257 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8259 return Match_InvalidOperand;
8260 if (CE->getValue() == 0)
8261 return Match_Success;
8263 return Match_InvalidOperand;