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(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
2285 SMLoc StartLoc, SMLoc EndLoc) {
2286 KindTy Kind = k_RegisterList;
2288 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
2289 Kind = k_DPRRegisterList;
2290 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2291 contains(Regs.front().first))
2292 Kind = k_SPRRegisterList;
2294 ARMOperand *Op = new ARMOperand(Kind);
2295 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
2296 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2297 Op->Registers.push_back(I->first);
2298 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
2299 Op->StartLoc = StartLoc;
2300 Op->EndLoc = EndLoc;
2304 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2305 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2306 ARMOperand *Op = new ARMOperand(k_VectorList);
2307 Op->VectorList.RegNum = RegNum;
2308 Op->VectorList.Count = Count;
2309 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2315 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2316 bool isDoubleSpaced,
2318 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2319 Op->VectorList.RegNum = RegNum;
2320 Op->VectorList.Count = Count;
2321 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2327 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2329 bool isDoubleSpaced,
2331 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2332 Op->VectorList.RegNum = RegNum;
2333 Op->VectorList.Count = Count;
2334 Op->VectorList.LaneIndex = Index;
2335 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2341 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2343 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2344 Op->VectorIndex.Val = Idx;
2350 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2351 ARMOperand *Op = new ARMOperand(k_Immediate);
2358 static ARMOperand *CreateMem(unsigned BaseRegNum,
2359 const MCConstantExpr *OffsetImm,
2360 unsigned OffsetRegNum,
2361 ARM_AM::ShiftOpc ShiftType,
2366 ARMOperand *Op = new ARMOperand(k_Memory);
2367 Op->Memory.BaseRegNum = BaseRegNum;
2368 Op->Memory.OffsetImm = OffsetImm;
2369 Op->Memory.OffsetRegNum = OffsetRegNum;
2370 Op->Memory.ShiftType = ShiftType;
2371 Op->Memory.ShiftImm = ShiftImm;
2372 Op->Memory.Alignment = Alignment;
2373 Op->Memory.isNegative = isNegative;
2379 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2380 ARM_AM::ShiftOpc ShiftTy,
2383 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2384 Op->PostIdxReg.RegNum = RegNum;
2385 Op->PostIdxReg.isAdd = isAdd;
2386 Op->PostIdxReg.ShiftTy = ShiftTy;
2387 Op->PostIdxReg.ShiftImm = ShiftImm;
2393 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2394 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2395 Op->MBOpt.Val = Opt;
2401 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2403 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2404 Op->ISBOpt.Val = Opt;
2410 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2411 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2412 Op->IFlags.Val = IFlags;
2418 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2419 ARMOperand *Op = new ARMOperand(k_MSRMask);
2420 Op->MMask.Val = MMask;
2427 } // end anonymous namespace.
2429 void ARMOperand::print(raw_ostream &OS) const {
2432 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2435 OS << "<ccout " << getReg() << ">";
2437 case k_ITCondMask: {
2438 static const char *const MaskStr[] = {
2439 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2440 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2442 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2443 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2447 OS << "<coprocessor number: " << getCoproc() << ">";
2450 OS << "<coprocessor register: " << getCoproc() << ">";
2452 case k_CoprocOption:
2453 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2456 OS << "<mask: " << getMSRMask() << ">";
2459 getImm()->print(OS);
2461 case k_MemBarrierOpt:
2462 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2464 case k_InstSyncBarrierOpt:
2465 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2469 << " base:" << Memory.BaseRegNum;
2472 case k_PostIndexRegister:
2473 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2474 << PostIdxReg.RegNum;
2475 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2476 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2477 << PostIdxReg.ShiftImm;
2480 case k_ProcIFlags: {
2481 OS << "<ARM_PROC::";
2482 unsigned IFlags = getProcIFlags();
2483 for (int i=2; i >= 0; --i)
2484 if (IFlags & (1 << i))
2485 OS << ARM_PROC::IFlagsToString(1 << i);
2490 OS << "<register " << getReg() << ">";
2492 case k_ShifterImmediate:
2493 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2494 << " #" << ShifterImm.Imm << ">";
2496 case k_ShiftedRegister:
2497 OS << "<so_reg_reg "
2498 << RegShiftedReg.SrcReg << " "
2499 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2500 << " " << RegShiftedReg.ShiftReg << ">";
2502 case k_ShiftedImmediate:
2503 OS << "<so_reg_imm "
2504 << RegShiftedImm.SrcReg << " "
2505 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2506 << " #" << RegShiftedImm.ShiftImm << ">";
2508 case k_RotateImmediate:
2509 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2511 case k_BitfieldDescriptor:
2512 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2513 << ", width: " << Bitfield.Width << ">";
2515 case k_RegisterList:
2516 case k_DPRRegisterList:
2517 case k_SPRRegisterList: {
2518 OS << "<register_list ";
2520 const SmallVectorImpl<unsigned> &RegList = getRegList();
2521 for (SmallVectorImpl<unsigned>::const_iterator
2522 I = RegList.begin(), E = RegList.end(); I != E; ) {
2524 if (++I < E) OS << ", ";
2531 OS << "<vector_list " << VectorList.Count << " * "
2532 << VectorList.RegNum << ">";
2534 case k_VectorListAllLanes:
2535 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2536 << VectorList.RegNum << ">";
2538 case k_VectorListIndexed:
2539 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2540 << VectorList.Count << " * " << VectorList.RegNum << ">";
2543 OS << "'" << getToken() << "'";
2546 OS << "<vectorindex " << getVectorIndex() << ">";
2551 /// @name Auto-generated Match Functions
2554 static unsigned MatchRegisterName(StringRef Name);
2558 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2559 SMLoc &StartLoc, SMLoc &EndLoc) {
2560 StartLoc = Parser.getTok().getLoc();
2561 EndLoc = Parser.getTok().getEndLoc();
2562 RegNo = tryParseRegister();
2564 return (RegNo == (unsigned)-1);
2567 /// Try to parse a register name. The token must be an Identifier when called,
2568 /// and if it is a register name the token is eaten and the register number is
2569 /// returned. Otherwise return -1.
2571 int ARMAsmParser::tryParseRegister() {
2572 const AsmToken &Tok = Parser.getTok();
2573 if (Tok.isNot(AsmToken::Identifier)) return -1;
2575 std::string lowerCase = Tok.getString().lower();
2576 unsigned RegNum = MatchRegisterName(lowerCase);
2578 RegNum = StringSwitch<unsigned>(lowerCase)
2579 .Case("r13", ARM::SP)
2580 .Case("r14", ARM::LR)
2581 .Case("r15", ARM::PC)
2582 .Case("ip", ARM::R12)
2583 // Additional register name aliases for 'gas' compatibility.
2584 .Case("a1", ARM::R0)
2585 .Case("a2", ARM::R1)
2586 .Case("a3", ARM::R2)
2587 .Case("a4", ARM::R3)
2588 .Case("v1", ARM::R4)
2589 .Case("v2", ARM::R5)
2590 .Case("v3", ARM::R6)
2591 .Case("v4", ARM::R7)
2592 .Case("v5", ARM::R8)
2593 .Case("v6", ARM::R9)
2594 .Case("v7", ARM::R10)
2595 .Case("v8", ARM::R11)
2596 .Case("sb", ARM::R9)
2597 .Case("sl", ARM::R10)
2598 .Case("fp", ARM::R11)
2602 // Check for aliases registered via .req. Canonicalize to lower case.
2603 // That's more consistent since register names are case insensitive, and
2604 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2605 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2606 // If no match, return failure.
2607 if (Entry == RegisterReqs.end())
2609 Parser.Lex(); // Eat identifier token.
2610 return Entry->getValue();
2613 Parser.Lex(); // Eat identifier token.
2618 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2619 // If a recoverable error occurs, return 1. If an irrecoverable error
2620 // occurs, return -1. An irrecoverable error is one where tokens have been
2621 // consumed in the process of trying to parse the shifter (i.e., when it is
2622 // indeed a shifter operand, but malformed).
2623 int ARMAsmParser::tryParseShiftRegister(
2624 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2625 SMLoc S = Parser.getTok().getLoc();
2626 const AsmToken &Tok = Parser.getTok();
2627 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2629 std::string lowerCase = Tok.getString().lower();
2630 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2631 .Case("asl", ARM_AM::lsl)
2632 .Case("lsl", ARM_AM::lsl)
2633 .Case("lsr", ARM_AM::lsr)
2634 .Case("asr", ARM_AM::asr)
2635 .Case("ror", ARM_AM::ror)
2636 .Case("rrx", ARM_AM::rrx)
2637 .Default(ARM_AM::no_shift);
2639 if (ShiftTy == ARM_AM::no_shift)
2642 Parser.Lex(); // Eat the operator.
2644 // The source register for the shift has already been added to the
2645 // operand list, so we need to pop it off and combine it into the shifted
2646 // register operand instead.
2647 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2648 if (!PrevOp->isReg())
2649 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2650 int SrcReg = PrevOp->getReg();
2655 if (ShiftTy == ARM_AM::rrx) {
2656 // RRX Doesn't have an explicit shift amount. The encoder expects
2657 // the shift register to be the same as the source register. Seems odd,
2661 // Figure out if this is shifted by a constant or a register (for non-RRX).
2662 if (Parser.getTok().is(AsmToken::Hash) ||
2663 Parser.getTok().is(AsmToken::Dollar)) {
2664 Parser.Lex(); // Eat hash.
2665 SMLoc ImmLoc = Parser.getTok().getLoc();
2666 const MCExpr *ShiftExpr = 0;
2667 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2668 Error(ImmLoc, "invalid immediate shift value");
2671 // The expression must be evaluatable as an immediate.
2672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2674 Error(ImmLoc, "invalid immediate shift value");
2677 // Range check the immediate.
2678 // lsl, ror: 0 <= imm <= 31
2679 // lsr, asr: 0 <= imm <= 32
2680 Imm = CE->getValue();
2682 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2683 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2684 Error(ImmLoc, "immediate shift value out of range");
2687 // shift by zero is a nop. Always send it through as lsl.
2688 // ('as' compatibility)
2690 ShiftTy = ARM_AM::lsl;
2691 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2692 SMLoc L = Parser.getTok().getLoc();
2693 EndLoc = Parser.getTok().getEndLoc();
2694 ShiftReg = tryParseRegister();
2695 if (ShiftReg == -1) {
2696 Error (L, "expected immediate or register in shift operand");
2700 Error (Parser.getTok().getLoc(),
2701 "expected immediate or register in shift operand");
2706 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2707 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2711 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2718 /// Try to parse a register name. The token must be an Identifier when called.
2719 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2720 /// if there is a "writeback". 'true' if it's not a register.
2722 /// TODO this is likely to change to allow different register types and or to
2723 /// parse for a specific register type.
2725 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2726 const AsmToken &RegTok = Parser.getTok();
2727 int RegNo = tryParseRegister();
2731 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2732 RegTok.getEndLoc()));
2734 const AsmToken &ExclaimTok = Parser.getTok();
2735 if (ExclaimTok.is(AsmToken::Exclaim)) {
2736 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2737 ExclaimTok.getLoc()));
2738 Parser.Lex(); // Eat exclaim token
2742 // Also check for an index operand. This is only legal for vector registers,
2743 // but that'll get caught OK in operand matching, so we don't need to
2744 // explicitly filter everything else out here.
2745 if (Parser.getTok().is(AsmToken::LBrac)) {
2746 SMLoc SIdx = Parser.getTok().getLoc();
2747 Parser.Lex(); // Eat left bracket token.
2749 const MCExpr *ImmVal;
2750 if (getParser().parseExpression(ImmVal))
2752 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2754 return TokError("immediate value expected for vector index");
2756 if (Parser.getTok().isNot(AsmToken::RBrac))
2757 return Error(Parser.getTok().getLoc(), "']' expected");
2759 SMLoc E = Parser.getTok().getEndLoc();
2760 Parser.Lex(); // Eat right bracket token.
2762 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2770 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2771 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2773 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2774 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2776 switch (Name.size()) {
2779 if (Name[0] != CoprocOp)
2795 if (Name[0] != CoprocOp || Name[1] != '1')
2799 case '0': return 10;
2800 case '1': return 11;
2801 case '2': return 12;
2802 case '3': return 13;
2803 case '4': return 14;
2804 case '5': return 15;
2809 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2810 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2811 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2812 SMLoc S = Parser.getTok().getLoc();
2813 const AsmToken &Tok = Parser.getTok();
2814 if (!Tok.is(AsmToken::Identifier))
2815 return MatchOperand_NoMatch;
2816 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2817 .Case("eq", ARMCC::EQ)
2818 .Case("ne", ARMCC::NE)
2819 .Case("hs", ARMCC::HS)
2820 .Case("cs", ARMCC::HS)
2821 .Case("lo", ARMCC::LO)
2822 .Case("cc", ARMCC::LO)
2823 .Case("mi", ARMCC::MI)
2824 .Case("pl", ARMCC::PL)
2825 .Case("vs", ARMCC::VS)
2826 .Case("vc", ARMCC::VC)
2827 .Case("hi", ARMCC::HI)
2828 .Case("ls", ARMCC::LS)
2829 .Case("ge", ARMCC::GE)
2830 .Case("lt", ARMCC::LT)
2831 .Case("gt", ARMCC::GT)
2832 .Case("le", ARMCC::LE)
2833 .Case("al", ARMCC::AL)
2836 return MatchOperand_NoMatch;
2837 Parser.Lex(); // Eat the token.
2839 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2841 return MatchOperand_Success;
2844 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2845 /// token must be an Identifier when called, and if it is a coprocessor
2846 /// number, the token is eaten and the operand is added to the operand list.
2847 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2848 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2849 SMLoc S = Parser.getTok().getLoc();
2850 const AsmToken &Tok = Parser.getTok();
2851 if (Tok.isNot(AsmToken::Identifier))
2852 return MatchOperand_NoMatch;
2854 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
2856 return MatchOperand_NoMatch;
2858 Parser.Lex(); // Eat identifier token.
2859 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
2860 return MatchOperand_Success;
2863 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
2864 /// token must be an Identifier when called, and if it is a coprocessor
2865 /// number, the token is eaten and the operand is added to the operand list.
2866 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2867 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2868 SMLoc S = Parser.getTok().getLoc();
2869 const AsmToken &Tok = Parser.getTok();
2870 if (Tok.isNot(AsmToken::Identifier))
2871 return MatchOperand_NoMatch;
2873 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2875 return MatchOperand_NoMatch;
2877 Parser.Lex(); // Eat identifier token.
2878 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
2879 return MatchOperand_Success;
2882 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2883 /// coproc_option : '{' imm0_255 '}'
2884 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2885 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2886 SMLoc S = Parser.getTok().getLoc();
2888 // If this isn't a '{', this isn't a coprocessor immediate operand.
2889 if (Parser.getTok().isNot(AsmToken::LCurly))
2890 return MatchOperand_NoMatch;
2891 Parser.Lex(); // Eat the '{'
2894 SMLoc Loc = Parser.getTok().getLoc();
2895 if (getParser().parseExpression(Expr)) {
2896 Error(Loc, "illegal expression");
2897 return MatchOperand_ParseFail;
2899 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2900 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2901 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2902 return MatchOperand_ParseFail;
2904 int Val = CE->getValue();
2906 // Check for and consume the closing '}'
2907 if (Parser.getTok().isNot(AsmToken::RCurly))
2908 return MatchOperand_ParseFail;
2909 SMLoc E = Parser.getTok().getEndLoc();
2910 Parser.Lex(); // Eat the '}'
2912 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2913 return MatchOperand_Success;
2916 // For register list parsing, we need to map from raw GPR register numbering
2917 // to the enumeration values. The enumeration values aren't sorted by
2918 // register number due to our using "sp", "lr" and "pc" as canonical names.
2919 static unsigned getNextRegister(unsigned Reg) {
2920 // If this is a GPR, we need to do it manually, otherwise we can rely
2921 // on the sort ordering of the enumeration since the other reg-classes
2923 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2926 default: llvm_unreachable("Invalid GPR number!");
2927 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2928 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2929 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2930 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2931 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2932 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2933 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2934 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2938 // Return the low-subreg of a given Q register.
2939 static unsigned getDRegFromQReg(unsigned QReg) {
2941 default: llvm_unreachable("expected a Q register!");
2942 case ARM::Q0: return ARM::D0;
2943 case ARM::Q1: return ARM::D2;
2944 case ARM::Q2: return ARM::D4;
2945 case ARM::Q3: return ARM::D6;
2946 case ARM::Q4: return ARM::D8;
2947 case ARM::Q5: return ARM::D10;
2948 case ARM::Q6: return ARM::D12;
2949 case ARM::Q7: return ARM::D14;
2950 case ARM::Q8: return ARM::D16;
2951 case ARM::Q9: return ARM::D18;
2952 case ARM::Q10: return ARM::D20;
2953 case ARM::Q11: return ARM::D22;
2954 case ARM::Q12: return ARM::D24;
2955 case ARM::Q13: return ARM::D26;
2956 case ARM::Q14: return ARM::D28;
2957 case ARM::Q15: return ARM::D30;
2961 /// Parse a register list.
2963 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2964 assert(Parser.getTok().is(AsmToken::LCurly) &&
2965 "Token is not a Left Curly Brace");
2966 SMLoc S = Parser.getTok().getLoc();
2967 Parser.Lex(); // Eat '{' token.
2968 SMLoc RegLoc = Parser.getTok().getLoc();
2970 // Check the first register in the list to see what register class
2971 // this is a list of.
2972 int Reg = tryParseRegister();
2974 return Error(RegLoc, "register expected");
2976 // The reglist instructions have at most 16 registers, so reserve
2977 // space for that many.
2978 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2980 // Allow Q regs and just interpret them as the two D sub-registers.
2981 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2982 Reg = getDRegFromQReg(Reg);
2983 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2986 const MCRegisterClass *RC;
2987 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2988 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2989 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2990 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2991 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2992 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2994 return Error(RegLoc, "invalid register in register list");
2996 // Store the register.
2997 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2999 // This starts immediately after the first register token in the list,
3000 // so we can see either a comma or a minus (range separator) as a legal
3002 while (Parser.getTok().is(AsmToken::Comma) ||
3003 Parser.getTok().is(AsmToken::Minus)) {
3004 if (Parser.getTok().is(AsmToken::Minus)) {
3005 Parser.Lex(); // Eat the minus.
3006 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3007 int EndReg = tryParseRegister();
3009 return Error(AfterMinusLoc, "register expected");
3010 // Allow Q regs and just interpret them as the two D sub-registers.
3011 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3012 EndReg = getDRegFromQReg(EndReg) + 1;
3013 // If the register is the same as the start reg, there's nothing
3017 // The register must be in the same register class as the first.
3018 if (!RC->contains(EndReg))
3019 return Error(AfterMinusLoc, "invalid register in register list");
3020 // Ranges must go from low to high.
3021 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3022 return Error(AfterMinusLoc, "bad range in register list");
3024 // Add all the registers in the range to the register list.
3025 while (Reg != EndReg) {
3026 Reg = getNextRegister(Reg);
3027 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
3031 Parser.Lex(); // Eat the comma.
3032 RegLoc = Parser.getTok().getLoc();
3034 const AsmToken RegTok = Parser.getTok();
3035 Reg = tryParseRegister();
3037 return Error(RegLoc, "register expected");
3038 // Allow Q regs and just interpret them as the two D sub-registers.
3039 bool isQReg = false;
3040 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3041 Reg = getDRegFromQReg(Reg);
3044 // The register must be in the same register class as the first.
3045 if (!RC->contains(Reg))
3046 return Error(RegLoc, "invalid register in register list");
3047 // List must be monotonically increasing.
3048 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3049 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3050 Warning(RegLoc, "register list not in ascending order");
3052 return Error(RegLoc, "register list not in ascending order");
3054 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3055 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3056 ") in register list");
3059 // VFP register lists must also be contiguous.
3060 // It's OK to use the enumeration values directly here rather, as the
3061 // VFP register classes have the enum sorted properly.
3062 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3064 return Error(RegLoc, "non-contiguous register range");
3065 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
3067 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
3070 if (Parser.getTok().isNot(AsmToken::RCurly))
3071 return Error(Parser.getTok().getLoc(), "'}' expected");
3072 SMLoc E = Parser.getTok().getEndLoc();
3073 Parser.Lex(); // Eat '}' token.
3075 // Push the register list operand.
3076 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3078 // The ARM system instruction variants for LDM/STM have a '^' token here.
3079 if (Parser.getTok().is(AsmToken::Caret)) {
3080 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3081 Parser.Lex(); // Eat '^' token.
3087 // Helper function to parse the lane index for vector lists.
3088 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3089 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3090 Index = 0; // Always return a defined index value.
3091 if (Parser.getTok().is(AsmToken::LBrac)) {
3092 Parser.Lex(); // Eat the '['.
3093 if (Parser.getTok().is(AsmToken::RBrac)) {
3094 // "Dn[]" is the 'all lanes' syntax.
3095 LaneKind = AllLanes;
3096 EndLoc = Parser.getTok().getEndLoc();
3097 Parser.Lex(); // Eat the ']'.
3098 return MatchOperand_Success;
3101 // There's an optional '#' token here. Normally there wouldn't be, but
3102 // inline assemble puts one in, and it's friendly to accept that.
3103 if (Parser.getTok().is(AsmToken::Hash))
3104 Parser.Lex(); // Eat '#' or '$'.
3106 const MCExpr *LaneIndex;
3107 SMLoc Loc = Parser.getTok().getLoc();
3108 if (getParser().parseExpression(LaneIndex)) {
3109 Error(Loc, "illegal expression");
3110 return MatchOperand_ParseFail;
3112 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3114 Error(Loc, "lane index must be empty or an integer");
3115 return MatchOperand_ParseFail;
3117 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3118 Error(Parser.getTok().getLoc(), "']' expected");
3119 return MatchOperand_ParseFail;
3121 EndLoc = Parser.getTok().getEndLoc();
3122 Parser.Lex(); // Eat the ']'.
3123 int64_t Val = CE->getValue();
3125 // FIXME: Make this range check context sensitive for .8, .16, .32.
3126 if (Val < 0 || Val > 7) {
3127 Error(Parser.getTok().getLoc(), "lane index out of range");
3128 return MatchOperand_ParseFail;
3131 LaneKind = IndexedLane;
3132 return MatchOperand_Success;
3135 return MatchOperand_Success;
3138 // parse a vector register list
3139 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3140 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3141 VectorLaneTy LaneKind;
3143 SMLoc S = Parser.getTok().getLoc();
3144 // As an extension (to match gas), support a plain D register or Q register
3145 // (without encosing curly braces) as a single or double entry list,
3147 if (Parser.getTok().is(AsmToken::Identifier)) {
3148 SMLoc E = Parser.getTok().getEndLoc();
3149 int Reg = tryParseRegister();
3151 return MatchOperand_NoMatch;
3152 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3153 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3154 if (Res != MatchOperand_Success)
3158 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3161 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3165 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3170 return MatchOperand_Success;
3172 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3173 Reg = getDRegFromQReg(Reg);
3174 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3175 if (Res != MatchOperand_Success)
3179 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3180 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3181 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3184 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3185 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3186 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3190 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3195 return MatchOperand_Success;
3197 Error(S, "vector register expected");
3198 return MatchOperand_ParseFail;
3201 if (Parser.getTok().isNot(AsmToken::LCurly))
3202 return MatchOperand_NoMatch;
3204 Parser.Lex(); // Eat '{' token.
3205 SMLoc RegLoc = Parser.getTok().getLoc();
3207 int Reg = tryParseRegister();
3209 Error(RegLoc, "register expected");
3210 return MatchOperand_ParseFail;
3214 unsigned FirstReg = Reg;
3215 // The list is of D registers, but we also allow Q regs and just interpret
3216 // them as the two D sub-registers.
3217 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3218 FirstReg = Reg = getDRegFromQReg(Reg);
3219 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3220 // it's ambiguous with four-register single spaced.
3226 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3227 return MatchOperand_ParseFail;
3229 while (Parser.getTok().is(AsmToken::Comma) ||
3230 Parser.getTok().is(AsmToken::Minus)) {
3231 if (Parser.getTok().is(AsmToken::Minus)) {
3233 Spacing = 1; // Register range implies a single spaced list.
3234 else if (Spacing == 2) {
3235 Error(Parser.getTok().getLoc(),
3236 "sequential registers in double spaced list");
3237 return MatchOperand_ParseFail;
3239 Parser.Lex(); // Eat the minus.
3240 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3241 int EndReg = tryParseRegister();
3243 Error(AfterMinusLoc, "register expected");
3244 return MatchOperand_ParseFail;
3246 // Allow Q regs and just interpret them as the two D sub-registers.
3247 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3248 EndReg = getDRegFromQReg(EndReg) + 1;
3249 // If the register is the same as the start reg, there's nothing
3253 // The register must be in the same register class as the first.
3254 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3255 Error(AfterMinusLoc, "invalid register in register list");
3256 return MatchOperand_ParseFail;
3258 // Ranges must go from low to high.
3260 Error(AfterMinusLoc, "bad range in register list");
3261 return MatchOperand_ParseFail;
3263 // Parse the lane specifier if present.
3264 VectorLaneTy NextLaneKind;
3265 unsigned NextLaneIndex;
3266 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3267 MatchOperand_Success)
3268 return MatchOperand_ParseFail;
3269 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3270 Error(AfterMinusLoc, "mismatched lane index in register list");
3271 return MatchOperand_ParseFail;
3274 // Add all the registers in the range to the register list.
3275 Count += EndReg - Reg;
3279 Parser.Lex(); // Eat the comma.
3280 RegLoc = Parser.getTok().getLoc();
3282 Reg = tryParseRegister();
3284 Error(RegLoc, "register expected");
3285 return MatchOperand_ParseFail;
3287 // vector register lists must be contiguous.
3288 // It's OK to use the enumeration values directly here rather, as the
3289 // VFP register classes have the enum sorted properly.
3291 // The list is of D registers, but we also allow Q regs and just interpret
3292 // them as the two D sub-registers.
3293 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3295 Spacing = 1; // Register range implies a single spaced list.
3296 else if (Spacing == 2) {
3298 "invalid register in double-spaced list (must be 'D' register')");
3299 return MatchOperand_ParseFail;
3301 Reg = getDRegFromQReg(Reg);
3302 if (Reg != OldReg + 1) {
3303 Error(RegLoc, "non-contiguous register range");
3304 return MatchOperand_ParseFail;
3308 // Parse the lane specifier if present.
3309 VectorLaneTy NextLaneKind;
3310 unsigned NextLaneIndex;
3311 SMLoc LaneLoc = Parser.getTok().getLoc();
3312 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3313 MatchOperand_Success)
3314 return MatchOperand_ParseFail;
3315 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3316 Error(LaneLoc, "mismatched lane index in register list");
3317 return MatchOperand_ParseFail;
3321 // Normal D register.
3322 // Figure out the register spacing (single or double) of the list if
3323 // we don't know it already.
3325 Spacing = 1 + (Reg == OldReg + 2);
3327 // Just check that it's contiguous and keep going.
3328 if (Reg != OldReg + Spacing) {
3329 Error(RegLoc, "non-contiguous register range");
3330 return MatchOperand_ParseFail;
3333 // Parse the lane specifier if present.
3334 VectorLaneTy NextLaneKind;
3335 unsigned NextLaneIndex;
3336 SMLoc EndLoc = Parser.getTok().getLoc();
3337 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3338 return MatchOperand_ParseFail;
3339 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3340 Error(EndLoc, "mismatched lane index in register list");
3341 return MatchOperand_ParseFail;
3345 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3346 Error(Parser.getTok().getLoc(), "'}' expected");
3347 return MatchOperand_ParseFail;
3349 E = Parser.getTok().getEndLoc();
3350 Parser.Lex(); // Eat '}' token.
3354 // Two-register operands have been converted to the
3355 // composite register classes.
3357 const MCRegisterClass *RC = (Spacing == 1) ?
3358 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3359 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3360 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3363 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3364 (Spacing == 2), S, E));
3367 // Two-register operands have been converted to the
3368 // composite register classes.
3370 const MCRegisterClass *RC = (Spacing == 1) ?
3371 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3372 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3373 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3375 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3380 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3386 return MatchOperand_Success;
3389 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3390 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3391 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3392 SMLoc S = Parser.getTok().getLoc();
3393 const AsmToken &Tok = Parser.getTok();
3396 if (Tok.is(AsmToken::Identifier)) {
3397 StringRef OptStr = Tok.getString();
3399 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3400 .Case("sy", ARM_MB::SY)
3401 .Case("st", ARM_MB::ST)
3402 .Case("sh", ARM_MB::ISH)
3403 .Case("ish", ARM_MB::ISH)
3404 .Case("shst", ARM_MB::ISHST)
3405 .Case("ishst", ARM_MB::ISHST)
3406 .Case("nsh", ARM_MB::NSH)
3407 .Case("un", ARM_MB::NSH)
3408 .Case("nshst", ARM_MB::NSHST)
3409 .Case("unst", ARM_MB::NSHST)
3410 .Case("osh", ARM_MB::OSH)
3411 .Case("oshst", ARM_MB::OSHST)
3415 return MatchOperand_NoMatch;
3417 Parser.Lex(); // Eat identifier token.
3418 } else if (Tok.is(AsmToken::Hash) ||
3419 Tok.is(AsmToken::Dollar) ||
3420 Tok.is(AsmToken::Integer)) {
3421 if (Parser.getTok().isNot(AsmToken::Integer))
3422 Parser.Lex(); // Eat '#' or '$'.
3423 SMLoc Loc = Parser.getTok().getLoc();
3425 const MCExpr *MemBarrierID;
3426 if (getParser().parseExpression(MemBarrierID)) {
3427 Error(Loc, "illegal expression");
3428 return MatchOperand_ParseFail;
3431 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3433 Error(Loc, "constant expression expected");
3434 return MatchOperand_ParseFail;
3437 int Val = CE->getValue();
3439 Error(Loc, "immediate value out of range");
3440 return MatchOperand_ParseFail;
3443 Opt = ARM_MB::RESERVED_0 + Val;
3445 return MatchOperand_ParseFail;
3447 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3448 return MatchOperand_Success;
3451 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3452 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3453 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3454 SMLoc S = Parser.getTok().getLoc();
3455 const AsmToken &Tok = Parser.getTok();
3458 if (Tok.is(AsmToken::Identifier)) {
3459 StringRef OptStr = Tok.getString();
3461 if (OptStr.lower() == "sy")
3464 return MatchOperand_NoMatch;
3466 Parser.Lex(); // Eat identifier token.
3467 } else if (Tok.is(AsmToken::Hash) ||
3468 Tok.is(AsmToken::Dollar) ||
3469 Tok.is(AsmToken::Integer)) {
3470 if (Parser.getTok().isNot(AsmToken::Integer))
3471 Parser.Lex(); // Eat '#' or '$'.
3472 SMLoc Loc = Parser.getTok().getLoc();
3474 const MCExpr *ISBarrierID;
3475 if (getParser().parseExpression(ISBarrierID)) {
3476 Error(Loc, "illegal expression");
3477 return MatchOperand_ParseFail;
3480 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3482 Error(Loc, "constant expression expected");
3483 return MatchOperand_ParseFail;
3486 int Val = CE->getValue();
3488 Error(Loc, "immediate value out of range");
3489 return MatchOperand_ParseFail;
3492 Opt = ARM_ISB::RESERVED_0 + Val;
3494 return MatchOperand_ParseFail;
3496 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3497 (ARM_ISB::InstSyncBOpt)Opt, S));
3498 return MatchOperand_Success;
3502 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3503 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3504 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3505 SMLoc S = Parser.getTok().getLoc();
3506 const AsmToken &Tok = Parser.getTok();
3507 if (!Tok.is(AsmToken::Identifier))
3508 return MatchOperand_NoMatch;
3509 StringRef IFlagsStr = Tok.getString();
3511 // An iflags string of "none" is interpreted to mean that none of the AIF
3512 // bits are set. Not a terribly useful instruction, but a valid encoding.
3513 unsigned IFlags = 0;
3514 if (IFlagsStr != "none") {
3515 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3516 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3517 .Case("a", ARM_PROC::A)
3518 .Case("i", ARM_PROC::I)
3519 .Case("f", ARM_PROC::F)
3522 // If some specific iflag is already set, it means that some letter is
3523 // present more than once, this is not acceptable.
3524 if (Flag == ~0U || (IFlags & Flag))
3525 return MatchOperand_NoMatch;
3531 Parser.Lex(); // Eat identifier token.
3532 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3533 return MatchOperand_Success;
3536 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3537 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3538 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3539 SMLoc S = Parser.getTok().getLoc();
3540 const AsmToken &Tok = Parser.getTok();
3541 if (!Tok.is(AsmToken::Identifier))
3542 return MatchOperand_NoMatch;
3543 StringRef Mask = Tok.getString();
3546 // See ARMv6-M 10.1.1
3547 std::string Name = Mask.lower();
3548 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3549 // Note: in the documentation:
3550 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3551 // for MSR APSR_nzcvq.
3552 // but we do make it an alias here. This is so to get the "mask encoding"
3553 // bits correct on MSR APSR writes.
3555 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3556 // should really only be allowed when writing a special register. Note
3557 // they get dropped in the MRS instruction reading a special register as
3558 // the SYSm field is only 8 bits.
3560 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3561 // includes the DSP extension but that is not checked.
3562 .Case("apsr", 0x800)
3563 .Case("apsr_nzcvq", 0x800)
3564 .Case("apsr_g", 0x400)
3565 .Case("apsr_nzcvqg", 0xc00)
3566 .Case("iapsr", 0x801)
3567 .Case("iapsr_nzcvq", 0x801)
3568 .Case("iapsr_g", 0x401)
3569 .Case("iapsr_nzcvqg", 0xc01)
3570 .Case("eapsr", 0x802)
3571 .Case("eapsr_nzcvq", 0x802)
3572 .Case("eapsr_g", 0x402)
3573 .Case("eapsr_nzcvqg", 0xc02)
3574 .Case("xpsr", 0x803)
3575 .Case("xpsr_nzcvq", 0x803)
3576 .Case("xpsr_g", 0x403)
3577 .Case("xpsr_nzcvqg", 0xc03)
3578 .Case("ipsr", 0x805)
3579 .Case("epsr", 0x806)
3580 .Case("iepsr", 0x807)
3583 .Case("primask", 0x810)
3584 .Case("basepri", 0x811)
3585 .Case("basepri_max", 0x812)
3586 .Case("faultmask", 0x813)
3587 .Case("control", 0x814)
3590 if (FlagsVal == ~0U)
3591 return MatchOperand_NoMatch;
3593 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3594 // basepri, basepri_max and faultmask only valid for V7m.
3595 return MatchOperand_NoMatch;
3597 Parser.Lex(); // Eat identifier token.
3598 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3599 return MatchOperand_Success;
3602 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3603 size_t Start = 0, Next = Mask.find('_');
3604 StringRef Flags = "";
3605 std::string SpecReg = Mask.slice(Start, Next).lower();
3606 if (Next != StringRef::npos)
3607 Flags = Mask.slice(Next+1, Mask.size());
3609 // FlagsVal contains the complete mask:
3611 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3612 unsigned FlagsVal = 0;
3614 if (SpecReg == "apsr") {
3615 FlagsVal = StringSwitch<unsigned>(Flags)
3616 .Case("nzcvq", 0x8) // same as CPSR_f
3617 .Case("g", 0x4) // same as CPSR_s
3618 .Case("nzcvqg", 0xc) // same as CPSR_fs
3621 if (FlagsVal == ~0U) {
3623 return MatchOperand_NoMatch;
3625 FlagsVal = 8; // No flag
3627 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3628 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3629 if (Flags == "all" || Flags == "")
3631 for (int i = 0, e = Flags.size(); i != e; ++i) {
3632 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3639 // If some specific flag is already set, it means that some letter is
3640 // present more than once, this is not acceptable.
3641 if (FlagsVal == ~0U || (FlagsVal & Flag))
3642 return MatchOperand_NoMatch;
3645 } else // No match for special register.
3646 return MatchOperand_NoMatch;
3648 // Special register without flags is NOT equivalent to "fc" flags.
3649 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3650 // two lines would enable gas compatibility at the expense of breaking
3656 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3657 if (SpecReg == "spsr")
3660 Parser.Lex(); // Eat identifier token.
3661 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3662 return MatchOperand_Success;
3665 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3666 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3667 int Low, int High) {
3668 const AsmToken &Tok = Parser.getTok();
3669 if (Tok.isNot(AsmToken::Identifier)) {
3670 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3671 return MatchOperand_ParseFail;
3673 StringRef ShiftName = Tok.getString();
3674 std::string LowerOp = Op.lower();
3675 std::string UpperOp = Op.upper();
3676 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3677 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3678 return MatchOperand_ParseFail;
3680 Parser.Lex(); // Eat shift type token.
3682 // There must be a '#' and a shift amount.
3683 if (Parser.getTok().isNot(AsmToken::Hash) &&
3684 Parser.getTok().isNot(AsmToken::Dollar)) {
3685 Error(Parser.getTok().getLoc(), "'#' expected");
3686 return MatchOperand_ParseFail;
3688 Parser.Lex(); // Eat hash token.
3690 const MCExpr *ShiftAmount;
3691 SMLoc Loc = Parser.getTok().getLoc();
3693 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3694 Error(Loc, "illegal expression");
3695 return MatchOperand_ParseFail;
3697 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3699 Error(Loc, "constant expression expected");
3700 return MatchOperand_ParseFail;
3702 int Val = CE->getValue();
3703 if (Val < Low || Val > High) {
3704 Error(Loc, "immediate value out of range");
3705 return MatchOperand_ParseFail;
3708 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3710 return MatchOperand_Success;
3713 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3714 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3715 const AsmToken &Tok = Parser.getTok();
3716 SMLoc S = Tok.getLoc();
3717 if (Tok.isNot(AsmToken::Identifier)) {
3718 Error(S, "'be' or 'le' operand expected");
3719 return MatchOperand_ParseFail;
3721 int Val = StringSwitch<int>(Tok.getString().lower())
3725 Parser.Lex(); // Eat the token.
3728 Error(S, "'be' or 'le' operand expected");
3729 return MatchOperand_ParseFail;
3731 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3733 S, Tok.getEndLoc()));
3734 return MatchOperand_Success;
3737 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3738 /// instructions. Legal values are:
3739 /// lsl #n 'n' in [0,31]
3740 /// asr #n 'n' in [1,32]
3741 /// n == 32 encoded as n == 0.
3742 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3743 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3744 const AsmToken &Tok = Parser.getTok();
3745 SMLoc S = Tok.getLoc();
3746 if (Tok.isNot(AsmToken::Identifier)) {
3747 Error(S, "shift operator 'asr' or 'lsl' expected");
3748 return MatchOperand_ParseFail;
3750 StringRef ShiftName = Tok.getString();
3752 if (ShiftName == "lsl" || ShiftName == "LSL")
3754 else if (ShiftName == "asr" || ShiftName == "ASR")
3757 Error(S, "shift operator 'asr' or 'lsl' expected");
3758 return MatchOperand_ParseFail;
3760 Parser.Lex(); // Eat the operator.
3762 // A '#' and a shift amount.
3763 if (Parser.getTok().isNot(AsmToken::Hash) &&
3764 Parser.getTok().isNot(AsmToken::Dollar)) {
3765 Error(Parser.getTok().getLoc(), "'#' expected");
3766 return MatchOperand_ParseFail;
3768 Parser.Lex(); // Eat hash token.
3769 SMLoc ExLoc = Parser.getTok().getLoc();
3771 const MCExpr *ShiftAmount;
3773 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3774 Error(ExLoc, "malformed shift expression");
3775 return MatchOperand_ParseFail;
3777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3779 Error(ExLoc, "shift amount must be an immediate");
3780 return MatchOperand_ParseFail;
3783 int64_t Val = CE->getValue();
3785 // Shift amount must be in [1,32]
3786 if (Val < 1 || Val > 32) {
3787 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3788 return MatchOperand_ParseFail;
3790 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3791 if (isThumb() && Val == 32) {
3792 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3793 return MatchOperand_ParseFail;
3795 if (Val == 32) Val = 0;
3797 // Shift amount must be in [1,32]
3798 if (Val < 0 || Val > 31) {
3799 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3800 return MatchOperand_ParseFail;
3804 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3806 return MatchOperand_Success;
3809 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3810 /// of instructions. Legal values are:
3811 /// ror #n 'n' in {0, 8, 16, 24}
3812 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3813 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3814 const AsmToken &Tok = Parser.getTok();
3815 SMLoc S = Tok.getLoc();
3816 if (Tok.isNot(AsmToken::Identifier))
3817 return MatchOperand_NoMatch;
3818 StringRef ShiftName = Tok.getString();
3819 if (ShiftName != "ror" && ShiftName != "ROR")
3820 return MatchOperand_NoMatch;
3821 Parser.Lex(); // Eat the operator.
3823 // A '#' and a rotate amount.
3824 if (Parser.getTok().isNot(AsmToken::Hash) &&
3825 Parser.getTok().isNot(AsmToken::Dollar)) {
3826 Error(Parser.getTok().getLoc(), "'#' expected");
3827 return MatchOperand_ParseFail;
3829 Parser.Lex(); // Eat hash token.
3830 SMLoc ExLoc = Parser.getTok().getLoc();
3832 const MCExpr *ShiftAmount;
3834 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3835 Error(ExLoc, "malformed rotate expression");
3836 return MatchOperand_ParseFail;
3838 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3840 Error(ExLoc, "rotate amount must be an immediate");
3841 return MatchOperand_ParseFail;
3844 int64_t Val = CE->getValue();
3845 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3846 // normally, zero is represented in asm by omitting the rotate operand
3848 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3849 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
3850 return MatchOperand_ParseFail;
3853 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
3855 return MatchOperand_Success;
3858 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3859 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3860 SMLoc S = Parser.getTok().getLoc();
3861 // The bitfield descriptor is really two operands, the LSB and the width.
3862 if (Parser.getTok().isNot(AsmToken::Hash) &&
3863 Parser.getTok().isNot(AsmToken::Dollar)) {
3864 Error(Parser.getTok().getLoc(), "'#' expected");
3865 return MatchOperand_ParseFail;
3867 Parser.Lex(); // Eat hash token.
3869 const MCExpr *LSBExpr;
3870 SMLoc E = Parser.getTok().getLoc();
3871 if (getParser().parseExpression(LSBExpr)) {
3872 Error(E, "malformed immediate expression");
3873 return MatchOperand_ParseFail;
3875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3877 Error(E, "'lsb' operand must be an immediate");
3878 return MatchOperand_ParseFail;
3881 int64_t LSB = CE->getValue();
3882 // The LSB must be in the range [0,31]
3883 if (LSB < 0 || LSB > 31) {
3884 Error(E, "'lsb' operand must be in the range [0,31]");
3885 return MatchOperand_ParseFail;
3887 E = Parser.getTok().getLoc();
3889 // Expect another immediate operand.
3890 if (Parser.getTok().isNot(AsmToken::Comma)) {
3891 Error(Parser.getTok().getLoc(), "too few operands");
3892 return MatchOperand_ParseFail;
3894 Parser.Lex(); // Eat hash token.
3895 if (Parser.getTok().isNot(AsmToken::Hash) &&
3896 Parser.getTok().isNot(AsmToken::Dollar)) {
3897 Error(Parser.getTok().getLoc(), "'#' expected");
3898 return MatchOperand_ParseFail;
3900 Parser.Lex(); // Eat hash token.
3902 const MCExpr *WidthExpr;
3904 if (getParser().parseExpression(WidthExpr, EndLoc)) {
3905 Error(E, "malformed immediate expression");
3906 return MatchOperand_ParseFail;
3908 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3910 Error(E, "'width' operand must be an immediate");
3911 return MatchOperand_ParseFail;
3914 int64_t Width = CE->getValue();
3915 // The LSB must be in the range [1,32-lsb]
3916 if (Width < 1 || Width > 32 - LSB) {
3917 Error(E, "'width' operand must be in the range [1,32-lsb]");
3918 return MatchOperand_ParseFail;
3921 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
3923 return MatchOperand_Success;
3926 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3927 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3928 // Check for a post-index addressing register operand. Specifically:
3929 // postidx_reg := '+' register {, shift}
3930 // | '-' register {, shift}
3931 // | register {, shift}
3933 // This method must return MatchOperand_NoMatch without consuming any tokens
3934 // in the case where there is no match, as other alternatives take other
3936 AsmToken Tok = Parser.getTok();
3937 SMLoc S = Tok.getLoc();
3938 bool haveEaten = false;
3940 if (Tok.is(AsmToken::Plus)) {
3941 Parser.Lex(); // Eat the '+' token.
3943 } else if (Tok.is(AsmToken::Minus)) {
3944 Parser.Lex(); // Eat the '-' token.
3949 SMLoc E = Parser.getTok().getEndLoc();
3950 int Reg = tryParseRegister();
3953 return MatchOperand_NoMatch;
3954 Error(Parser.getTok().getLoc(), "register expected");
3955 return MatchOperand_ParseFail;
3958 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3959 unsigned ShiftImm = 0;
3960 if (Parser.getTok().is(AsmToken::Comma)) {
3961 Parser.Lex(); // Eat the ','.
3962 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3963 return MatchOperand_ParseFail;
3965 // FIXME: Only approximates end...may include intervening whitespace.
3966 E = Parser.getTok().getLoc();
3969 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3972 return MatchOperand_Success;
3975 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3976 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3977 // Check for a post-index addressing register operand. Specifically:
3978 // am3offset := '+' register
3985 // This method must return MatchOperand_NoMatch without consuming any tokens
3986 // in the case where there is no match, as other alternatives take other
3988 AsmToken Tok = Parser.getTok();
3989 SMLoc S = Tok.getLoc();
3991 // Do immediates first, as we always parse those if we have a '#'.
3992 if (Parser.getTok().is(AsmToken::Hash) ||
3993 Parser.getTok().is(AsmToken::Dollar)) {
3994 Parser.Lex(); // Eat '#' or '$'.
3995 // Explicitly look for a '-', as we need to encode negative zero
3997 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3998 const MCExpr *Offset;
4000 if (getParser().parseExpression(Offset, E))
4001 return MatchOperand_ParseFail;
4002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4004 Error(S, "constant expression expected");
4005 return MatchOperand_ParseFail;
4007 // Negative zero is encoded as the flag value INT32_MIN.
4008 int32_t Val = CE->getValue();
4009 if (isNegative && Val == 0)
4013 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4015 return MatchOperand_Success;
4019 bool haveEaten = false;
4021 if (Tok.is(AsmToken::Plus)) {
4022 Parser.Lex(); // Eat the '+' token.
4024 } else if (Tok.is(AsmToken::Minus)) {
4025 Parser.Lex(); // Eat the '-' token.
4030 Tok = Parser.getTok();
4031 int Reg = tryParseRegister();
4034 return MatchOperand_NoMatch;
4035 Error(Tok.getLoc(), "register expected");
4036 return MatchOperand_ParseFail;
4039 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4040 0, S, Tok.getEndLoc()));
4042 return MatchOperand_Success;
4045 /// cvtT2LdrdPre - Convert parsed operands to MCInst.
4046 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4047 /// when they refer multiple MIOperands inside a single one.
4049 cvtT2LdrdPre(MCInst &Inst,
4050 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4052 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4053 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4054 // Create a writeback register dummy placeholder.
4055 Inst.addOperand(MCOperand::CreateReg(0));
4057 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4059 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4062 /// cvtT2StrdPre - Convert parsed operands to MCInst.
4063 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4064 /// when they refer multiple MIOperands inside a single one.
4066 cvtT2StrdPre(MCInst &Inst,
4067 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4068 // Create a writeback register dummy placeholder.
4069 Inst.addOperand(MCOperand::CreateReg(0));
4071 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4072 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4074 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
4076 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4079 /// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4080 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4081 /// when they refer multiple MIOperands inside a single one.
4083 cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
4084 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4085 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4087 // Create a writeback register dummy placeholder.
4088 Inst.addOperand(MCOperand::CreateImm(0));
4090 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4091 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4094 /// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
4095 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4096 /// when they refer multiple MIOperands inside a single one.
4098 cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
4099 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4100 // Create a writeback register dummy placeholder.
4101 Inst.addOperand(MCOperand::CreateImm(0));
4102 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4103 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
4104 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4107 /// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
4108 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4109 /// when they refer multiple MIOperands inside a single one.
4111 cvtLdWriteBackRegAddrMode2(MCInst &Inst,
4112 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4113 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4115 // Create a writeback register dummy placeholder.
4116 Inst.addOperand(MCOperand::CreateImm(0));
4118 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4119 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4122 /// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4123 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4124 /// when they refer multiple MIOperands inside a single one.
4126 cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
4127 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4128 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4130 // Create a writeback register dummy placeholder.
4131 Inst.addOperand(MCOperand::CreateImm(0));
4133 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4134 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4138 /// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
4139 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4140 /// when they refer multiple MIOperands inside a single one.
4142 cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
4143 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4144 // Create a writeback register dummy placeholder.
4145 Inst.addOperand(MCOperand::CreateImm(0));
4146 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4147 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
4148 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4151 /// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
4152 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4153 /// when they refer multiple MIOperands inside a single one.
4155 cvtStWriteBackRegAddrMode2(MCInst &Inst,
4156 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4157 // Create a writeback register dummy placeholder.
4158 Inst.addOperand(MCOperand::CreateImm(0));
4159 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4160 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4161 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4164 /// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4165 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4166 /// when they refer multiple MIOperands inside a single one.
4168 cvtStWriteBackRegAddrMode3(MCInst &Inst,
4169 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4170 // Create a writeback register dummy placeholder.
4171 Inst.addOperand(MCOperand::CreateImm(0));
4172 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4173 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4174 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4177 /// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4178 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4179 /// when they refer multiple MIOperands inside a single one.
4181 cvtLdExtTWriteBackImm(MCInst &Inst,
4182 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4184 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4185 // Create a writeback register dummy placeholder.
4186 Inst.addOperand(MCOperand::CreateImm(0));
4188 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4190 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4192 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4195 /// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
4196 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4197 /// when they refer multiple MIOperands inside a single one.
4199 cvtLdExtTWriteBackReg(MCInst &Inst,
4200 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4202 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4203 // Create a writeback register dummy placeholder.
4204 Inst.addOperand(MCOperand::CreateImm(0));
4206 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4208 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4210 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4213 /// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
4214 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4215 /// when they refer multiple MIOperands inside a single one.
4217 cvtStExtTWriteBackImm(MCInst &Inst,
4218 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4219 // Create a writeback register dummy placeholder.
4220 Inst.addOperand(MCOperand::CreateImm(0));
4222 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4224 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4226 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4228 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4231 /// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4232 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4233 /// when they refer multiple MIOperands inside a single one.
4235 cvtStExtTWriteBackReg(MCInst &Inst,
4236 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4237 // Create a writeback register dummy placeholder.
4238 Inst.addOperand(MCOperand::CreateImm(0));
4240 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4242 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4244 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4246 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4249 /// cvtLdrdPre - Convert parsed operands to MCInst.
4250 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4251 /// when they refer multiple MIOperands inside a single one.
4253 cvtLdrdPre(MCInst &Inst,
4254 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4256 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4257 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4258 // Create a writeback register dummy placeholder.
4259 Inst.addOperand(MCOperand::CreateImm(0));
4261 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4263 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4266 /// cvtStrdPre - Convert parsed operands to MCInst.
4267 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4268 /// when they refer multiple MIOperands inside a single one.
4270 cvtStrdPre(MCInst &Inst,
4271 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4272 // Create a writeback register dummy placeholder.
4273 Inst.addOperand(MCOperand::CreateImm(0));
4275 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4276 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4278 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4280 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4283 /// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4284 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4285 /// when they refer multiple MIOperands inside a single one.
4287 cvtLdWriteBackRegAddrMode3(MCInst &Inst,
4288 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4289 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4290 // Create a writeback register dummy placeholder.
4291 Inst.addOperand(MCOperand::CreateImm(0));
4292 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4293 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4296 /// cvtThumbMultiply - Convert parsed operands to MCInst.
4297 /// Needed here because the Asm Gen Matcher can't handle properly tied operands
4298 /// when they refer multiple MIOperands inside a single one.
4300 cvtThumbMultiply(MCInst &Inst,
4301 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4302 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4303 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4304 // If we have a three-operand form, make sure to set Rn to be the operand
4305 // that isn't the same as Rd.
4307 if (Operands.size() == 6 &&
4308 ((ARMOperand*)Operands[4])->getReg() ==
4309 ((ARMOperand*)Operands[3])->getReg())
4311 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4312 Inst.addOperand(Inst.getOperand(0));
4313 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4317 cvtVLDwbFixed(MCInst &Inst,
4318 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4320 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4321 // Create a writeback register dummy placeholder.
4322 Inst.addOperand(MCOperand::CreateImm(0));
4324 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4326 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4330 cvtVLDwbRegister(MCInst &Inst,
4331 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4333 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4334 // Create a writeback register dummy placeholder.
4335 Inst.addOperand(MCOperand::CreateImm(0));
4337 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4339 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4341 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4345 cvtVSTwbFixed(MCInst &Inst,
4346 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4347 // Create a writeback register dummy placeholder.
4348 Inst.addOperand(MCOperand::CreateImm(0));
4350 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4352 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4354 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4358 cvtVSTwbRegister(MCInst &Inst,
4359 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4360 // Create a writeback register dummy placeholder.
4361 Inst.addOperand(MCOperand::CreateImm(0));
4363 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4365 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4367 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
4369 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4372 /// Parse an ARM memory expression, return false if successful else return true
4373 /// or an error. The first token must be a '[' when called.
4375 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4377 assert(Parser.getTok().is(AsmToken::LBrac) &&
4378 "Token is not a Left Bracket");
4379 S = Parser.getTok().getLoc();
4380 Parser.Lex(); // Eat left bracket token.
4382 const AsmToken &BaseRegTok = Parser.getTok();
4383 int BaseRegNum = tryParseRegister();
4384 if (BaseRegNum == -1)
4385 return Error(BaseRegTok.getLoc(), "register expected");
4387 // The next token must either be a comma, a colon or a closing bracket.
4388 const AsmToken &Tok = Parser.getTok();
4389 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4390 !Tok.is(AsmToken::RBrac))
4391 return Error(Tok.getLoc(), "malformed memory operand");
4393 if (Tok.is(AsmToken::RBrac)) {
4394 E = Tok.getEndLoc();
4395 Parser.Lex(); // Eat right bracket token.
4397 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4398 0, 0, false, S, E));
4400 // If there's a pre-indexing writeback marker, '!', just add it as a token
4401 // operand. It's rather odd, but syntactically valid.
4402 if (Parser.getTok().is(AsmToken::Exclaim)) {
4403 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4404 Parser.Lex(); // Eat the '!'.
4410 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4411 "Lost colon or comma in memory operand?!");
4412 if (Tok.is(AsmToken::Comma)) {
4413 Parser.Lex(); // Eat the comma.
4416 // If we have a ':', it's an alignment specifier.
4417 if (Parser.getTok().is(AsmToken::Colon)) {
4418 Parser.Lex(); // Eat the ':'.
4419 E = Parser.getTok().getLoc();
4422 if (getParser().parseExpression(Expr))
4425 // The expression has to be a constant. Memory references with relocations
4426 // don't come through here, as they use the <label> forms of the relevant
4428 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4430 return Error (E, "constant expression expected");
4433 switch (CE->getValue()) {
4436 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4437 case 16: Align = 2; break;
4438 case 32: Align = 4; break;
4439 case 64: Align = 8; break;
4440 case 128: Align = 16; break;
4441 case 256: Align = 32; break;
4444 // Now we should have the closing ']'
4445 if (Parser.getTok().isNot(AsmToken::RBrac))
4446 return Error(Parser.getTok().getLoc(), "']' expected");
4447 E = Parser.getTok().getEndLoc();
4448 Parser.Lex(); // Eat right bracket token.
4450 // Don't worry about range checking the value here. That's handled by
4451 // the is*() predicates.
4452 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4453 ARM_AM::no_shift, 0, Align,
4456 // If there's a pre-indexing writeback marker, '!', just add it as a token
4458 if (Parser.getTok().is(AsmToken::Exclaim)) {
4459 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4460 Parser.Lex(); // Eat the '!'.
4466 // If we have a '#', it's an immediate offset, else assume it's a register
4467 // offset. Be friendly and also accept a plain integer (without a leading
4468 // hash) for gas compatibility.
4469 if (Parser.getTok().is(AsmToken::Hash) ||
4470 Parser.getTok().is(AsmToken::Dollar) ||
4471 Parser.getTok().is(AsmToken::Integer)) {
4472 if (Parser.getTok().isNot(AsmToken::Integer))
4473 Parser.Lex(); // Eat '#' or '$'.
4474 E = Parser.getTok().getLoc();
4476 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4477 const MCExpr *Offset;
4478 if (getParser().parseExpression(Offset))
4481 // The expression has to be a constant. Memory references with relocations
4482 // don't come through here, as they use the <label> forms of the relevant
4484 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4486 return Error (E, "constant expression expected");
4488 // If the constant was #-0, represent it as INT32_MIN.
4489 int32_t Val = CE->getValue();
4490 if (isNegative && Val == 0)
4491 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4493 // Now we should have the closing ']'
4494 if (Parser.getTok().isNot(AsmToken::RBrac))
4495 return Error(Parser.getTok().getLoc(), "']' expected");
4496 E = Parser.getTok().getEndLoc();
4497 Parser.Lex(); // Eat right bracket token.
4499 // Don't worry about range checking the value here. That's handled by
4500 // the is*() predicates.
4501 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4502 ARM_AM::no_shift, 0, 0,
4505 // If there's a pre-indexing writeback marker, '!', just add it as a token
4507 if (Parser.getTok().is(AsmToken::Exclaim)) {
4508 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4509 Parser.Lex(); // Eat the '!'.
4515 // The register offset is optionally preceded by a '+' or '-'
4516 bool isNegative = false;
4517 if (Parser.getTok().is(AsmToken::Minus)) {
4519 Parser.Lex(); // Eat the '-'.
4520 } else if (Parser.getTok().is(AsmToken::Plus)) {
4522 Parser.Lex(); // Eat the '+'.
4525 E = Parser.getTok().getLoc();
4526 int OffsetRegNum = tryParseRegister();
4527 if (OffsetRegNum == -1)
4528 return Error(E, "register expected");
4530 // If there's a shift operator, handle it.
4531 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4532 unsigned ShiftImm = 0;
4533 if (Parser.getTok().is(AsmToken::Comma)) {
4534 Parser.Lex(); // Eat the ','.
4535 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4539 // Now we should have the closing ']'
4540 if (Parser.getTok().isNot(AsmToken::RBrac))
4541 return Error(Parser.getTok().getLoc(), "']' expected");
4542 E = Parser.getTok().getEndLoc();
4543 Parser.Lex(); // Eat right bracket token.
4545 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4546 ShiftType, ShiftImm, 0, isNegative,
4549 // If there's a pre-indexing writeback marker, '!', just add it as a token
4551 if (Parser.getTok().is(AsmToken::Exclaim)) {
4552 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4553 Parser.Lex(); // Eat the '!'.
4559 /// parseMemRegOffsetShift - one of these two:
4560 /// ( lsl | lsr | asr | ror ) , # shift_amount
4562 /// return true if it parses a shift otherwise it returns false.
4563 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4565 SMLoc Loc = Parser.getTok().getLoc();
4566 const AsmToken &Tok = Parser.getTok();
4567 if (Tok.isNot(AsmToken::Identifier))
4569 StringRef ShiftName = Tok.getString();
4570 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4571 ShiftName == "asl" || ShiftName == "ASL")
4573 else if (ShiftName == "lsr" || ShiftName == "LSR")
4575 else if (ShiftName == "asr" || ShiftName == "ASR")
4577 else if (ShiftName == "ror" || ShiftName == "ROR")
4579 else if (ShiftName == "rrx" || ShiftName == "RRX")
4582 return Error(Loc, "illegal shift operator");
4583 Parser.Lex(); // Eat shift type token.
4585 // rrx stands alone.
4587 if (St != ARM_AM::rrx) {
4588 Loc = Parser.getTok().getLoc();
4589 // A '#' and a shift amount.
4590 const AsmToken &HashTok = Parser.getTok();
4591 if (HashTok.isNot(AsmToken::Hash) &&
4592 HashTok.isNot(AsmToken::Dollar))
4593 return Error(HashTok.getLoc(), "'#' expected");
4594 Parser.Lex(); // Eat hash token.
4597 if (getParser().parseExpression(Expr))
4599 // Range check the immediate.
4600 // lsl, ror: 0 <= imm <= 31
4601 // lsr, asr: 0 <= imm <= 32
4602 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4604 return Error(Loc, "shift amount must be an immediate");
4605 int64_t Imm = CE->getValue();
4607 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4608 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4609 return Error(Loc, "immediate shift value out of range");
4610 // If <ShiftTy> #0, turn it into a no_shift.
4613 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4622 /// parseFPImm - A floating point immediate expression operand.
4623 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4624 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4625 // Anything that can accept a floating point constant as an operand
4626 // needs to go through here, as the regular parseExpression is
4629 // This routine still creates a generic Immediate operand, containing
4630 // a bitcast of the 64-bit floating point value. The various operands
4631 // that accept floats can check whether the value is valid for them
4632 // via the standard is*() predicates.
4634 SMLoc S = Parser.getTok().getLoc();
4636 if (Parser.getTok().isNot(AsmToken::Hash) &&
4637 Parser.getTok().isNot(AsmToken::Dollar))
4638 return MatchOperand_NoMatch;
4640 // Disambiguate the VMOV forms that can accept an FP immediate.
4641 // vmov.f32 <sreg>, #imm
4642 // vmov.f64 <dreg>, #imm
4643 // vmov.f32 <dreg>, #imm @ vector f32x2
4644 // vmov.f32 <qreg>, #imm @ vector f32x4
4646 // There are also the NEON VMOV instructions which expect an
4647 // integer constant. Make sure we don't try to parse an FPImm
4649 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4650 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4651 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4652 TyOp->getToken() != ".f64"))
4653 return MatchOperand_NoMatch;
4655 Parser.Lex(); // Eat '#' or '$'.
4657 // Handle negation, as that still comes through as a separate token.
4658 bool isNegative = false;
4659 if (Parser.getTok().is(AsmToken::Minus)) {
4663 const AsmToken &Tok = Parser.getTok();
4664 SMLoc Loc = Tok.getLoc();
4665 if (Tok.is(AsmToken::Real)) {
4666 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4667 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4668 // If we had a '-' in front, toggle the sign bit.
4669 IntVal ^= (uint64_t)isNegative << 31;
4670 Parser.Lex(); // Eat the token.
4671 Operands.push_back(ARMOperand::CreateImm(
4672 MCConstantExpr::Create(IntVal, getContext()),
4673 S, Parser.getTok().getLoc()));
4674 return MatchOperand_Success;
4676 // Also handle plain integers. Instructions which allow floating point
4677 // immediates also allow a raw encoded 8-bit value.
4678 if (Tok.is(AsmToken::Integer)) {
4679 int64_t Val = Tok.getIntVal();
4680 Parser.Lex(); // Eat the token.
4681 if (Val > 255 || Val < 0) {
4682 Error(Loc, "encoded floating point value out of range");
4683 return MatchOperand_ParseFail;
4685 double RealVal = ARM_AM::getFPImmFloat(Val);
4686 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4687 Operands.push_back(ARMOperand::CreateImm(
4688 MCConstantExpr::Create(Val, getContext()), S,
4689 Parser.getTok().getLoc()));
4690 return MatchOperand_Success;
4693 Error(Loc, "invalid floating point immediate");
4694 return MatchOperand_ParseFail;
4697 /// Parse a arm instruction operand. For now this parses the operand regardless
4698 /// of the mnemonic.
4699 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4700 StringRef Mnemonic) {
4703 // Check if the current operand has a custom associated parser, if so, try to
4704 // custom parse the operand, or fallback to the general approach.
4705 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4706 if (ResTy == MatchOperand_Success)
4708 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4709 // there was a match, but an error occurred, in which case, just return that
4710 // the operand parsing failed.
4711 if (ResTy == MatchOperand_ParseFail)
4714 switch (getLexer().getKind()) {
4716 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4718 case AsmToken::Identifier: {
4719 // If we've seen a branch mnemonic, the next operand must be a label. This
4720 // is true even if the label is a register name. So "br r1" means branch to
4722 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4724 if (!tryParseRegisterWithWriteBack(Operands))
4726 int Res = tryParseShiftRegister(Operands);
4727 if (Res == 0) // success
4729 else if (Res == -1) // irrecoverable error
4731 // If this is VMRS, check for the apsr_nzcv operand.
4732 if (Mnemonic == "vmrs" &&
4733 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4734 S = Parser.getTok().getLoc();
4736 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4741 // Fall though for the Identifier case that is not a register or a
4744 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4745 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4746 case AsmToken::String: // quoted label names.
4747 case AsmToken::Dot: { // . as a branch target
4748 // This was not a register so parse other operands that start with an
4749 // identifier (like labels) as expressions and create them as immediates.
4750 const MCExpr *IdVal;
4751 S = Parser.getTok().getLoc();
4752 if (getParser().parseExpression(IdVal))
4754 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4755 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4758 case AsmToken::LBrac:
4759 return parseMemory(Operands);
4760 case AsmToken::LCurly:
4761 return parseRegisterList(Operands);
4762 case AsmToken::Dollar:
4763 case AsmToken::Hash: {
4764 // #42 -> immediate.
4765 S = Parser.getTok().getLoc();
4768 if (Parser.getTok().isNot(AsmToken::Colon)) {
4769 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4770 const MCExpr *ImmVal;
4771 if (getParser().parseExpression(ImmVal))
4773 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4775 int32_t Val = CE->getValue();
4776 if (isNegative && Val == 0)
4777 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4779 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4780 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4782 // There can be a trailing '!' on operands that we want as a separate
4783 // '!' Token operand. Handle that here. For example, the compatibilty
4784 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4785 if (Parser.getTok().is(AsmToken::Exclaim)) {
4786 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4787 Parser.getTok().getLoc()));
4788 Parser.Lex(); // Eat exclaim token
4792 // w/ a ':' after the '#', it's just like a plain ':'.
4795 case AsmToken::Colon: {
4796 // ":lower16:" and ":upper16:" expression prefixes
4797 // FIXME: Check it's an expression prefix,
4798 // e.g. (FOO - :lower16:BAR) isn't legal.
4799 ARMMCExpr::VariantKind RefKind;
4800 if (parsePrefix(RefKind))
4803 const MCExpr *SubExprVal;
4804 if (getParser().parseExpression(SubExprVal))
4807 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4809 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4810 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4816 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4817 // :lower16: and :upper16:.
4818 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4819 RefKind = ARMMCExpr::VK_ARM_None;
4821 // :lower16: and :upper16: modifiers
4822 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4823 Parser.Lex(); // Eat ':'
4825 if (getLexer().isNot(AsmToken::Identifier)) {
4826 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4830 StringRef IDVal = Parser.getTok().getIdentifier();
4831 if (IDVal == "lower16") {
4832 RefKind = ARMMCExpr::VK_ARM_LO16;
4833 } else if (IDVal == "upper16") {
4834 RefKind = ARMMCExpr::VK_ARM_HI16;
4836 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4841 if (getLexer().isNot(AsmToken::Colon)) {
4842 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4845 Parser.Lex(); // Eat the last ':'
4849 /// \brief Given a mnemonic, split out possible predication code and carry
4850 /// setting letters to form a canonical mnemonic and flags.
4852 // FIXME: Would be nice to autogen this.
4853 // FIXME: This is a bit of a maze of special cases.
4854 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4855 unsigned &PredicationCode,
4857 unsigned &ProcessorIMod,
4858 StringRef &ITMask) {
4859 PredicationCode = ARMCC::AL;
4860 CarrySetting = false;
4863 // Ignore some mnemonics we know aren't predicated forms.
4865 // FIXME: Would be nice to autogen this.
4866 if ((Mnemonic == "movs" && isThumb()) ||
4867 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4868 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4869 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4870 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4871 Mnemonic == "vaclt" || Mnemonic == "vacle" ||
4872 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4873 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4874 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4875 Mnemonic == "fmuls")
4878 // First, split out any predication code. Ignore mnemonics we know aren't
4879 // predicated but do have a carry-set and so weren't caught above.
4880 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4881 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4882 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4883 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4884 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4885 .Case("eq", ARMCC::EQ)
4886 .Case("ne", ARMCC::NE)
4887 .Case("hs", ARMCC::HS)
4888 .Case("cs", ARMCC::HS)
4889 .Case("lo", ARMCC::LO)
4890 .Case("cc", ARMCC::LO)
4891 .Case("mi", ARMCC::MI)
4892 .Case("pl", ARMCC::PL)
4893 .Case("vs", ARMCC::VS)
4894 .Case("vc", ARMCC::VC)
4895 .Case("hi", ARMCC::HI)
4896 .Case("ls", ARMCC::LS)
4897 .Case("ge", ARMCC::GE)
4898 .Case("lt", ARMCC::LT)
4899 .Case("gt", ARMCC::GT)
4900 .Case("le", ARMCC::LE)
4901 .Case("al", ARMCC::AL)
4904 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4905 PredicationCode = CC;
4909 // Next, determine if we have a carry setting bit. We explicitly ignore all
4910 // the instructions we know end in 's'.
4911 if (Mnemonic.endswith("s") &&
4912 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4913 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4914 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4915 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4916 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4917 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4918 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4919 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4920 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4921 (Mnemonic == "movs" && isThumb()))) {
4922 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4923 CarrySetting = true;
4926 // The "cps" instruction can have a interrupt mode operand which is glued into
4927 // the mnemonic. Check if this is the case, split it and parse the imod op
4928 if (Mnemonic.startswith("cps")) {
4929 // Split out any imod code.
4931 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4932 .Case("ie", ARM_PROC::IE)
4933 .Case("id", ARM_PROC::ID)
4936 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4937 ProcessorIMod = IMod;
4941 // The "it" instruction has the condition mask on the end of the mnemonic.
4942 if (Mnemonic.startswith("it")) {
4943 ITMask = Mnemonic.slice(2, Mnemonic.size());
4944 Mnemonic = Mnemonic.slice(0, 2);
4950 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4951 /// inclusion of carry set or predication code operands.
4953 // FIXME: It would be nice to autogen this.
4955 getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
4956 bool &CanAcceptPredicationCode) {
4957 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4958 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4959 Mnemonic == "add" || Mnemonic == "adc" ||
4960 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4961 Mnemonic == "orr" || Mnemonic == "mvn" ||
4962 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4963 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4964 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4965 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4966 Mnemonic == "mla" || Mnemonic == "smlal" ||
4967 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4968 CanAcceptCarrySet = true;
4970 CanAcceptCarrySet = false;
4972 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4973 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4974 Mnemonic == "trap" || Mnemonic == "setend" ||
4975 Mnemonic.startswith("cps")) {
4976 // These mnemonics are never predicable
4977 CanAcceptPredicationCode = false;
4978 } else if (!isThumb()) {
4979 // Some instructions are only predicable in Thumb mode
4980 CanAcceptPredicationCode
4981 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4982 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4983 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4984 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4985 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4986 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4987 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4988 } else if (isThumbOne()) {
4989 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4991 CanAcceptPredicationCode = true;
4994 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4995 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4996 // FIXME: This is all horribly hacky. We really need a better way to deal
4997 // with optional operands like this in the matcher table.
4999 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5000 // another does not. Specifically, the MOVW instruction does not. So we
5001 // special case it here and remove the defaulted (non-setting) cc_out
5002 // operand if that's the instruction we're trying to match.
5004 // We do this as post-processing of the explicit operands rather than just
5005 // conditionally adding the cc_out in the first place because we need
5006 // to check the type of the parsed immediate operand.
5007 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
5008 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
5009 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
5010 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5013 // Register-register 'add' for thumb does not have a cc_out operand
5014 // when there are only two register operands.
5015 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
5016 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5017 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5018 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5020 // Register-register 'add' for thumb does not have a cc_out operand
5021 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5022 // have to check the immediate range here since Thumb2 has a variant
5023 // that can handle a different range and has a cc_out operand.
5024 if (((isThumb() && Mnemonic == "add") ||
5025 (isThumbTwo() && Mnemonic == "sub")) &&
5026 Operands.size() == 6 &&
5027 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5028 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5029 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
5030 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5031 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
5032 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
5034 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5035 // imm0_4095 variant. That's the least-preferred variant when
5036 // selecting via the generic "add" mnemonic, so to know that we
5037 // should remove the cc_out operand, we have to explicitly check that
5038 // it's not one of the other variants. Ugh.
5039 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5040 Operands.size() == 6 &&
5041 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5042 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5043 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5044 // Nest conditions rather than one big 'if' statement for readability.
5046 // If either register is a high reg, it's either one of the SP
5047 // variants (handled above) or a 32-bit encoding, so we just
5048 // check against T3. If the second register is the PC, this is an
5049 // alternate form of ADR, which uses encoding T4, so check for that too.
5050 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5051 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
5052 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5053 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5055 // If both registers are low, we're in an IT block, and the immediate is
5056 // in range, we should use encoding T1 instead, which has a cc_out.
5058 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5059 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5060 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5063 // Otherwise, we use encoding T4, which does not have a cc_out
5068 // The thumb2 multiply instruction doesn't have a CCOut register, so
5069 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5070 // use the 16-bit encoding or not.
5071 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5072 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5073 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5074 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5075 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5076 // If the registers aren't low regs, the destination reg isn't the
5077 // same as one of the source regs, or the cc_out operand is zero
5078 // outside of an IT block, we have to use the 32-bit encoding, so
5079 // remove the cc_out operand.
5080 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5081 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5082 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
5084 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5085 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5086 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5087 static_cast<ARMOperand*>(Operands[4])->getReg())))
5090 // Also check the 'mul' syntax variant that doesn't specify an explicit
5091 // destination register.
5092 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5093 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5094 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5095 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5096 // If the registers aren't low regs or the cc_out operand is zero
5097 // outside of an IT block, we have to use the 32-bit encoding, so
5098 // remove the cc_out operand.
5099 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5100 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5106 // Register-register 'add/sub' for thumb does not have a cc_out operand
5107 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5108 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5109 // right, this will result in better diagnostics (which operand is off)
5111 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5112 (Operands.size() == 5 || Operands.size() == 6) &&
5113 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5114 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
5115 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5116 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5117 (Operands.size() == 6 &&
5118 static_cast<ARMOperand*>(Operands[5])->isImm())))
5124 static bool isDataTypeToken(StringRef Tok) {
5125 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5126 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5127 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5128 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5129 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5130 Tok == ".f" || Tok == ".d";
5133 // FIXME: This bit should probably be handled via an explicit match class
5134 // in the .td files that matches the suffix instead of having it be
5135 // a literal string token the way it is now.
5136 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5137 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5139 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5140 unsigned VariantID);
5141 /// Parse an arm instruction mnemonic followed by its operands.
5142 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5144 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5145 // Apply mnemonic aliases before doing anything else, as the destination
5146 // mnemnonic may include suffices and we want to handle them normally.
5147 // The generic tblgen'erated code does this later, at the start of
5148 // MatchInstructionImpl(), but that's too late for aliases that include
5149 // any sort of suffix.
5150 unsigned AvailableFeatures = getAvailableFeatures();
5151 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5152 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5154 // First check for the ARM-specific .req directive.
5155 if (Parser.getTok().is(AsmToken::Identifier) &&
5156 Parser.getTok().getIdentifier() == ".req") {
5157 parseDirectiveReq(Name, NameLoc);
5158 // We always return 'error' for this, as we're done with this
5159 // statement and don't need to match the 'instruction."
5163 // Create the leading tokens for the mnemonic, split by '.' characters.
5164 size_t Start = 0, Next = Name.find('.');
5165 StringRef Mnemonic = Name.slice(Start, Next);
5167 // Split out the predication code and carry setting flag from the mnemonic.
5168 unsigned PredicationCode;
5169 unsigned ProcessorIMod;
5172 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5173 ProcessorIMod, ITMask);
5175 // In Thumb1, only the branch (B) instruction can be predicated.
5176 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5177 Parser.eatToEndOfStatement();
5178 return Error(NameLoc, "conditional execution not supported in Thumb1");
5181 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5183 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5184 // is the mask as it will be for the IT encoding if the conditional
5185 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5186 // where the conditional bit0 is zero, the instruction post-processing
5187 // will adjust the mask accordingly.
5188 if (Mnemonic == "it") {
5189 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5190 if (ITMask.size() > 3) {
5191 Parser.eatToEndOfStatement();
5192 return Error(Loc, "too many conditions on IT instruction");
5195 for (unsigned i = ITMask.size(); i != 0; --i) {
5196 char pos = ITMask[i - 1];
5197 if (pos != 't' && pos != 'e') {
5198 Parser.eatToEndOfStatement();
5199 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5202 if (ITMask[i - 1] == 't')
5205 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5208 // FIXME: This is all a pretty gross hack. We should automatically handle
5209 // optional operands like this via tblgen.
5211 // Next, add the CCOut and ConditionCode operands, if needed.
5213 // For mnemonics which can ever incorporate a carry setting bit or predication
5214 // code, our matching model involves us always generating CCOut and
5215 // ConditionCode operands to match the mnemonic "as written" and then we let
5216 // the matcher deal with finding the right instruction or generating an
5217 // appropriate error.
5218 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5219 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
5221 // If we had a carry-set on an instruction that can't do that, issue an
5223 if (!CanAcceptCarrySet && CarrySetting) {
5224 Parser.eatToEndOfStatement();
5225 return Error(NameLoc, "instruction '" + Mnemonic +
5226 "' can not set flags, but 's' suffix specified");
5228 // If we had a predication code on an instruction that can't do that, issue an
5230 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5231 Parser.eatToEndOfStatement();
5232 return Error(NameLoc, "instruction '" + Mnemonic +
5233 "' is not predicable, but condition code specified");
5236 // Add the carry setting operand, if necessary.
5237 if (CanAcceptCarrySet) {
5238 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5239 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5243 // Add the predication code operand, if necessary.
5244 if (CanAcceptPredicationCode) {
5245 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5247 Operands.push_back(ARMOperand::CreateCondCode(
5248 ARMCC::CondCodes(PredicationCode), Loc));
5251 // Add the processor imod operand, if necessary.
5252 if (ProcessorIMod) {
5253 Operands.push_back(ARMOperand::CreateImm(
5254 MCConstantExpr::Create(ProcessorIMod, getContext()),
5258 // Add the remaining tokens in the mnemonic.
5259 while (Next != StringRef::npos) {
5261 Next = Name.find('.', Start + 1);
5262 StringRef ExtraToken = Name.slice(Start, Next);
5264 // Some NEON instructions have an optional datatype suffix that is
5265 // completely ignored. Check for that.
5266 if (isDataTypeToken(ExtraToken) &&
5267 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5270 // For for ARM mode generate an error if the .n qualifier is used.
5271 if (ExtraToken == ".n" && !isThumb()) {
5272 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5273 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5277 // The .n qualifier is always discarded as that is what the tables
5278 // and matcher expect. In ARM mode the .w qualifier has no effect,
5279 // so discard it to avoid errors that can be caused by the matcher.
5280 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5281 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5282 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5286 // Read the remaining operands.
5287 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5288 // Read the first operand.
5289 if (parseOperand(Operands, Mnemonic)) {
5290 Parser.eatToEndOfStatement();
5294 while (getLexer().is(AsmToken::Comma)) {
5295 Parser.Lex(); // Eat the comma.
5297 // Parse and remember the operand.
5298 if (parseOperand(Operands, Mnemonic)) {
5299 Parser.eatToEndOfStatement();
5305 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5306 SMLoc Loc = getLexer().getLoc();
5307 Parser.eatToEndOfStatement();
5308 return Error(Loc, "unexpected token in argument list");
5311 Parser.Lex(); // Consume the EndOfStatement
5313 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5314 // do and don't have a cc_out optional-def operand. With some spot-checks
5315 // of the operand list, we can figure out which variant we're trying to
5316 // parse and adjust accordingly before actually matching. We shouldn't ever
5317 // try to remove a cc_out operand that was explicitly set on the the
5318 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5319 // table driven matcher doesn't fit well with the ARM instruction set.
5320 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5321 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5322 Operands.erase(Operands.begin() + 1);
5326 // ARM mode 'blx' need special handling, as the register operand version
5327 // is predicable, but the label operand version is not. So, we can't rely
5328 // on the Mnemonic based checking to correctly figure out when to put
5329 // a k_CondCode operand in the list. If we're trying to match the label
5330 // version, remove the k_CondCode operand here.
5331 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5332 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5333 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5334 Operands.erase(Operands.begin() + 1);
5338 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5339 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5340 // a single GPRPair reg operand is used in the .td file to replace the two
5341 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5342 // expressed as a GPRPair, so we have to manually merge them.
5343 // FIXME: We would really like to be able to tablegen'erate this.
5344 if (!isThumb() && Operands.size() > 4 &&
5345 (Mnemonic == "ldrexd" || Mnemonic == "strexd")) {
5346 bool isLoad = (Mnemonic == "ldrexd");
5347 unsigned Idx = isLoad ? 2 : 3;
5348 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5349 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5351 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5352 // Adjust only if Op1 and Op2 are GPRs.
5353 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5354 MRC.contains(Op2->getReg())) {
5355 unsigned Reg1 = Op1->getReg();
5356 unsigned Reg2 = Op2->getReg();
5357 unsigned Rt = MRI->getEncodingValue(Reg1);
5358 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5360 // Rt2 must be Rt + 1 and Rt must be even.
5361 if (Rt + 1 != Rt2 || (Rt & 1)) {
5362 Error(Op2->getStartLoc(), isLoad ?
5363 "destination operands must be sequential" :
5364 "source operands must be sequential");
5367 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5368 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5369 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5370 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5371 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5380 // Validate context-sensitive operand constraints.
5382 // return 'true' if register list contains non-low GPR registers,
5383 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5384 // 'containsReg' to true.
5385 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5386 unsigned HiReg, bool &containsReg) {
5387 containsReg = false;
5388 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5389 unsigned OpReg = Inst.getOperand(i).getReg();
5392 // Anything other than a low register isn't legal here.
5393 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5399 // Check if the specified regisgter is in the register list of the inst,
5400 // starting at the indicated operand number.
5401 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5402 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5403 unsigned OpReg = Inst.getOperand(i).getReg();
5410 // FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5411 // the ARMInsts array) instead. Getting that here requires awkward
5412 // API changes, though. Better way?
5414 extern const MCInstrDesc ARMInsts[];
5416 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
5417 return ARMInsts[Opcode];
5420 // FIXME: We would really like to be able to tablegen'erate this.
5422 validateInstruction(MCInst &Inst,
5423 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5424 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
5425 SMLoc Loc = Operands[0]->getStartLoc();
5426 // Check the IT block state first.
5427 // NOTE: BKPT instruction has the interesting property of being
5428 // allowed in IT blocks, but not being predicable. It just always
5430 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5431 Inst.getOpcode() != ARM::BKPT) {
5433 if (ITState.FirstCond)
5434 ITState.FirstCond = false;
5436 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5437 // The instruction must be predicable.
5438 if (!MCID.isPredicable())
5439 return Error(Loc, "instructions in IT block must be predicable");
5440 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5441 unsigned ITCond = bit ? ITState.Cond :
5442 ARMCC::getOppositeCondition(ITState.Cond);
5443 if (Cond != ITCond) {
5444 // Find the condition code Operand to get its SMLoc information.
5446 for (unsigned i = 1; i < Operands.size(); ++i)
5447 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5448 CondLoc = Operands[i]->getStartLoc();
5449 return Error(CondLoc, "incorrect condition in IT block; got '" +
5450 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5451 "', but expected '" +
5452 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5454 // Check for non-'al' condition codes outside of the IT block.
5455 } else if (isThumbTwo() && MCID.isPredicable() &&
5456 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5457 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5458 Inst.getOpcode() != ARM::t2B)
5459 return Error(Loc, "predicated instructions must be in IT block");
5461 switch (Inst.getOpcode()) {
5464 case ARM::LDRD_POST: {
5465 // Rt2 must be Rt + 1.
5466 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5467 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5469 return Error(Operands[3]->getStartLoc(),
5470 "destination operands must be sequential");
5474 // Rt2 must be Rt + 1.
5475 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5476 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5478 return Error(Operands[3]->getStartLoc(),
5479 "source operands must be sequential");
5483 case ARM::STRD_POST: {
5484 // Rt2 must be Rt + 1.
5485 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5486 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5488 return Error(Operands[3]->getStartLoc(),
5489 "source operands must be sequential");
5494 // width must be in range [1, 32-lsb]
5495 unsigned lsb = Inst.getOperand(2).getImm();
5496 unsigned widthm1 = Inst.getOperand(3).getImm();
5497 if (widthm1 >= 32 - lsb)
5498 return Error(Operands[5]->getStartLoc(),
5499 "bitfield width must be in range [1,32-lsb]");
5503 // If we're parsing Thumb2, the .w variant is available and handles
5504 // most cases that are normally illegal for a Thumb1 LDM
5505 // instruction. We'll make the transformation in processInstruction()
5508 // Thumb LDM instructions are writeback iff the base register is not
5509 // in the register list.
5510 unsigned Rn = Inst.getOperand(0).getReg();
5511 bool hasWritebackToken =
5512 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5513 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5514 bool listContainsBase;
5515 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
5516 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5517 "registers must be in range r0-r7");
5518 // If we should have writeback, then there should be a '!' token.
5519 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
5520 return Error(Operands[2]->getStartLoc(),
5521 "writeback operator '!' expected");
5522 // If we should not have writeback, there must not be a '!'. This is
5523 // true even for the 32-bit wide encodings.
5524 if (listContainsBase && hasWritebackToken)
5525 return Error(Operands[3]->getStartLoc(),
5526 "writeback operator '!' not allowed when base register "
5527 "in register list");
5531 case ARM::t2LDMIA_UPD: {
5532 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5533 return Error(Operands[4]->getStartLoc(),
5534 "writeback operator '!' not allowed when base register "
5535 "in register list");
5539 // The second source operand must be the same register as the destination
5542 // In this case, we must directly check the parsed operands because the
5543 // cvtThumbMultiply() function is written in such a way that it guarantees
5544 // this first statement is always true for the new Inst. Essentially, the
5545 // destination is unconditionally copied into the second source operand
5546 // without checking to see if it matches what we actually parsed.
5547 if (Operands.size() == 6 &&
5548 (((ARMOperand*)Operands[3])->getReg() !=
5549 ((ARMOperand*)Operands[5])->getReg()) &&
5550 (((ARMOperand*)Operands[3])->getReg() !=
5551 ((ARMOperand*)Operands[4])->getReg())) {
5552 return Error(Operands[3]->getStartLoc(),
5553 "destination register must match source register");
5557 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5558 // so only issue a diagnostic for thumb1. The instructions will be
5559 // switched to the t2 encodings in processInstruction() if necessary.
5561 bool listContainsBase;
5562 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5564 return Error(Operands[2]->getStartLoc(),
5565 "registers must be in range r0-r7 or pc");
5569 bool listContainsBase;
5570 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5572 return Error(Operands[2]->getStartLoc(),
5573 "registers must be in range r0-r7 or lr");
5576 case ARM::tSTMIA_UPD: {
5577 bool listContainsBase;
5578 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
5579 return Error(Operands[4]->getStartLoc(),
5580 "registers must be in range r0-r7");
5583 case ARM::tADDrSP: {
5584 // If the non-SP source operand and the destination operand are not the
5585 // same, we need thumb2 (for the wide encoding), or we have an error.
5586 if (!isThumbTwo() &&
5587 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5588 return Error(Operands[4]->getStartLoc(),
5589 "source register must be the same as destination");
5598 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5600 default: llvm_unreachable("unexpected opcode!");
5602 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5603 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5604 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5605 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5606 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5607 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5608 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5609 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5610 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5613 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5614 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5615 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5616 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5617 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5619 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5620 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5621 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5622 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5623 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5625 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5626 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5627 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5628 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5629 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5632 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5633 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5634 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5635 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5636 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5637 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5638 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5639 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5640 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5641 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5642 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5643 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5644 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5645 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5646 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5649 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5650 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5651 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5652 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5653 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5654 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5655 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5656 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5657 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5658 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5659 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5660 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5661 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5662 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5663 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5664 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5665 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5666 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5669 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5670 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5671 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5672 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5673 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5674 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5675 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5676 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5677 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5678 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5679 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5680 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5681 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5682 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5683 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5686 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5687 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5688 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5689 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5690 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5691 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5692 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5693 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5694 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5695 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5696 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5697 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5698 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5699 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5700 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5701 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5702 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5703 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5707 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5709 default: llvm_unreachable("unexpected opcode!");
5711 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5712 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5713 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5714 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5715 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5716 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5717 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5718 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5719 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5722 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5723 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5724 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5725 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5726 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5727 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5728 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5729 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5730 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5731 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5732 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5733 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5734 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5735 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5736 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5739 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5740 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5741 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5742 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5743 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5744 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5745 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5746 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5747 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5748 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5749 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5750 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5751 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5752 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5753 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5754 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5755 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5756 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5759 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5760 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5761 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5762 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5763 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5764 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5765 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5766 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5767 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5768 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5769 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5770 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5771 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5772 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5773 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5776 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5777 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5778 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5779 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5780 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5781 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5782 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5783 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5784 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5785 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5786 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5787 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5788 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5789 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5790 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5791 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5792 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5793 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5796 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5797 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5798 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5799 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5800 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5801 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5802 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5803 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5804 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5805 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5806 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5807 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5808 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5809 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5810 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5813 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5814 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5815 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5816 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5817 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5818 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5819 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5820 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5821 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5822 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5823 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5824 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5825 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5826 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5827 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5828 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5829 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5830 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5833 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5834 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5835 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5836 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5837 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5838 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5839 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5840 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5841 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5842 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5843 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5844 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5845 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5846 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5847 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5848 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5849 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5850 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5855 processInstruction(MCInst &Inst,
5856 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5857 switch (Inst.getOpcode()) {
5858 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5860 if (Inst.getOperand(1).getReg() != ARM::PC ||
5861 Inst.getOperand(5).getReg() != 0)
5864 TmpInst.setOpcode(ARM::ADR);
5865 TmpInst.addOperand(Inst.getOperand(0));
5866 TmpInst.addOperand(Inst.getOperand(2));
5867 TmpInst.addOperand(Inst.getOperand(3));
5868 TmpInst.addOperand(Inst.getOperand(4));
5872 // Aliases for alternate PC+imm syntax of LDR instructions.
5873 case ARM::t2LDRpcrel:
5874 // Select the narrow version if the immediate will fit.
5875 if (Inst.getOperand(1).getImm() > 0 &&
5876 Inst.getOperand(1).getImm() <= 0xff &&
5877 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5878 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
5879 Inst.setOpcode(ARM::tLDRpci);
5881 Inst.setOpcode(ARM::t2LDRpci);
5883 case ARM::t2LDRBpcrel:
5884 Inst.setOpcode(ARM::t2LDRBpci);
5886 case ARM::t2LDRHpcrel:
5887 Inst.setOpcode(ARM::t2LDRHpci);
5889 case ARM::t2LDRSBpcrel:
5890 Inst.setOpcode(ARM::t2LDRSBpci);
5892 case ARM::t2LDRSHpcrel:
5893 Inst.setOpcode(ARM::t2LDRSHpci);
5895 // Handle NEON VST complex aliases.
5896 case ARM::VST1LNdWB_register_Asm_8:
5897 case ARM::VST1LNdWB_register_Asm_16:
5898 case ARM::VST1LNdWB_register_Asm_32: {
5900 // Shuffle the operands around so the lane index operand is in the
5903 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5904 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5905 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5906 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5907 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5908 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5909 TmpInst.addOperand(Inst.getOperand(1)); // lane
5910 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5911 TmpInst.addOperand(Inst.getOperand(6));
5916 case ARM::VST2LNdWB_register_Asm_8:
5917 case ARM::VST2LNdWB_register_Asm_16:
5918 case ARM::VST2LNdWB_register_Asm_32:
5919 case ARM::VST2LNqWB_register_Asm_16:
5920 case ARM::VST2LNqWB_register_Asm_32: {
5922 // Shuffle the operands around so the lane index operand is in the
5925 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5926 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5927 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5928 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5929 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5930 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5931 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5933 TmpInst.addOperand(Inst.getOperand(1)); // lane
5934 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5935 TmpInst.addOperand(Inst.getOperand(6));
5940 case ARM::VST3LNdWB_register_Asm_8:
5941 case ARM::VST3LNdWB_register_Asm_16:
5942 case ARM::VST3LNdWB_register_Asm_32:
5943 case ARM::VST3LNqWB_register_Asm_16:
5944 case ARM::VST3LNqWB_register_Asm_32: {
5946 // Shuffle the operands around so the lane index operand is in the
5949 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5950 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5951 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5952 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5953 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5954 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5955 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5957 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5959 TmpInst.addOperand(Inst.getOperand(1)); // lane
5960 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5961 TmpInst.addOperand(Inst.getOperand(6));
5966 case ARM::VST4LNdWB_register_Asm_8:
5967 case ARM::VST4LNdWB_register_Asm_16:
5968 case ARM::VST4LNdWB_register_Asm_32:
5969 case ARM::VST4LNqWB_register_Asm_16:
5970 case ARM::VST4LNqWB_register_Asm_32: {
5972 // Shuffle the operands around so the lane index operand is in the
5975 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5976 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5977 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5978 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5979 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5980 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5981 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5983 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5985 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5987 TmpInst.addOperand(Inst.getOperand(1)); // lane
5988 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5989 TmpInst.addOperand(Inst.getOperand(6));
5994 case ARM::VST1LNdWB_fixed_Asm_8:
5995 case ARM::VST1LNdWB_fixed_Asm_16:
5996 case ARM::VST1LNdWB_fixed_Asm_32: {
5998 // Shuffle the operands around so the lane index operand is in the
6001 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6002 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6003 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6004 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6005 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6006 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6007 TmpInst.addOperand(Inst.getOperand(1)); // lane
6008 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6009 TmpInst.addOperand(Inst.getOperand(5));
6014 case ARM::VST2LNdWB_fixed_Asm_8:
6015 case ARM::VST2LNdWB_fixed_Asm_16:
6016 case ARM::VST2LNdWB_fixed_Asm_32:
6017 case ARM::VST2LNqWB_fixed_Asm_16:
6018 case ARM::VST2LNqWB_fixed_Asm_32: {
6020 // Shuffle the operands around so the lane index operand is in the
6023 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6024 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6025 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6026 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6027 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6028 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6029 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6031 TmpInst.addOperand(Inst.getOperand(1)); // lane
6032 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6033 TmpInst.addOperand(Inst.getOperand(5));
6038 case ARM::VST3LNdWB_fixed_Asm_8:
6039 case ARM::VST3LNdWB_fixed_Asm_16:
6040 case ARM::VST3LNdWB_fixed_Asm_32:
6041 case ARM::VST3LNqWB_fixed_Asm_16:
6042 case ARM::VST3LNqWB_fixed_Asm_32: {
6044 // Shuffle the operands around so the lane index operand is in the
6047 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6048 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6049 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6050 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6051 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6052 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6053 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6055 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6057 TmpInst.addOperand(Inst.getOperand(1)); // lane
6058 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6059 TmpInst.addOperand(Inst.getOperand(5));
6064 case ARM::VST4LNdWB_fixed_Asm_8:
6065 case ARM::VST4LNdWB_fixed_Asm_16:
6066 case ARM::VST4LNdWB_fixed_Asm_32:
6067 case ARM::VST4LNqWB_fixed_Asm_16:
6068 case ARM::VST4LNqWB_fixed_Asm_32: {
6070 // Shuffle the operands around so the lane index operand is in the
6073 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6074 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6075 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6076 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6077 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6078 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6079 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6081 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6083 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6085 TmpInst.addOperand(Inst.getOperand(1)); // lane
6086 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6087 TmpInst.addOperand(Inst.getOperand(5));
6092 case ARM::VST1LNdAsm_8:
6093 case ARM::VST1LNdAsm_16:
6094 case ARM::VST1LNdAsm_32: {
6096 // Shuffle the operands around so the lane index operand is in the
6099 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6100 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6101 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6102 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6103 TmpInst.addOperand(Inst.getOperand(1)); // lane
6104 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6105 TmpInst.addOperand(Inst.getOperand(5));
6110 case ARM::VST2LNdAsm_8:
6111 case ARM::VST2LNdAsm_16:
6112 case ARM::VST2LNdAsm_32:
6113 case ARM::VST2LNqAsm_16:
6114 case ARM::VST2LNqAsm_32: {
6116 // Shuffle the operands around so the lane index operand is in the
6119 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6120 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6121 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6122 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6123 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6125 TmpInst.addOperand(Inst.getOperand(1)); // lane
6126 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6127 TmpInst.addOperand(Inst.getOperand(5));
6132 case ARM::VST3LNdAsm_8:
6133 case ARM::VST3LNdAsm_16:
6134 case ARM::VST3LNdAsm_32:
6135 case ARM::VST3LNqAsm_16:
6136 case ARM::VST3LNqAsm_32: {
6138 // Shuffle the operands around so the lane index operand is in the
6141 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6142 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6143 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6144 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6145 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6147 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6149 TmpInst.addOperand(Inst.getOperand(1)); // lane
6150 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6151 TmpInst.addOperand(Inst.getOperand(5));
6156 case ARM::VST4LNdAsm_8:
6157 case ARM::VST4LNdAsm_16:
6158 case ARM::VST4LNdAsm_32:
6159 case ARM::VST4LNqAsm_16:
6160 case ARM::VST4LNqAsm_32: {
6162 // Shuffle the operands around so the lane index operand is in the
6165 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6166 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6167 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6168 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6169 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6171 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6173 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6175 TmpInst.addOperand(Inst.getOperand(1)); // lane
6176 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6177 TmpInst.addOperand(Inst.getOperand(5));
6182 // Handle NEON VLD complex aliases.
6183 case ARM::VLD1LNdWB_register_Asm_8:
6184 case ARM::VLD1LNdWB_register_Asm_16:
6185 case ARM::VLD1LNdWB_register_Asm_32: {
6187 // Shuffle the operands around so the lane index operand is in the
6190 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6191 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6192 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6193 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6194 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6195 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6196 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6197 TmpInst.addOperand(Inst.getOperand(1)); // lane
6198 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6199 TmpInst.addOperand(Inst.getOperand(6));
6204 case ARM::VLD2LNdWB_register_Asm_8:
6205 case ARM::VLD2LNdWB_register_Asm_16:
6206 case ARM::VLD2LNdWB_register_Asm_32:
6207 case ARM::VLD2LNqWB_register_Asm_16:
6208 case ARM::VLD2LNqWB_register_Asm_32: {
6210 // Shuffle the operands around so the lane index operand is in the
6213 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6214 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6215 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6217 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6218 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6219 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6220 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6221 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6222 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6224 TmpInst.addOperand(Inst.getOperand(1)); // lane
6225 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6226 TmpInst.addOperand(Inst.getOperand(6));
6231 case ARM::VLD3LNdWB_register_Asm_8:
6232 case ARM::VLD3LNdWB_register_Asm_16:
6233 case ARM::VLD3LNdWB_register_Asm_32:
6234 case ARM::VLD3LNqWB_register_Asm_16:
6235 case ARM::VLD3LNqWB_register_Asm_32: {
6237 // Shuffle the operands around so the lane index operand is in the
6240 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6241 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6242 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6244 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6246 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6247 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6248 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6249 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6250 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6251 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6253 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6255 TmpInst.addOperand(Inst.getOperand(1)); // lane
6256 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6257 TmpInst.addOperand(Inst.getOperand(6));
6262 case ARM::VLD4LNdWB_register_Asm_8:
6263 case ARM::VLD4LNdWB_register_Asm_16:
6264 case ARM::VLD4LNdWB_register_Asm_32:
6265 case ARM::VLD4LNqWB_register_Asm_16:
6266 case ARM::VLD4LNqWB_register_Asm_32: {
6268 // Shuffle the operands around so the lane index operand is in the
6271 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6272 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6273 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6275 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6277 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6279 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6280 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6281 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6282 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6283 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6284 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6286 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6288 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6290 TmpInst.addOperand(Inst.getOperand(1)); // lane
6291 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6292 TmpInst.addOperand(Inst.getOperand(6));
6297 case ARM::VLD1LNdWB_fixed_Asm_8:
6298 case ARM::VLD1LNdWB_fixed_Asm_16:
6299 case ARM::VLD1LNdWB_fixed_Asm_32: {
6301 // Shuffle the operands around so the lane index operand is in the
6304 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6305 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6306 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6307 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6308 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6309 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6310 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6311 TmpInst.addOperand(Inst.getOperand(1)); // lane
6312 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6313 TmpInst.addOperand(Inst.getOperand(5));
6318 case ARM::VLD2LNdWB_fixed_Asm_8:
6319 case ARM::VLD2LNdWB_fixed_Asm_16:
6320 case ARM::VLD2LNdWB_fixed_Asm_32:
6321 case ARM::VLD2LNqWB_fixed_Asm_16:
6322 case ARM::VLD2LNqWB_fixed_Asm_32: {
6324 // Shuffle the operands around so the lane index operand is in the
6327 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6328 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6329 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6331 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6332 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6333 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6334 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6335 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6336 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6338 TmpInst.addOperand(Inst.getOperand(1)); // lane
6339 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6340 TmpInst.addOperand(Inst.getOperand(5));
6345 case ARM::VLD3LNdWB_fixed_Asm_8:
6346 case ARM::VLD3LNdWB_fixed_Asm_16:
6347 case ARM::VLD3LNdWB_fixed_Asm_32:
6348 case ARM::VLD3LNqWB_fixed_Asm_16:
6349 case ARM::VLD3LNqWB_fixed_Asm_32: {
6351 // Shuffle the operands around so the lane index operand is in the
6354 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6355 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6356 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6360 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6361 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6362 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6363 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6364 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6365 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6367 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6369 TmpInst.addOperand(Inst.getOperand(1)); // lane
6370 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6371 TmpInst.addOperand(Inst.getOperand(5));
6376 case ARM::VLD4LNdWB_fixed_Asm_8:
6377 case ARM::VLD4LNdWB_fixed_Asm_16:
6378 case ARM::VLD4LNdWB_fixed_Asm_32:
6379 case ARM::VLD4LNqWB_fixed_Asm_16:
6380 case ARM::VLD4LNqWB_fixed_Asm_32: {
6382 // Shuffle the operands around so the lane index operand is in the
6385 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6386 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6387 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6389 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6391 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6393 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6394 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6395 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6396 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6397 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6400 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6404 TmpInst.addOperand(Inst.getOperand(1)); // lane
6405 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6406 TmpInst.addOperand(Inst.getOperand(5));
6411 case ARM::VLD1LNdAsm_8:
6412 case ARM::VLD1LNdAsm_16:
6413 case ARM::VLD1LNdAsm_32: {
6415 // Shuffle the operands around so the lane index operand is in the
6418 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6419 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6420 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6421 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6422 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6423 TmpInst.addOperand(Inst.getOperand(1)); // lane
6424 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6425 TmpInst.addOperand(Inst.getOperand(5));
6430 case ARM::VLD2LNdAsm_8:
6431 case ARM::VLD2LNdAsm_16:
6432 case ARM::VLD2LNdAsm_32:
6433 case ARM::VLD2LNqAsm_16:
6434 case ARM::VLD2LNqAsm_32: {
6436 // Shuffle the operands around so the lane index operand is in the
6439 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6440 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6441 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6443 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6444 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6445 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6446 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6448 TmpInst.addOperand(Inst.getOperand(1)); // lane
6449 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6450 TmpInst.addOperand(Inst.getOperand(5));
6455 case ARM::VLD3LNdAsm_8:
6456 case ARM::VLD3LNdAsm_16:
6457 case ARM::VLD3LNdAsm_32:
6458 case ARM::VLD3LNqAsm_16:
6459 case ARM::VLD3LNqAsm_32: {
6461 // Shuffle the operands around so the lane index operand is in the
6464 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6465 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6466 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6468 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6470 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6471 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6472 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6473 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6475 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6477 TmpInst.addOperand(Inst.getOperand(1)); // lane
6478 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6479 TmpInst.addOperand(Inst.getOperand(5));
6484 case ARM::VLD4LNdAsm_8:
6485 case ARM::VLD4LNdAsm_16:
6486 case ARM::VLD4LNdAsm_32:
6487 case ARM::VLD4LNqAsm_16:
6488 case ARM::VLD4LNqAsm_32: {
6490 // Shuffle the operands around so the lane index operand is in the
6493 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6494 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6501 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6502 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6503 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6504 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6506 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6508 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6510 TmpInst.addOperand(Inst.getOperand(1)); // lane
6511 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6512 TmpInst.addOperand(Inst.getOperand(5));
6517 // VLD3DUP single 3-element structure to all lanes instructions.
6518 case ARM::VLD3DUPdAsm_8:
6519 case ARM::VLD3DUPdAsm_16:
6520 case ARM::VLD3DUPdAsm_32:
6521 case ARM::VLD3DUPqAsm_8:
6522 case ARM::VLD3DUPqAsm_16:
6523 case ARM::VLD3DUPqAsm_32: {
6526 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6527 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6532 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6533 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6534 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6535 TmpInst.addOperand(Inst.getOperand(4));
6540 case ARM::VLD3DUPdWB_fixed_Asm_8:
6541 case ARM::VLD3DUPdWB_fixed_Asm_16:
6542 case ARM::VLD3DUPdWB_fixed_Asm_32:
6543 case ARM::VLD3DUPqWB_fixed_Asm_8:
6544 case ARM::VLD3DUPqWB_fixed_Asm_16:
6545 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6548 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6549 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6550 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6552 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6554 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6555 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6556 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6557 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6558 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6559 TmpInst.addOperand(Inst.getOperand(4));
6564 case ARM::VLD3DUPdWB_register_Asm_8:
6565 case ARM::VLD3DUPdWB_register_Asm_16:
6566 case ARM::VLD3DUPdWB_register_Asm_32:
6567 case ARM::VLD3DUPqWB_register_Asm_8:
6568 case ARM::VLD3DUPqWB_register_Asm_16:
6569 case ARM::VLD3DUPqWB_register_Asm_32: {
6572 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6573 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6574 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6578 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6579 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6580 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6581 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6582 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6583 TmpInst.addOperand(Inst.getOperand(5));
6588 // VLD3 multiple 3-element structure instructions.
6589 case ARM::VLD3dAsm_8:
6590 case ARM::VLD3dAsm_16:
6591 case ARM::VLD3dAsm_32:
6592 case ARM::VLD3qAsm_8:
6593 case ARM::VLD3qAsm_16:
6594 case ARM::VLD3qAsm_32: {
6597 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6598 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6599 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6601 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6603 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6604 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6605 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6606 TmpInst.addOperand(Inst.getOperand(4));
6611 case ARM::VLD3dWB_fixed_Asm_8:
6612 case ARM::VLD3dWB_fixed_Asm_16:
6613 case ARM::VLD3dWB_fixed_Asm_32:
6614 case ARM::VLD3qWB_fixed_Asm_8:
6615 case ARM::VLD3qWB_fixed_Asm_16:
6616 case ARM::VLD3qWB_fixed_Asm_32: {
6619 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6620 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6625 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6626 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6627 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6628 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6629 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6630 TmpInst.addOperand(Inst.getOperand(4));
6635 case ARM::VLD3dWB_register_Asm_8:
6636 case ARM::VLD3dWB_register_Asm_16:
6637 case ARM::VLD3dWB_register_Asm_32:
6638 case ARM::VLD3qWB_register_Asm_8:
6639 case ARM::VLD3qWB_register_Asm_16:
6640 case ARM::VLD3qWB_register_Asm_32: {
6643 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6644 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6645 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6647 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6649 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6650 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6651 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6652 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6653 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6654 TmpInst.addOperand(Inst.getOperand(5));
6659 // VLD4DUP single 3-element structure to all lanes instructions.
6660 case ARM::VLD4DUPdAsm_8:
6661 case ARM::VLD4DUPdAsm_16:
6662 case ARM::VLD4DUPdAsm_32:
6663 case ARM::VLD4DUPqAsm_8:
6664 case ARM::VLD4DUPqAsm_16:
6665 case ARM::VLD4DUPqAsm_32: {
6668 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6669 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6670 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6672 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6676 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6677 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6678 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6679 TmpInst.addOperand(Inst.getOperand(4));
6684 case ARM::VLD4DUPdWB_fixed_Asm_8:
6685 case ARM::VLD4DUPdWB_fixed_Asm_16:
6686 case ARM::VLD4DUPdWB_fixed_Asm_32:
6687 case ARM::VLD4DUPqWB_fixed_Asm_8:
6688 case ARM::VLD4DUPqWB_fixed_Asm_16:
6689 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6692 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6693 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6694 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6696 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6700 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6701 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6702 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6703 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6704 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6705 TmpInst.addOperand(Inst.getOperand(4));
6710 case ARM::VLD4DUPdWB_register_Asm_8:
6711 case ARM::VLD4DUPdWB_register_Asm_16:
6712 case ARM::VLD4DUPdWB_register_Asm_32:
6713 case ARM::VLD4DUPqWB_register_Asm_8:
6714 case ARM::VLD4DUPqWB_register_Asm_16:
6715 case ARM::VLD4DUPqWB_register_Asm_32: {
6718 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6719 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6720 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6722 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6726 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6727 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6728 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6729 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6730 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6731 TmpInst.addOperand(Inst.getOperand(5));
6736 // VLD4 multiple 4-element structure instructions.
6737 case ARM::VLD4dAsm_8:
6738 case ARM::VLD4dAsm_16:
6739 case ARM::VLD4dAsm_32:
6740 case ARM::VLD4qAsm_8:
6741 case ARM::VLD4qAsm_16:
6742 case ARM::VLD4qAsm_32: {
6745 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6746 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6749 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6751 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6753 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6754 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6755 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6756 TmpInst.addOperand(Inst.getOperand(4));
6761 case ARM::VLD4dWB_fixed_Asm_8:
6762 case ARM::VLD4dWB_fixed_Asm_16:
6763 case ARM::VLD4dWB_fixed_Asm_32:
6764 case ARM::VLD4qWB_fixed_Asm_8:
6765 case ARM::VLD4qWB_fixed_Asm_16:
6766 case ARM::VLD4qWB_fixed_Asm_32: {
6769 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6770 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6771 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6773 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6775 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6777 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6778 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6779 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6780 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6781 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6782 TmpInst.addOperand(Inst.getOperand(4));
6787 case ARM::VLD4dWB_register_Asm_8:
6788 case ARM::VLD4dWB_register_Asm_16:
6789 case ARM::VLD4dWB_register_Asm_32:
6790 case ARM::VLD4qWB_register_Asm_8:
6791 case ARM::VLD4qWB_register_Asm_16:
6792 case ARM::VLD4qWB_register_Asm_32: {
6795 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6796 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6797 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6799 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6801 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6803 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6804 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6805 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6806 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6807 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6808 TmpInst.addOperand(Inst.getOperand(5));
6813 // VST3 multiple 3-element structure instructions.
6814 case ARM::VST3dAsm_8:
6815 case ARM::VST3dAsm_16:
6816 case ARM::VST3dAsm_32:
6817 case ARM::VST3qAsm_8:
6818 case ARM::VST3qAsm_16:
6819 case ARM::VST3qAsm_32: {
6822 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6823 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6824 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6825 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6826 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6828 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6830 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6831 TmpInst.addOperand(Inst.getOperand(4));
6836 case ARM::VST3dWB_fixed_Asm_8:
6837 case ARM::VST3dWB_fixed_Asm_16:
6838 case ARM::VST3dWB_fixed_Asm_32:
6839 case ARM::VST3qWB_fixed_Asm_8:
6840 case ARM::VST3qWB_fixed_Asm_16:
6841 case ARM::VST3qWB_fixed_Asm_32: {
6844 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6845 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6846 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6847 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6848 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6849 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6850 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6852 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6854 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6855 TmpInst.addOperand(Inst.getOperand(4));
6860 case ARM::VST3dWB_register_Asm_8:
6861 case ARM::VST3dWB_register_Asm_16:
6862 case ARM::VST3dWB_register_Asm_32:
6863 case ARM::VST3qWB_register_Asm_8:
6864 case ARM::VST3qWB_register_Asm_16:
6865 case ARM::VST3qWB_register_Asm_32: {
6868 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6869 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6870 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6871 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6872 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6873 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6874 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6876 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6878 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6879 TmpInst.addOperand(Inst.getOperand(5));
6884 // VST4 multiple 3-element structure instructions.
6885 case ARM::VST4dAsm_8:
6886 case ARM::VST4dAsm_16:
6887 case ARM::VST4dAsm_32:
6888 case ARM::VST4qAsm_8:
6889 case ARM::VST4qAsm_16:
6890 case ARM::VST4qAsm_32: {
6893 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6894 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6895 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6896 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6897 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6899 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6901 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6903 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6904 TmpInst.addOperand(Inst.getOperand(4));
6909 case ARM::VST4dWB_fixed_Asm_8:
6910 case ARM::VST4dWB_fixed_Asm_16:
6911 case ARM::VST4dWB_fixed_Asm_32:
6912 case ARM::VST4qWB_fixed_Asm_8:
6913 case ARM::VST4qWB_fixed_Asm_16:
6914 case ARM::VST4qWB_fixed_Asm_32: {
6917 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6918 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6919 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6920 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6921 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6922 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6923 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6925 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6927 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6929 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6930 TmpInst.addOperand(Inst.getOperand(4));
6935 case ARM::VST4dWB_register_Asm_8:
6936 case ARM::VST4dWB_register_Asm_16:
6937 case ARM::VST4dWB_register_Asm_32:
6938 case ARM::VST4qWB_register_Asm_8:
6939 case ARM::VST4qWB_register_Asm_16:
6940 case ARM::VST4qWB_register_Asm_32: {
6943 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6944 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6945 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6946 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6947 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6948 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6949 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6951 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6953 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6955 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6956 TmpInst.addOperand(Inst.getOperand(5));
6961 // Handle encoding choice for the shift-immediate instructions.
6964 case ARM::t2ASRri: {
6965 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6966 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6967 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6968 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6969 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6971 switch (Inst.getOpcode()) {
6972 default: llvm_unreachable("unexpected opcode");
6973 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6974 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6975 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6977 // The Thumb1 operands aren't in the same order. Awesome, eh?
6979 TmpInst.setOpcode(NewOpc);
6980 TmpInst.addOperand(Inst.getOperand(0));
6981 TmpInst.addOperand(Inst.getOperand(5));
6982 TmpInst.addOperand(Inst.getOperand(1));
6983 TmpInst.addOperand(Inst.getOperand(2));
6984 TmpInst.addOperand(Inst.getOperand(3));
6985 TmpInst.addOperand(Inst.getOperand(4));
6992 // Handle the Thumb2 mode MOV complex aliases.
6994 case ARM::t2MOVSsr: {
6995 // Which instruction to expand to depends on the CCOut operand and
6996 // whether we're in an IT block if the register operands are low
6998 bool isNarrow = false;
6999 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7000 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7001 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7002 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7003 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7007 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7008 default: llvm_unreachable("unexpected opcode!");
7009 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7010 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7011 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7012 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7014 TmpInst.setOpcode(newOpc);
7015 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7017 TmpInst.addOperand(MCOperand::CreateReg(
7018 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7019 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7020 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7021 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7022 TmpInst.addOperand(Inst.getOperand(5));
7024 TmpInst.addOperand(MCOperand::CreateReg(
7025 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7030 case ARM::t2MOVSsi: {
7031 // Which instruction to expand to depends on the CCOut operand and
7032 // whether we're in an IT block if the register operands are low
7034 bool isNarrow = false;
7035 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7036 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7037 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7041 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7042 default: llvm_unreachable("unexpected opcode!");
7043 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7044 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7045 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7046 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7047 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7049 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7050 if (Amount == 32) Amount = 0;
7051 TmpInst.setOpcode(newOpc);
7052 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7054 TmpInst.addOperand(MCOperand::CreateReg(
7055 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7056 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7057 if (newOpc != ARM::t2RRX)
7058 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7059 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7060 TmpInst.addOperand(Inst.getOperand(4));
7062 TmpInst.addOperand(MCOperand::CreateReg(
7063 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7067 // Handle the ARM mode MOV complex aliases.
7072 ARM_AM::ShiftOpc ShiftTy;
7073 switch(Inst.getOpcode()) {
7074 default: llvm_unreachable("unexpected opcode!");
7075 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7076 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7077 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7078 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7080 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7082 TmpInst.setOpcode(ARM::MOVsr);
7083 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7084 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7085 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7086 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7087 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7088 TmpInst.addOperand(Inst.getOperand(4));
7089 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7097 ARM_AM::ShiftOpc ShiftTy;
7098 switch(Inst.getOpcode()) {
7099 default: llvm_unreachable("unexpected opcode!");
7100 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7101 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7102 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7103 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7105 // A shift by zero is a plain MOVr, not a MOVsi.
7106 unsigned Amt = Inst.getOperand(2).getImm();
7107 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7108 // A shift by 32 should be encoded as 0 when permitted
7109 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7111 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7113 TmpInst.setOpcode(Opc);
7114 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7115 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7116 if (Opc == ARM::MOVsi)
7117 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7118 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7119 TmpInst.addOperand(Inst.getOperand(4));
7120 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7125 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7127 TmpInst.setOpcode(ARM::MOVsi);
7128 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7129 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7130 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7131 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7132 TmpInst.addOperand(Inst.getOperand(3));
7133 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7137 case ARM::t2LDMIA_UPD: {
7138 // If this is a load of a single register, then we should use
7139 // a post-indexed LDR instruction instead, per the ARM ARM.
7140 if (Inst.getNumOperands() != 5)
7143 TmpInst.setOpcode(ARM::t2LDR_POST);
7144 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7145 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7146 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7147 TmpInst.addOperand(MCOperand::CreateImm(4));
7148 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7149 TmpInst.addOperand(Inst.getOperand(3));
7153 case ARM::t2STMDB_UPD: {
7154 // If this is a store of a single register, then we should use
7155 // a pre-indexed STR instruction instead, per the ARM ARM.
7156 if (Inst.getNumOperands() != 5)
7159 TmpInst.setOpcode(ARM::t2STR_PRE);
7160 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7161 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7162 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7163 TmpInst.addOperand(MCOperand::CreateImm(-4));
7164 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7165 TmpInst.addOperand(Inst.getOperand(3));
7169 case ARM::LDMIA_UPD:
7170 // If this is a load of a single register via a 'pop', then we should use
7171 // a post-indexed LDR instruction instead, per the ARM ARM.
7172 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7173 Inst.getNumOperands() == 5) {
7175 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7176 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7177 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7178 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7179 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7180 TmpInst.addOperand(MCOperand::CreateImm(4));
7181 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7182 TmpInst.addOperand(Inst.getOperand(3));
7187 case ARM::STMDB_UPD:
7188 // If this is a store of a single register via a 'push', then we should use
7189 // a pre-indexed STR instruction instead, per the ARM ARM.
7190 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7191 Inst.getNumOperands() == 5) {
7193 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7194 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7195 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7196 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7197 TmpInst.addOperand(MCOperand::CreateImm(-4));
7198 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7199 TmpInst.addOperand(Inst.getOperand(3));
7203 case ARM::t2ADDri12:
7204 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7205 // mnemonic was used (not "addw"), encoding T3 is preferred.
7206 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7207 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7209 Inst.setOpcode(ARM::t2ADDri);
7210 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7212 case ARM::t2SUBri12:
7213 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7214 // mnemonic was used (not "subw"), encoding T3 is preferred.
7215 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7216 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7218 Inst.setOpcode(ARM::t2SUBri);
7219 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7222 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7223 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7224 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7225 // to encoding T1 if <Rd> is omitted."
7226 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7227 Inst.setOpcode(ARM::tADDi3);
7232 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7233 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7234 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7235 // to encoding T1 if <Rd> is omitted."
7236 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7237 Inst.setOpcode(ARM::tSUBi3);
7242 case ARM::t2SUBri: {
7243 // If the destination and first source operand are the same, and
7244 // the flags are compatible with the current IT status, use encoding T2
7245 // instead of T3. For compatibility with the system 'as'. Make sure the
7246 // wide encoding wasn't explicit.
7247 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7248 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7249 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7250 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7251 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7252 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7253 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7256 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7257 ARM::tADDi8 : ARM::tSUBi8);
7258 TmpInst.addOperand(Inst.getOperand(0));
7259 TmpInst.addOperand(Inst.getOperand(5));
7260 TmpInst.addOperand(Inst.getOperand(0));
7261 TmpInst.addOperand(Inst.getOperand(2));
7262 TmpInst.addOperand(Inst.getOperand(3));
7263 TmpInst.addOperand(Inst.getOperand(4));
7267 case ARM::t2ADDrr: {
7268 // If the destination and first source operand are the same, and
7269 // there's no setting of the flags, use encoding T2 instead of T3.
7270 // Note that this is only for ADD, not SUB. This mirrors the system
7271 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7272 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7273 Inst.getOperand(5).getReg() != 0 ||
7274 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7275 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7278 TmpInst.setOpcode(ARM::tADDhirr);
7279 TmpInst.addOperand(Inst.getOperand(0));
7280 TmpInst.addOperand(Inst.getOperand(0));
7281 TmpInst.addOperand(Inst.getOperand(2));
7282 TmpInst.addOperand(Inst.getOperand(3));
7283 TmpInst.addOperand(Inst.getOperand(4));
7287 case ARM::tADDrSP: {
7288 // If the non-SP source operand and the destination operand are not the
7289 // same, we need to use the 32-bit encoding if it's available.
7290 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7291 Inst.setOpcode(ARM::t2ADDrr);
7292 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7298 // A Thumb conditional branch outside of an IT block is a tBcc.
7299 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7300 Inst.setOpcode(ARM::tBcc);
7305 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7306 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7307 Inst.setOpcode(ARM::t2Bcc);
7312 // If the conditional is AL or we're in an IT block, we really want t2B.
7313 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7314 Inst.setOpcode(ARM::t2B);
7319 // If the conditional is AL, we really want tB.
7320 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7321 Inst.setOpcode(ARM::tB);
7326 // If the register list contains any high registers, or if the writeback
7327 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7328 // instead if we're in Thumb2. Otherwise, this should have generated
7329 // an error in validateInstruction().
7330 unsigned Rn = Inst.getOperand(0).getReg();
7331 bool hasWritebackToken =
7332 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7333 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7334 bool listContainsBase;
7335 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7336 (!listContainsBase && !hasWritebackToken) ||
7337 (listContainsBase && hasWritebackToken)) {
7338 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7339 assert (isThumbTwo());
7340 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7341 // If we're switching to the updating version, we need to insert
7342 // the writeback tied operand.
7343 if (hasWritebackToken)
7344 Inst.insert(Inst.begin(),
7345 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7350 case ARM::tSTMIA_UPD: {
7351 // If the register list contains any high registers, we need to use
7352 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7353 // should have generated an error in validateInstruction().
7354 unsigned Rn = Inst.getOperand(0).getReg();
7355 bool listContainsBase;
7356 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7357 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7358 assert (isThumbTwo());
7359 Inst.setOpcode(ARM::t2STMIA_UPD);
7365 bool listContainsBase;
7366 // If the register list contains any high registers, we need to use
7367 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7368 // should have generated an error in validateInstruction().
7369 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7371 assert (isThumbTwo());
7372 Inst.setOpcode(ARM::t2LDMIA_UPD);
7373 // Add the base register and writeback operands.
7374 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7375 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7379 bool listContainsBase;
7380 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7382 assert (isThumbTwo());
7383 Inst.setOpcode(ARM::t2STMDB_UPD);
7384 // Add the base register and writeback operands.
7385 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7386 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7390 // If we can use the 16-bit encoding and the user didn't explicitly
7391 // request the 32-bit variant, transform it here.
7392 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7393 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7394 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7395 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7396 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7397 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7398 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7399 // The operands aren't in the same order for tMOVi8...
7401 TmpInst.setOpcode(ARM::tMOVi8);
7402 TmpInst.addOperand(Inst.getOperand(0));
7403 TmpInst.addOperand(Inst.getOperand(4));
7404 TmpInst.addOperand(Inst.getOperand(1));
7405 TmpInst.addOperand(Inst.getOperand(2));
7406 TmpInst.addOperand(Inst.getOperand(3));
7413 // If we can use the 16-bit encoding and the user didn't explicitly
7414 // request the 32-bit variant, transform it here.
7415 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7416 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7417 Inst.getOperand(2).getImm() == ARMCC::AL &&
7418 Inst.getOperand(4).getReg() == ARM::CPSR &&
7419 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7420 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7421 // The operands aren't the same for tMOV[S]r... (no cc_out)
7423 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7424 TmpInst.addOperand(Inst.getOperand(0));
7425 TmpInst.addOperand(Inst.getOperand(1));
7426 TmpInst.addOperand(Inst.getOperand(2));
7427 TmpInst.addOperand(Inst.getOperand(3));
7437 // If we can use the 16-bit encoding and the user didn't explicitly
7438 // request the 32-bit variant, transform it here.
7439 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7440 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7441 Inst.getOperand(2).getImm() == 0 &&
7442 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7443 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7445 switch (Inst.getOpcode()) {
7446 default: llvm_unreachable("Illegal opcode!");
7447 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7448 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7449 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7450 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7452 // The operands aren't the same for thumb1 (no rotate operand).
7454 TmpInst.setOpcode(NewOpc);
7455 TmpInst.addOperand(Inst.getOperand(0));
7456 TmpInst.addOperand(Inst.getOperand(1));
7457 TmpInst.addOperand(Inst.getOperand(3));
7458 TmpInst.addOperand(Inst.getOperand(4));
7465 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7466 // rrx shifts and asr/lsr of #32 is encoded as 0
7467 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7469 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7470 // Shifting by zero is accepted as a vanilla 'MOVr'
7472 TmpInst.setOpcode(ARM::MOVr);
7473 TmpInst.addOperand(Inst.getOperand(0));
7474 TmpInst.addOperand(Inst.getOperand(1));
7475 TmpInst.addOperand(Inst.getOperand(3));
7476 TmpInst.addOperand(Inst.getOperand(4));
7477 TmpInst.addOperand(Inst.getOperand(5));
7490 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7491 if (SOpc == ARM_AM::rrx) return false;
7492 switch (Inst.getOpcode()) {
7493 default: llvm_unreachable("unexpected opcode!");
7494 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7495 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7496 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7497 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7498 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7499 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7501 // If the shift is by zero, use the non-shifted instruction definition.
7502 // The exception is for right shifts, where 0 == 32
7503 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7504 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7506 TmpInst.setOpcode(newOpc);
7507 TmpInst.addOperand(Inst.getOperand(0));
7508 TmpInst.addOperand(Inst.getOperand(1));
7509 TmpInst.addOperand(Inst.getOperand(2));
7510 TmpInst.addOperand(Inst.getOperand(4));
7511 TmpInst.addOperand(Inst.getOperand(5));
7512 TmpInst.addOperand(Inst.getOperand(6));
7520 // The mask bits for all but the first condition are represented as
7521 // the low bit of the condition code value implies 't'. We currently
7522 // always have 1 implies 't', so XOR toggle the bits if the low bit
7523 // of the condition code is zero.
7524 MCOperand &MO = Inst.getOperand(1);
7525 unsigned Mask = MO.getImm();
7526 unsigned OrigMask = Mask;
7527 unsigned TZ = countTrailingZeros(Mask);
7528 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7529 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7530 Mask ^= (0xE << TZ) & 0xF;
7534 // Set up the IT block state according to the IT instruction we just
7536 assert(!inITBlock() && "nested IT blocks?!");
7537 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7538 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7539 ITState.CurPosition = 0;
7540 ITState.FirstCond = true;
7550 // Assemblers should use the narrow encodings of these instructions when permissible.
7551 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7552 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7553 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7554 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7555 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7556 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7557 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7559 switch (Inst.getOpcode()) {
7560 default: llvm_unreachable("unexpected opcode");
7561 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7562 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7563 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7564 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7565 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7566 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7569 TmpInst.setOpcode(NewOpc);
7570 TmpInst.addOperand(Inst.getOperand(0));
7571 TmpInst.addOperand(Inst.getOperand(5));
7572 TmpInst.addOperand(Inst.getOperand(1));
7573 TmpInst.addOperand(Inst.getOperand(2));
7574 TmpInst.addOperand(Inst.getOperand(3));
7575 TmpInst.addOperand(Inst.getOperand(4));
7586 // Assemblers should use the narrow encodings of these instructions when permissible.
7587 // These instructions are special in that they are commutable, so shorter encodings
7588 // are available more often.
7589 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7590 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7591 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7592 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7593 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7594 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7595 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7596 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7598 switch (Inst.getOpcode()) {
7599 default: llvm_unreachable("unexpected opcode");
7600 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7601 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7602 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7603 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7606 TmpInst.setOpcode(NewOpc);
7607 TmpInst.addOperand(Inst.getOperand(0));
7608 TmpInst.addOperand(Inst.getOperand(5));
7609 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7610 TmpInst.addOperand(Inst.getOperand(1));
7611 TmpInst.addOperand(Inst.getOperand(2));
7613 TmpInst.addOperand(Inst.getOperand(2));
7614 TmpInst.addOperand(Inst.getOperand(1));
7616 TmpInst.addOperand(Inst.getOperand(3));
7617 TmpInst.addOperand(Inst.getOperand(4));
7627 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7628 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7629 // suffix depending on whether they're in an IT block or not.
7630 unsigned Opc = Inst.getOpcode();
7631 const MCInstrDesc &MCID = getInstDesc(Opc);
7632 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7633 assert(MCID.hasOptionalDef() &&
7634 "optionally flag setting instruction missing optional def operand");
7635 assert(MCID.NumOperands == Inst.getNumOperands() &&
7636 "operand count mismatch!");
7637 // Find the optional-def operand (cc_out).
7640 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7643 // If we're parsing Thumb1, reject it completely.
7644 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7645 return Match_MnemonicFail;
7646 // If we're parsing Thumb2, which form is legal depends on whether we're
7648 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7650 return Match_RequiresITBlock;
7651 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7653 return Match_RequiresNotITBlock;
7655 // Some high-register supporting Thumb1 encodings only allow both registers
7656 // to be from r0-r7 when in Thumb2.
7657 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7658 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7659 isARMLowRegister(Inst.getOperand(2).getReg()))
7660 return Match_RequiresThumb2;
7661 // Others only require ARMv6 or later.
7662 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7663 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7664 isARMLowRegister(Inst.getOperand(1).getReg()))
7665 return Match_RequiresV6;
7666 return Match_Success;
7669 static const char *getSubtargetFeatureName(unsigned Val);
7671 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7672 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7673 MCStreamer &Out, unsigned &ErrorInfo,
7674 bool MatchingInlineAsm) {
7676 unsigned MatchResult;
7678 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7680 switch (MatchResult) {
7683 // Context sensitive operand constraints aren't handled by the matcher,
7684 // so check them here.
7685 if (validateInstruction(Inst, Operands)) {
7686 // Still progress the IT block, otherwise one wrong condition causes
7687 // nasty cascading errors.
7688 forwardITPosition();
7692 // Some instructions need post-processing to, for example, tweak which
7693 // encoding is selected. Loop on it while changes happen so the
7694 // individual transformations can chain off each other. E.g.,
7695 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7696 while (processInstruction(Inst, Operands))
7699 // Only move forward at the very end so that everything in validate
7700 // and process gets a consistent answer about whether we're in an IT
7702 forwardITPosition();
7704 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7705 // doesn't actually encode.
7706 if (Inst.getOpcode() == ARM::ITasm)
7710 Out.EmitInstruction(Inst);
7712 case Match_MissingFeature: {
7713 assert(ErrorInfo && "Unknown missing feature!");
7714 // Special case the error message for the very common case where only
7715 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7716 std::string Msg = "instruction requires:";
7718 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7719 if (ErrorInfo & Mask) {
7721 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7725 return Error(IDLoc, Msg);
7727 case Match_InvalidOperand: {
7728 SMLoc ErrorLoc = IDLoc;
7729 if (ErrorInfo != ~0U) {
7730 if (ErrorInfo >= Operands.size())
7731 return Error(IDLoc, "too few operands for instruction");
7733 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7734 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7737 return Error(ErrorLoc, "invalid operand for instruction");
7739 case Match_MnemonicFail:
7740 return Error(IDLoc, "invalid instruction",
7741 ((ARMOperand*)Operands[0])->getLocRange());
7742 case Match_RequiresNotITBlock:
7743 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7744 case Match_RequiresITBlock:
7745 return Error(IDLoc, "instruction only valid inside IT block");
7746 case Match_RequiresV6:
7747 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7748 case Match_RequiresThumb2:
7749 return Error(IDLoc, "instruction variant requires Thumb2");
7750 case Match_ImmRange0_4: {
7751 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7752 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7753 return Error(ErrorLoc, "immediate operand must be in the range [0,4]");
7755 case Match_ImmRange0_15: {
7756 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7757 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7758 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7762 llvm_unreachable("Implement any new match types added!");
7765 /// parseDirective parses the arm specific directives
7766 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7767 StringRef IDVal = DirectiveID.getIdentifier();
7768 if (IDVal == ".word")
7769 return parseDirectiveWord(4, DirectiveID.getLoc());
7770 else if (IDVal == ".thumb")
7771 return parseDirectiveThumb(DirectiveID.getLoc());
7772 else if (IDVal == ".arm")
7773 return parseDirectiveARM(DirectiveID.getLoc());
7774 else if (IDVal == ".thumb_func")
7775 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7776 else if (IDVal == ".code")
7777 return parseDirectiveCode(DirectiveID.getLoc());
7778 else if (IDVal == ".syntax")
7779 return parseDirectiveSyntax(DirectiveID.getLoc());
7780 else if (IDVal == ".unreq")
7781 return parseDirectiveUnreq(DirectiveID.getLoc());
7782 else if (IDVal == ".arch")
7783 return parseDirectiveArch(DirectiveID.getLoc());
7784 else if (IDVal == ".eabi_attribute")
7785 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7786 else if (IDVal == ".fnstart")
7787 return parseDirectiveFnStart(DirectiveID.getLoc());
7788 else if (IDVal == ".fnend")
7789 return parseDirectiveFnEnd(DirectiveID.getLoc());
7790 else if (IDVal == ".cantunwind")
7791 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7792 else if (IDVal == ".personality")
7793 return parseDirectivePersonality(DirectiveID.getLoc());
7794 else if (IDVal == ".handlerdata")
7795 return parseDirectiveHandlerData(DirectiveID.getLoc());
7796 else if (IDVal == ".setfp")
7797 return parseDirectiveSetFP(DirectiveID.getLoc());
7798 else if (IDVal == ".pad")
7799 return parseDirectivePad(DirectiveID.getLoc());
7800 else if (IDVal == ".save")
7801 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7802 else if (IDVal == ".vsave")
7803 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7807 /// parseDirectiveWord
7808 /// ::= .word [ expression (, expression)* ]
7809 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7810 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7812 const MCExpr *Value;
7813 if (getParser().parseExpression(Value))
7816 getParser().getStreamer().EmitValue(Value, Size);
7818 if (getLexer().is(AsmToken::EndOfStatement))
7821 // FIXME: Improve diagnostic.
7822 if (getLexer().isNot(AsmToken::Comma))
7823 return Error(L, "unexpected token in directive");
7832 /// parseDirectiveThumb
7834 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7835 if (getLexer().isNot(AsmToken::EndOfStatement))
7836 return Error(L, "unexpected token in directive");
7840 return Error(L, "target does not support Thumb mode");
7844 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7848 /// parseDirectiveARM
7850 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7851 if (getLexer().isNot(AsmToken::EndOfStatement))
7852 return Error(L, "unexpected token in directive");
7856 return Error(L, "target does not support ARM mode");
7860 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7864 /// parseDirectiveThumbFunc
7865 /// ::= .thumbfunc symbol_name
7866 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7867 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7868 bool isMachO = MAI->hasSubsectionsViaSymbols();
7870 bool needFuncName = true;
7872 // Darwin asm has (optionally) function name after .thumb_func direction
7875 const AsmToken &Tok = Parser.getTok();
7876 if (Tok.isNot(AsmToken::EndOfStatement)) {
7877 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7878 return Error(L, "unexpected token in .thumb_func directive");
7879 Name = Tok.getIdentifier();
7880 Parser.Lex(); // Consume the identifier token.
7881 needFuncName = false;
7885 if (getLexer().isNot(AsmToken::EndOfStatement))
7886 return Error(L, "unexpected token in directive");
7888 // Eat the end of statement and any blank lines that follow.
7889 while (getLexer().is(AsmToken::EndOfStatement))
7892 // FIXME: assuming function name will be the line following .thumb_func
7893 // We really should be checking the next symbol definition even if there's
7894 // stuff in between.
7896 Name = Parser.getTok().getIdentifier();
7899 // Mark symbol as a thumb symbol.
7900 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7901 getParser().getStreamer().EmitThumbFunc(Func);
7905 /// parseDirectiveSyntax
7906 /// ::= .syntax unified | divided
7907 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
7908 const AsmToken &Tok = Parser.getTok();
7909 if (Tok.isNot(AsmToken::Identifier))
7910 return Error(L, "unexpected token in .syntax directive");
7911 StringRef Mode = Tok.getString();
7912 if (Mode == "unified" || Mode == "UNIFIED")
7914 else if (Mode == "divided" || Mode == "DIVIDED")
7915 return Error(L, "'.syntax divided' arm asssembly not supported");
7917 return Error(L, "unrecognized syntax mode in .syntax directive");
7919 if (getLexer().isNot(AsmToken::EndOfStatement))
7920 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7923 // TODO tell the MC streamer the mode
7924 // getParser().getStreamer().Emit???();
7928 /// parseDirectiveCode
7929 /// ::= .code 16 | 32
7930 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
7931 const AsmToken &Tok = Parser.getTok();
7932 if (Tok.isNot(AsmToken::Integer))
7933 return Error(L, "unexpected token in .code directive");
7934 int64_t Val = Parser.getTok().getIntVal();
7940 return Error(L, "invalid operand to .code directive");
7942 if (getLexer().isNot(AsmToken::EndOfStatement))
7943 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
7948 return Error(L, "target does not support Thumb mode");
7952 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7955 return Error(L, "target does not support ARM mode");
7959 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7965 /// parseDirectiveReq
7966 /// ::= name .req registername
7967 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7968 Parser.Lex(); // Eat the '.req' token.
7970 SMLoc SRegLoc, ERegLoc;
7971 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7972 Parser.eatToEndOfStatement();
7973 return Error(SRegLoc, "register name expected");
7976 // Shouldn't be anything else.
7977 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7978 Parser.eatToEndOfStatement();
7979 return Error(Parser.getTok().getLoc(),
7980 "unexpected input in .req directive.");
7983 Parser.Lex(); // Consume the EndOfStatement
7985 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7986 return Error(SRegLoc, "redefinition of '" + Name +
7987 "' does not match original.");
7992 /// parseDirectiveUneq
7993 /// ::= .unreq registername
7994 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7995 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7996 Parser.eatToEndOfStatement();
7997 return Error(L, "unexpected input in .unreq directive.");
7999 RegisterReqs.erase(Parser.getTok().getIdentifier());
8000 Parser.Lex(); // Eat the identifier.
8004 /// parseDirectiveArch
8006 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8010 /// parseDirectiveEabiAttr
8011 /// ::= .eabi_attribute int, int
8012 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8016 /// parseDirectiveFnStart
8018 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8019 if (FnStartLoc.isValid()) {
8020 Error(L, ".fnstart starts before the end of previous one");
8021 Error(FnStartLoc, "previous .fnstart starts here");
8026 getParser().getStreamer().EmitFnStart();
8030 /// parseDirectiveFnEnd
8032 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8033 // Check the ordering of unwind directives
8034 if (!FnStartLoc.isValid())
8035 return Error(L, ".fnstart must precede .fnend directive");
8037 // Reset the unwind directives parser state
8038 resetUnwindDirectiveParserState();
8040 getParser().getStreamer().EmitFnEnd();
8044 /// parseDirectiveCantUnwind
8046 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8047 // Check the ordering of unwind directives
8049 if (!FnStartLoc.isValid())
8050 return Error(L, ".fnstart must precede .cantunwind directive");
8051 if (HandlerDataLoc.isValid()) {
8052 Error(L, ".cantunwind can't be used with .handlerdata directive");
8053 Error(HandlerDataLoc, ".handlerdata was specified here");
8056 if (PersonalityLoc.isValid()) {
8057 Error(L, ".cantunwind can't be used with .personality directive");
8058 Error(PersonalityLoc, ".personality was specified here");
8062 getParser().getStreamer().EmitCantUnwind();
8066 /// parseDirectivePersonality
8067 /// ::= .personality name
8068 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8069 // Check the ordering of unwind directives
8071 if (!FnStartLoc.isValid())
8072 return Error(L, ".fnstart must precede .personality directive");
8073 if (CantUnwindLoc.isValid()) {
8074 Error(L, ".personality can't be used with .cantunwind directive");
8075 Error(CantUnwindLoc, ".cantunwind was specified here");
8078 if (HandlerDataLoc.isValid()) {
8079 Error(L, ".personality must precede .handlerdata directive");
8080 Error(HandlerDataLoc, ".handlerdata was specified here");
8084 // Parse the name of the personality routine
8085 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8086 Parser.eatToEndOfStatement();
8087 return Error(L, "unexpected input in .personality directive.");
8089 StringRef Name(Parser.getTok().getIdentifier());
8092 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8093 getParser().getStreamer().EmitPersonality(PR);
8097 /// parseDirectiveHandlerData
8098 /// ::= .handlerdata
8099 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8100 // Check the ordering of unwind directives
8102 if (!FnStartLoc.isValid())
8103 return Error(L, ".fnstart must precede .personality directive");
8104 if (CantUnwindLoc.isValid()) {
8105 Error(L, ".handlerdata can't be used with .cantunwind directive");
8106 Error(CantUnwindLoc, ".cantunwind was specified here");
8110 getParser().getStreamer().EmitHandlerData();
8114 /// parseDirectiveSetFP
8115 /// ::= .setfp fpreg, spreg [, offset]
8116 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8117 // Check the ordering of unwind directives
8118 if (!FnStartLoc.isValid())
8119 return Error(L, ".fnstart must precede .setfp directive");
8120 if (HandlerDataLoc.isValid())
8121 return Error(L, ".setfp must precede .handlerdata directive");
8124 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8125 int NewFPReg = tryParseRegister();
8127 return Error(NewFPRegLoc, "frame pointer register expected");
8130 if (!Parser.getTok().is(AsmToken::Comma))
8131 return Error(Parser.getTok().getLoc(), "comma expected");
8132 Parser.Lex(); // skip comma
8135 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8136 int NewSPReg = tryParseRegister();
8138 return Error(NewSPRegLoc, "stack pointer register expected");
8140 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8141 return Error(NewSPRegLoc,
8142 "register should be either $sp or the latest fp register");
8144 // Update the frame pointer register
8149 if (Parser.getTok().is(AsmToken::Comma)) {
8150 Parser.Lex(); // skip comma
8152 if (Parser.getTok().isNot(AsmToken::Hash) &&
8153 Parser.getTok().isNot(AsmToken::Dollar)) {
8154 return Error(Parser.getTok().getLoc(), "'#' expected");
8156 Parser.Lex(); // skip hash token.
8158 const MCExpr *OffsetExpr;
8159 SMLoc ExLoc = Parser.getTok().getLoc();
8161 if (getParser().parseExpression(OffsetExpr, EndLoc))
8162 return Error(ExLoc, "malformed setfp offset");
8163 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8165 return Error(ExLoc, "setfp offset must be an immediate");
8167 Offset = CE->getValue();
8170 getParser().getStreamer().EmitSetFP(static_cast<unsigned>(NewFPReg),
8171 static_cast<unsigned>(NewSPReg),
8178 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8179 // Check the ordering of unwind directives
8180 if (!FnStartLoc.isValid())
8181 return Error(L, ".fnstart must precede .pad directive");
8182 if (HandlerDataLoc.isValid())
8183 return Error(L, ".pad must precede .handlerdata directive");
8186 if (Parser.getTok().isNot(AsmToken::Hash) &&
8187 Parser.getTok().isNot(AsmToken::Dollar)) {
8188 return Error(Parser.getTok().getLoc(), "'#' expected");
8190 Parser.Lex(); // skip hash token.
8192 const MCExpr *OffsetExpr;
8193 SMLoc ExLoc = Parser.getTok().getLoc();
8195 if (getParser().parseExpression(OffsetExpr, EndLoc))
8196 return Error(ExLoc, "malformed pad offset");
8197 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8199 return Error(ExLoc, "pad offset must be an immediate");
8201 getParser().getStreamer().EmitPad(CE->getValue());
8205 /// parseDirectiveRegSave
8206 /// ::= .save { registers }
8207 /// ::= .vsave { registers }
8208 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8209 // Check the ordering of unwind directives
8210 if (!FnStartLoc.isValid())
8211 return Error(L, ".fnstart must precede .save or .vsave directives");
8212 if (HandlerDataLoc.isValid())
8213 return Error(L, ".save or .vsave must precede .handlerdata directive");
8215 // Parse the register list
8216 SmallVector<MCParsedAsmOperand*, 1> Operands;
8217 if (parseRegisterList(Operands))
8219 ARMOperand *Op = (ARMOperand*)Operands[0];
8220 if (!IsVector && !Op->isRegList())
8221 return Error(L, ".save expects GPR registers");
8222 if (IsVector && !Op->isDPRRegList())
8223 return Error(L, ".vsave expects DPR registers");
8225 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8229 /// Force static initialization.
8230 extern "C" void LLVMInitializeARMAsmParser() {
8231 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8232 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8235 #define GET_REGISTER_MATCHER
8236 #define GET_SUBTARGET_FEATURE_NAME
8237 #define GET_MATCHER_IMPLEMENTATION
8238 #include "ARMGenAsmMatcher.inc"
8240 // Define this matcher function after the auto-generated include so we
8241 // have the match class enum definitions.
8242 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8244 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8245 // If the kind is a token for a literal immediate, check if our asm
8246 // operand matches. This is for InstAliases which have a fixed-value
8247 // immediate in the syntax.
8248 if (Kind == MCK__35_0 && Op->isImm()) {
8249 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8251 return Match_InvalidOperand;
8252 if (CE->getValue() == 0)
8253 return Match_Success;
8255 return Match_InvalidOperand;