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 "ARMFPUName.h"
11 #include "ARMFeatures.h"
12 #include "MCTargetDesc/ARMAddressingModes.h"
13 #include "MCTargetDesc/ARMArchName.h"
14 #include "MCTargetDesc/ARMBaseInfo.h"
15 #include "MCTargetDesc/ARMMCExpr.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/ADT/Twine.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCAssembler.h"
23 #include "llvm/MC/MCContext.h"
24 #include "llvm/MC/MCDisassembler.h"
25 #include "llvm/MC/MCELFStreamer.h"
26 #include "llvm/MC/MCExpr.h"
27 #include "llvm/MC/MCInst.h"
28 #include "llvm/MC/MCInstrDesc.h"
29 #include "llvm/MC/MCInstrInfo.h"
30 #include "llvm/MC/MCObjectFileInfo.h"
31 #include "llvm/MC/MCParser/MCAsmLexer.h"
32 #include "llvm/MC/MCParser/MCAsmParser.h"
33 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
34 #include "llvm/MC/MCRegisterInfo.h"
35 #include "llvm/MC/MCSection.h"
36 #include "llvm/MC/MCStreamer.h"
37 #include "llvm/MC/MCSubtargetInfo.h"
38 #include "llvm/MC/MCSymbol.h"
39 #include "llvm/MC/MCTargetAsmParser.h"
40 #include "llvm/Support/ARMBuildAttributes.h"
41 #include "llvm/Support/ARMEHABI.h"
42 #include "llvm/Support/COFF.h"
43 #include "llvm/Support/Debug.h"
44 #include "llvm/Support/ELF.h"
45 #include "llvm/Support/MathExtras.h"
46 #include "llvm/Support/SourceMgr.h"
47 #include "llvm/Support/TargetRegistry.h"
48 #include "llvm/Support/raw_ostream.h"
56 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
61 typedef SmallVector<SMLoc, 4> Locs;
66 Locs PersonalityIndexLocs;
71 UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {}
73 bool hasFnStart() const { return !FnStartLocs.empty(); }
74 bool cantUnwind() const { return !CantUnwindLocs.empty(); }
75 bool hasHandlerData() const { return !HandlerDataLocs.empty(); }
76 bool hasPersonality() const {
77 return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty());
80 void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); }
81 void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); }
82 void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); }
83 void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); }
84 void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); }
86 void saveFPReg(int Reg) { FPReg = Reg; }
87 int getFPReg() const { return FPReg; }
89 void emitFnStartLocNotes() const {
90 for (Locs::const_iterator FI = FnStartLocs.begin(), FE = FnStartLocs.end();
92 Parser.Note(*FI, ".fnstart was specified here");
94 void emitCantUnwindLocNotes() const {
95 for (Locs::const_iterator UI = CantUnwindLocs.begin(),
96 UE = CantUnwindLocs.end(); UI != UE; ++UI)
97 Parser.Note(*UI, ".cantunwind was specified here");
99 void emitHandlerDataLocNotes() const {
100 for (Locs::const_iterator HI = HandlerDataLocs.begin(),
101 HE = HandlerDataLocs.end(); HI != HE; ++HI)
102 Parser.Note(*HI, ".handlerdata was specified here");
104 void emitPersonalityLocNotes() const {
105 for (Locs::const_iterator PI = PersonalityLocs.begin(),
106 PE = PersonalityLocs.end(),
107 PII = PersonalityIndexLocs.begin(),
108 PIE = PersonalityIndexLocs.end();
109 PI != PE || PII != PIE;) {
110 if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer()))
111 Parser.Note(*PI++, ".personality was specified here");
112 else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer()))
113 Parser.Note(*PII++, ".personalityindex was specified here");
115 llvm_unreachable(".personality and .personalityindex cannot be "
116 "at the same location");
121 FnStartLocs = Locs();
122 CantUnwindLocs = Locs();
123 PersonalityLocs = Locs();
124 HandlerDataLocs = Locs();
125 PersonalityIndexLocs = Locs();
130 class ARMAsmParser : public MCTargetAsmParser {
131 MCSubtargetInfo &STI;
132 const MCInstrInfo &MII;
133 const MCRegisterInfo *MRI;
136 ARMTargetStreamer &getTargetStreamer() {
137 assert(getParser().getStreamer().getTargetStreamer() &&
138 "do not have a target streamer");
139 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
140 return static_cast<ARMTargetStreamer &>(TS);
143 // Map of register aliases registers via the .req directive.
144 StringMap<unsigned> RegisterReqs;
146 bool NextSymbolIsThumb;
149 ARMCC::CondCodes Cond; // Condition for IT block.
150 unsigned Mask:4; // Condition mask for instructions.
151 // Starting at first 1 (from lsb).
152 // '1' condition as indicated in IT.
153 // '0' inverse of condition (else).
154 // Count of instructions in IT block is
155 // 4 - trailingzeroes(mask)
157 bool FirstCond; // Explicit flag for when we're parsing the
158 // First instruction in the IT block. It's
159 // implied in the mask, so needs special
162 unsigned CurPosition; // Current position in parsing of IT
163 // block. In range [0,3]. Initialized
164 // according to count of instructions in block.
165 // ~0U if no active IT block.
167 bool inITBlock() { return ITState.CurPosition != ~0U; }
168 bool lastInITBlock() {
169 return ITState.CurPosition == 4 - countTrailingZeros(ITState.Mask);
171 void forwardITPosition() {
172 if (!inITBlock()) return;
173 // Move to the next instruction in the IT block, if there is one. If not,
174 // mark the block as done.
175 unsigned TZ = countTrailingZeros(ITState.Mask);
176 if (++ITState.CurPosition == 5 - TZ)
177 ITState.CurPosition = ~0U; // Done with the IT block after this.
180 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
181 return getParser().Note(L, Msg, Ranges);
183 bool Warning(SMLoc L, const Twine &Msg,
184 ArrayRef<SMRange> Ranges = None) {
185 return getParser().Warning(L, Msg, Ranges);
187 bool Error(SMLoc L, const Twine &Msg,
188 ArrayRef<SMRange> Ranges = None) {
189 return getParser().Error(L, Msg, Ranges);
192 bool validatetLDMRegList(MCInst Inst, const OperandVector &Operands,
193 unsigned ListNo, bool IsPop = false);
194 bool validatetSTMRegList(MCInst Inst, const OperandVector &Operands,
197 int tryParseRegister();
198 bool tryParseRegisterWithWriteBack(OperandVector &);
199 int tryParseShiftRegister(OperandVector &);
200 bool parseRegisterList(OperandVector &);
201 bool parseMemory(OperandVector &);
202 bool parseOperand(OperandVector &, StringRef Mnemonic);
203 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
204 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
205 unsigned &ShiftAmount);
206 bool parseLiteralValues(unsigned Size, SMLoc L);
207 bool parseDirectiveThumb(SMLoc L);
208 bool parseDirectiveARM(SMLoc L);
209 bool parseDirectiveThumbFunc(SMLoc L);
210 bool parseDirectiveCode(SMLoc L);
211 bool parseDirectiveSyntax(SMLoc L);
212 bool parseDirectiveReq(StringRef Name, SMLoc L);
213 bool parseDirectiveUnreq(SMLoc L);
214 bool parseDirectiveArch(SMLoc L);
215 bool parseDirectiveEabiAttr(SMLoc L);
216 bool parseDirectiveCPU(SMLoc L);
217 bool parseDirectiveFPU(SMLoc L);
218 bool parseDirectiveFnStart(SMLoc L);
219 bool parseDirectiveFnEnd(SMLoc L);
220 bool parseDirectiveCantUnwind(SMLoc L);
221 bool parseDirectivePersonality(SMLoc L);
222 bool parseDirectiveHandlerData(SMLoc L);
223 bool parseDirectiveSetFP(SMLoc L);
224 bool parseDirectivePad(SMLoc L);
225 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
226 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
227 bool parseDirectiveLtorg(SMLoc L);
228 bool parseDirectiveEven(SMLoc L);
229 bool parseDirectivePersonalityIndex(SMLoc L);
230 bool parseDirectiveUnwindRaw(SMLoc L);
231 bool parseDirectiveTLSDescSeq(SMLoc L);
232 bool parseDirectiveMovSP(SMLoc L);
233 bool parseDirectiveObjectArch(SMLoc L);
234 bool parseDirectiveArchExtension(SMLoc L);
235 bool parseDirectiveAlign(SMLoc L);
236 bool parseDirectiveThumbSet(SMLoc L);
238 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
239 bool &CarrySetting, unsigned &ProcessorIMod,
241 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
242 bool &CanAcceptCarrySet,
243 bool &CanAcceptPredicationCode);
245 bool isThumb() const {
246 // FIXME: Can tablegen auto-generate this?
247 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
249 bool isThumbOne() const {
250 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
252 bool isThumbTwo() const {
253 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
255 bool hasThumb() const {
256 return STI.getFeatureBits() & ARM::HasV4TOps;
258 bool hasV6Ops() const {
259 return STI.getFeatureBits() & ARM::HasV6Ops;
261 bool hasV6MOps() const {
262 return STI.getFeatureBits() & ARM::HasV6MOps;
264 bool hasV7Ops() const {
265 return STI.getFeatureBits() & ARM::HasV7Ops;
267 bool hasV8Ops() const {
268 return STI.getFeatureBits() & ARM::HasV8Ops;
270 bool hasARM() const {
271 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
273 bool hasThumb2DSP() const {
274 return STI.getFeatureBits() & ARM::FeatureDSPThumb2;
276 bool hasD16() const {
277 return STI.getFeatureBits() & ARM::FeatureD16;
281 uint64_t FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
282 setAvailableFeatures(FB);
284 bool isMClass() const {
285 return STI.getFeatureBits() & ARM::FeatureMClass;
288 /// @name Auto-generated Match Functions
291 #define GET_ASSEMBLER_HEADER
292 #include "ARMGenAsmMatcher.inc"
296 OperandMatchResultTy parseITCondCode(OperandVector &);
297 OperandMatchResultTy parseCoprocNumOperand(OperandVector &);
298 OperandMatchResultTy parseCoprocRegOperand(OperandVector &);
299 OperandMatchResultTy parseCoprocOptionOperand(OperandVector &);
300 OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &);
301 OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &);
302 OperandMatchResultTy parseProcIFlagsOperand(OperandVector &);
303 OperandMatchResultTy parseMSRMaskOperand(OperandVector &);
304 OperandMatchResultTy parseBankedRegOperand(OperandVector &);
305 OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low,
307 OperandMatchResultTy parsePKHLSLImm(OperandVector &O) {
308 return parsePKHImm(O, "lsl", 0, 31);
310 OperandMatchResultTy parsePKHASRImm(OperandVector &O) {
311 return parsePKHImm(O, "asr", 1, 32);
313 OperandMatchResultTy parseSetEndImm(OperandVector &);
314 OperandMatchResultTy parseShifterImm(OperandVector &);
315 OperandMatchResultTy parseRotImm(OperandVector &);
316 OperandMatchResultTy parseModImm(OperandVector &);
317 OperandMatchResultTy parseBitfield(OperandVector &);
318 OperandMatchResultTy parsePostIdxReg(OperandVector &);
319 OperandMatchResultTy parseAM3Offset(OperandVector &);
320 OperandMatchResultTy parseFPImm(OperandVector &);
321 OperandMatchResultTy parseVectorList(OperandVector &);
322 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
325 // Asm Match Converter Methods
326 void cvtThumbMultiply(MCInst &Inst, const OperandVector &);
327 void cvtThumbBranches(MCInst &Inst, const OperandVector &);
329 bool validateInstruction(MCInst &Inst, const OperandVector &Ops);
330 bool processInstruction(MCInst &Inst, const OperandVector &Ops, MCStreamer &Out);
331 bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands);
332 bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands);
335 enum ARMMatchResultTy {
336 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
337 Match_RequiresNotITBlock,
339 Match_RequiresThumb2,
340 #define GET_OPERAND_DIAGNOSTIC_TYPES
341 #include "ARMGenAsmMatcher.inc"
345 ARMAsmParser(MCSubtargetInfo & _STI, MCAsmParser & _Parser,
346 const MCInstrInfo &MII, const MCTargetOptions &Options)
347 : MCTargetAsmParser(), STI(_STI), MII(MII), UC(_Parser) {
348 MCAsmParserExtension::Initialize(_Parser);
350 // Cache the MCRegisterInfo.
351 MRI = getContext().getRegisterInfo();
353 // Initialize the set of available features.
354 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
356 // Not in an ITBlock to start with.
357 ITState.CurPosition = ~0U;
359 NextSymbolIsThumb = false;
362 // Implementation of the MCTargetAsmParser interface:
363 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
364 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
365 SMLoc NameLoc, OperandVector &Operands) override;
366 bool ParseDirective(AsmToken DirectiveID) override;
368 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
369 unsigned Kind) override;
370 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
372 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
373 OperandVector &Operands, MCStreamer &Out,
375 bool MatchingInlineAsm) override;
376 void onLabelParsed(MCSymbol *Symbol) override;
378 } // end anonymous namespace
382 /// ARMOperand - Instances of this class represent a parsed ARM machine
384 class ARMOperand : public MCParsedAsmOperand {
394 k_InstSyncBarrierOpt,
406 k_VectorListAllLanes,
413 k_BitfieldDescriptor,
417 SMLoc StartLoc, EndLoc, AlignmentLoc;
418 SmallVector<unsigned, 8> Registers;
421 ARMCC::CondCodes Val;
428 struct CoprocOptionOp {
441 ARM_ISB::InstSyncBOpt Val;
445 ARM_PROC::IFlags Val;
465 // A vector register list is a sequential list of 1 to 4 registers.
466 struct VectorListOp {
473 struct VectorIndexOp {
481 /// Combined record for all forms of ARM address expressions.
484 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
486 const MCConstantExpr *OffsetImm; // Offset immediate value
487 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
488 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
489 unsigned ShiftImm; // shift for OffsetReg.
490 unsigned Alignment; // 0 = no alignment specified
491 // n = alignment in bytes (2, 4, 8, 16, or 32)
492 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
495 struct PostIdxRegOp {
498 ARM_AM::ShiftOpc ShiftTy;
502 struct ShifterImmOp {
507 struct RegShiftedRegOp {
508 ARM_AM::ShiftOpc ShiftTy;
514 struct RegShiftedImmOp {
515 ARM_AM::ShiftOpc ShiftTy;
537 struct CoprocOptionOp CoprocOption;
538 struct MBOptOp MBOpt;
539 struct ISBOptOp ISBOpt;
540 struct ITMaskOp ITMask;
541 struct IFlagsOp IFlags;
542 struct MMaskOp MMask;
543 struct BankedRegOp BankedReg;
546 struct VectorListOp VectorList;
547 struct VectorIndexOp VectorIndex;
549 struct MemoryOp Memory;
550 struct PostIdxRegOp PostIdxReg;
551 struct ShifterImmOp ShifterImm;
552 struct RegShiftedRegOp RegShiftedReg;
553 struct RegShiftedImmOp RegShiftedImm;
554 struct RotImmOp RotImm;
555 struct ModImmOp ModImm;
556 struct BitfieldOp Bitfield;
560 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
561 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
563 StartLoc = o.StartLoc;
580 case k_DPRRegisterList:
581 case k_SPRRegisterList:
582 Registers = o.Registers;
585 case k_VectorListAllLanes:
586 case k_VectorListIndexed:
587 VectorList = o.VectorList;
594 CoprocOption = o.CoprocOption;
599 case k_MemBarrierOpt:
602 case k_InstSyncBarrierOpt:
607 case k_PostIndexRegister:
608 PostIdxReg = o.PostIdxReg;
614 BankedReg = o.BankedReg;
619 case k_ShifterImmediate:
620 ShifterImm = o.ShifterImm;
622 case k_ShiftedRegister:
623 RegShiftedReg = o.RegShiftedReg;
625 case k_ShiftedImmediate:
626 RegShiftedImm = o.RegShiftedImm;
628 case k_RotateImmediate:
631 case k_ModifiedImmediate:
634 case k_BitfieldDescriptor:
635 Bitfield = o.Bitfield;
638 VectorIndex = o.VectorIndex;
643 /// getStartLoc - Get the location of the first token of this operand.
644 SMLoc getStartLoc() const override { return StartLoc; }
645 /// getEndLoc - Get the location of the last token of this operand.
646 SMLoc getEndLoc() const override { return EndLoc; }
647 /// getLocRange - Get the range between the first and last token of this
649 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
651 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
652 SMLoc getAlignmentLoc() const {
653 assert(Kind == k_Memory && "Invalid access!");
657 ARMCC::CondCodes getCondCode() const {
658 assert(Kind == k_CondCode && "Invalid access!");
662 unsigned getCoproc() const {
663 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
667 StringRef getToken() const {
668 assert(Kind == k_Token && "Invalid access!");
669 return StringRef(Tok.Data, Tok.Length);
672 unsigned getReg() const override {
673 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
677 const SmallVectorImpl<unsigned> &getRegList() const {
678 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
679 Kind == k_SPRRegisterList) && "Invalid access!");
683 const MCExpr *getImm() const {
684 assert(isImm() && "Invalid access!");
688 unsigned getVectorIndex() const {
689 assert(Kind == k_VectorIndex && "Invalid access!");
690 return VectorIndex.Val;
693 ARM_MB::MemBOpt getMemBarrierOpt() const {
694 assert(Kind == k_MemBarrierOpt && "Invalid access!");
698 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
699 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
703 ARM_PROC::IFlags getProcIFlags() const {
704 assert(Kind == k_ProcIFlags && "Invalid access!");
708 unsigned getMSRMask() const {
709 assert(Kind == k_MSRMask && "Invalid access!");
713 unsigned getBankedReg() const {
714 assert(Kind == k_BankedReg && "Invalid access!");
715 return BankedReg.Val;
718 bool isCoprocNum() const { return Kind == k_CoprocNum; }
719 bool isCoprocReg() const { return Kind == k_CoprocReg; }
720 bool isCoprocOption() const { return Kind == k_CoprocOption; }
721 bool isCondCode() const { return Kind == k_CondCode; }
722 bool isCCOut() const { return Kind == k_CCOut; }
723 bool isITMask() const { return Kind == k_ITCondMask; }
724 bool isITCondCode() const { return Kind == k_CondCode; }
725 bool isImm() const override { return Kind == k_Immediate; }
726 // checks whether this operand is an unsigned offset which fits is a field
727 // of specified width and scaled by a specific number of bits
728 template<unsigned width, unsigned scale>
729 bool isUnsignedOffset() const {
730 if (!isImm()) return false;
731 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
732 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
733 int64_t Val = CE->getValue();
734 int64_t Align = 1LL << scale;
735 int64_t Max = Align * ((1LL << width) - 1);
736 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
740 // checks whether this operand is an signed offset which fits is a field
741 // of specified width and scaled by a specific number of bits
742 template<unsigned width, unsigned scale>
743 bool isSignedOffset() const {
744 if (!isImm()) return false;
745 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
746 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
747 int64_t Val = CE->getValue();
748 int64_t Align = 1LL << scale;
749 int64_t Max = Align * ((1LL << (width-1)) - 1);
750 int64_t Min = -Align * (1LL << (width-1));
751 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
756 // checks whether this operand is a memory operand computed as an offset
757 // applied to PC. the offset may have 8 bits of magnitude and is represented
758 // with two bits of shift. textually it may be either [pc, #imm], #imm or
759 // relocable expression...
760 bool isThumbMemPC() const {
763 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
764 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
765 if (!CE) return false;
766 Val = CE->getValue();
769 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
770 if(Memory.BaseRegNum != ARM::PC) return false;
771 Val = Memory.OffsetImm->getValue();
774 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
776 bool isFPImm() const {
777 if (!isImm()) return false;
778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
779 if (!CE) return false;
780 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
783 bool isFBits16() const {
784 if (!isImm()) return false;
785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
786 if (!CE) return false;
787 int64_t Value = CE->getValue();
788 return Value >= 0 && Value <= 16;
790 bool isFBits32() const {
791 if (!isImm()) return false;
792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
793 if (!CE) return false;
794 int64_t Value = CE->getValue();
795 return Value >= 1 && Value <= 32;
797 bool isImm8s4() const {
798 if (!isImm()) return false;
799 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
800 if (!CE) return false;
801 int64_t Value = CE->getValue();
802 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
804 bool isImm0_1020s4() const {
805 if (!isImm()) return false;
806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
807 if (!CE) return false;
808 int64_t Value = CE->getValue();
809 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
811 bool isImm0_508s4() const {
812 if (!isImm()) return false;
813 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
814 if (!CE) return false;
815 int64_t Value = CE->getValue();
816 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
818 bool isImm0_508s4Neg() const {
819 if (!isImm()) return false;
820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
821 if (!CE) return false;
822 int64_t Value = -CE->getValue();
823 // explicitly exclude zero. we want that to use the normal 0_508 version.
824 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
826 bool isImm0_239() const {
827 if (!isImm()) return false;
828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
829 if (!CE) return false;
830 int64_t Value = CE->getValue();
831 return Value >= 0 && Value < 240;
833 bool isImm0_255() const {
834 if (!isImm()) return false;
835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
836 if (!CE) return false;
837 int64_t Value = CE->getValue();
838 return Value >= 0 && Value < 256;
840 bool isImm0_4095() const {
841 if (!isImm()) return false;
842 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
843 if (!CE) return false;
844 int64_t Value = CE->getValue();
845 return Value >= 0 && Value < 4096;
847 bool isImm0_4095Neg() const {
848 if (!isImm()) return false;
849 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
850 if (!CE) return false;
851 int64_t Value = -CE->getValue();
852 return Value > 0 && Value < 4096;
854 bool isImm0_1() const {
855 if (!isImm()) return false;
856 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
857 if (!CE) return false;
858 int64_t Value = CE->getValue();
859 return Value >= 0 && Value < 2;
861 bool isImm0_3() const {
862 if (!isImm()) return false;
863 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
864 if (!CE) return false;
865 int64_t Value = CE->getValue();
866 return Value >= 0 && Value < 4;
868 bool isImm0_7() const {
869 if (!isImm()) return false;
870 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
871 if (!CE) return false;
872 int64_t Value = CE->getValue();
873 return Value >= 0 && Value < 8;
875 bool isImm0_15() const {
876 if (!isImm()) return false;
877 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
878 if (!CE) return false;
879 int64_t Value = CE->getValue();
880 return Value >= 0 && Value < 16;
882 bool isImm0_31() const {
883 if (!isImm()) return false;
884 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
885 if (!CE) return false;
886 int64_t Value = CE->getValue();
887 return Value >= 0 && Value < 32;
889 bool isImm0_63() const {
890 if (!isImm()) return false;
891 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
892 if (!CE) return false;
893 int64_t Value = CE->getValue();
894 return Value >= 0 && Value < 64;
896 bool isImm8() const {
897 if (!isImm()) return false;
898 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
899 if (!CE) return false;
900 int64_t Value = CE->getValue();
903 bool isImm16() const {
904 if (!isImm()) return false;
905 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
906 if (!CE) return false;
907 int64_t Value = CE->getValue();
910 bool isImm32() const {
911 if (!isImm()) return false;
912 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
913 if (!CE) return false;
914 int64_t Value = CE->getValue();
917 bool isShrImm8() 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 Value > 0 && Value <= 8;
924 bool isShrImm16() 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 Value > 0 && Value <= 16;
931 bool isShrImm32() 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 return Value > 0 && Value <= 32;
938 bool isShrImm64() const {
939 if (!isImm()) return false;
940 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
941 if (!CE) return false;
942 int64_t Value = CE->getValue();
943 return Value > 0 && Value <= 64;
945 bool isImm1_7() const {
946 if (!isImm()) return false;
947 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
948 if (!CE) return false;
949 int64_t Value = CE->getValue();
950 return Value > 0 && Value < 8;
952 bool isImm1_15() const {
953 if (!isImm()) return false;
954 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
955 if (!CE) return false;
956 int64_t Value = CE->getValue();
957 return Value > 0 && Value < 16;
959 bool isImm1_31() const {
960 if (!isImm()) return false;
961 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
962 if (!CE) return false;
963 int64_t Value = CE->getValue();
964 return Value > 0 && Value < 32;
966 bool isImm1_16() const {
967 if (!isImm()) return false;
968 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
969 if (!CE) return false;
970 int64_t Value = CE->getValue();
971 return Value > 0 && Value < 17;
973 bool isImm1_32() const {
974 if (!isImm()) return false;
975 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
976 if (!CE) return false;
977 int64_t Value = CE->getValue();
978 return Value > 0 && Value < 33;
980 bool isImm0_32() const {
981 if (!isImm()) return false;
982 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
983 if (!CE) return false;
984 int64_t Value = CE->getValue();
985 return Value >= 0 && Value < 33;
987 bool isImm0_65535() const {
988 if (!isImm()) return false;
989 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
990 if (!CE) return false;
991 int64_t Value = CE->getValue();
992 return Value >= 0 && Value < 65536;
994 bool isImm256_65535Expr() const {
995 if (!isImm()) return false;
996 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
997 // If it's not a constant expression, it'll generate a fixup and be
999 if (!CE) return true;
1000 int64_t Value = CE->getValue();
1001 return Value >= 256 && Value < 65536;
1003 bool isImm0_65535Expr() const {
1004 if (!isImm()) return false;
1005 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1006 // If it's not a constant expression, it'll generate a fixup and be
1008 if (!CE) return true;
1009 int64_t Value = CE->getValue();
1010 return Value >= 0 && Value < 65536;
1012 bool isImm24bit() const {
1013 if (!isImm()) return false;
1014 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1015 if (!CE) return false;
1016 int64_t Value = CE->getValue();
1017 return Value >= 0 && Value <= 0xffffff;
1019 bool isImmThumbSR() const {
1020 if (!isImm()) return false;
1021 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1022 if (!CE) return false;
1023 int64_t Value = CE->getValue();
1024 return Value > 0 && Value < 33;
1026 bool isPKHLSLImm() const {
1027 if (!isImm()) return false;
1028 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1029 if (!CE) return false;
1030 int64_t Value = CE->getValue();
1031 return Value >= 0 && Value < 32;
1033 bool isPKHASRImm() const {
1034 if (!isImm()) return false;
1035 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1036 if (!CE) return false;
1037 int64_t Value = CE->getValue();
1038 return Value > 0 && Value <= 32;
1040 bool isAdrLabel() const {
1041 // If we have an immediate that's not a constant, treat it as a label
1042 // reference needing a fixup. If it is a constant, but it can't fit
1043 // into shift immediate encoding, we reject it.
1044 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1045 else return (isARMSOImm() || isARMSOImmNeg());
1047 bool isARMSOImm() const {
1048 if (!isImm()) return false;
1049 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1050 if (!CE) return false;
1051 int64_t Value = CE->getValue();
1052 return ARM_AM::getSOImmVal(Value) != -1;
1054 bool isARMSOImmNot() const {
1055 if (!isImm()) return false;
1056 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1057 if (!CE) return false;
1058 int64_t Value = CE->getValue();
1059 return ARM_AM::getSOImmVal(~Value) != -1;
1061 bool isARMSOImmNeg() const {
1062 if (!isImm()) return false;
1063 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1064 if (!CE) return false;
1065 int64_t Value = CE->getValue();
1066 // Only use this when not representable as a plain so_imm.
1067 return ARM_AM::getSOImmVal(Value) == -1 &&
1068 ARM_AM::getSOImmVal(-Value) != -1;
1070 bool isT2SOImm() const {
1071 if (!isImm()) return false;
1072 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1073 if (!CE) return false;
1074 int64_t Value = CE->getValue();
1075 return ARM_AM::getT2SOImmVal(Value) != -1;
1077 bool isT2SOImmNot() const {
1078 if (!isImm()) return false;
1079 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1080 if (!CE) return false;
1081 int64_t Value = CE->getValue();
1082 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1083 ARM_AM::getT2SOImmVal(~Value) != -1;
1085 bool isT2SOImmNeg() const {
1086 if (!isImm()) return false;
1087 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1088 if (!CE) return false;
1089 int64_t Value = CE->getValue();
1090 // Only use this when not representable as a plain so_imm.
1091 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1092 ARM_AM::getT2SOImmVal(-Value) != -1;
1094 bool isSetEndImm() const {
1095 if (!isImm()) return false;
1096 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1097 if (!CE) return false;
1098 int64_t Value = CE->getValue();
1099 return Value == 1 || Value == 0;
1101 bool isReg() const override { return Kind == k_Register; }
1102 bool isRegList() const { return Kind == k_RegisterList; }
1103 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1104 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
1105 bool isToken() const override { return Kind == k_Token; }
1106 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
1107 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
1108 bool isMem() const override { return Kind == k_Memory; }
1109 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1110 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1111 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1112 bool isRotImm() const { return Kind == k_RotateImmediate; }
1113 bool isModImm() const { return Kind == k_ModifiedImmediate; }
1114 bool isModImmNot() const {
1115 if (!isImm()) return false;
1116 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1117 if (!CE) return false;
1118 int64_t Value = CE->getValue();
1119 return ARM_AM::getSOImmVal(~Value) != -1;
1121 bool isModImmNeg() const {
1122 if (!isImm()) return false;
1123 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1124 if (!CE) return false;
1125 int64_t Value = CE->getValue();
1126 return ARM_AM::getSOImmVal(Value) == -1 &&
1127 ARM_AM::getSOImmVal(-Value) != -1;
1129 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1130 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
1131 bool isPostIdxReg() const {
1132 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
1134 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
1137 // No offset of any kind.
1138 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
1139 (alignOK || Memory.Alignment == Alignment);
1141 bool isMemPCRelImm12() const {
1142 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1144 // Base register must be PC.
1145 if (Memory.BaseRegNum != ARM::PC)
1147 // Immediate offset in range [-4095, 4095].
1148 if (!Memory.OffsetImm) return true;
1149 int64_t Val = Memory.OffsetImm->getValue();
1150 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1152 bool isAlignedMemory() const {
1153 return isMemNoOffset(true);
1155 bool isAlignedMemoryNone() const {
1156 return isMemNoOffset(false, 0);
1158 bool isDupAlignedMemoryNone() const {
1159 return isMemNoOffset(false, 0);
1161 bool isAlignedMemory16() const {
1162 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1164 return isMemNoOffset(false, 0);
1166 bool isDupAlignedMemory16() const {
1167 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1169 return isMemNoOffset(false, 0);
1171 bool isAlignedMemory32() const {
1172 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1174 return isMemNoOffset(false, 0);
1176 bool isDupAlignedMemory32() const {
1177 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1179 return isMemNoOffset(false, 0);
1181 bool isAlignedMemory64() const {
1182 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1184 return isMemNoOffset(false, 0);
1186 bool isDupAlignedMemory64() const {
1187 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1189 return isMemNoOffset(false, 0);
1191 bool isAlignedMemory64or128() const {
1192 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1194 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1196 return isMemNoOffset(false, 0);
1198 bool isDupAlignedMemory64or128() const {
1199 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1201 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1203 return isMemNoOffset(false, 0);
1205 bool isAlignedMemory64or128or256() const {
1206 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1208 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1210 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1212 return isMemNoOffset(false, 0);
1214 bool isAddrMode2() const {
1215 if (!isMem() || Memory.Alignment != 0) return false;
1216 // Check for register offset.
1217 if (Memory.OffsetRegNum) return true;
1218 // Immediate offset in range [-4095, 4095].
1219 if (!Memory.OffsetImm) return true;
1220 int64_t Val = Memory.OffsetImm->getValue();
1221 return Val > -4096 && Val < 4096;
1223 bool isAM2OffsetImm() const {
1224 if (!isImm()) return false;
1225 // Immediate offset in range [-4095, 4095].
1226 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1227 if (!CE) return false;
1228 int64_t Val = CE->getValue();
1229 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1231 bool isAddrMode3() const {
1232 // If we have an immediate that's not a constant, treat it as a label
1233 // reference needing a fixup. If it is a constant, it's something else
1234 // and we reject it.
1235 if (isImm() && !isa<MCConstantExpr>(getImm()))
1237 if (!isMem() || Memory.Alignment != 0) return false;
1238 // No shifts are legal for AM3.
1239 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1240 // Check for register offset.
1241 if (Memory.OffsetRegNum) return true;
1242 // Immediate offset in range [-255, 255].
1243 if (!Memory.OffsetImm) return true;
1244 int64_t Val = Memory.OffsetImm->getValue();
1245 // The #-0 offset is encoded as INT32_MIN, and we have to check
1247 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1249 bool isAM3Offset() const {
1250 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1252 if (Kind == k_PostIndexRegister)
1253 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1254 // Immediate offset in range [-255, 255].
1255 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1256 if (!CE) return false;
1257 int64_t Val = CE->getValue();
1258 // Special case, #-0 is INT32_MIN.
1259 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1261 bool isAddrMode5() const {
1262 // If we have an immediate that's not a constant, treat it as a label
1263 // reference needing a fixup. If it is a constant, it's something else
1264 // and we reject it.
1265 if (isImm() && !isa<MCConstantExpr>(getImm()))
1267 if (!isMem() || Memory.Alignment != 0) return false;
1268 // Check for register offset.
1269 if (Memory.OffsetRegNum) return false;
1270 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1271 if (!Memory.OffsetImm) return true;
1272 int64_t Val = Memory.OffsetImm->getValue();
1273 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1276 bool isMemTBB() const {
1277 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1278 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1282 bool isMemTBH() const {
1283 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1284 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1285 Memory.Alignment != 0 )
1289 bool isMemRegOffset() const {
1290 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1294 bool isT2MemRegOffset() const {
1295 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1296 Memory.Alignment != 0)
1298 // Only lsl #{0, 1, 2, 3} allowed.
1299 if (Memory.ShiftType == ARM_AM::no_shift)
1301 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1305 bool isMemThumbRR() const {
1306 // Thumb reg+reg addressing is simple. Just two registers, a base and
1307 // an offset. No shifts, negations or any other complicating factors.
1308 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1309 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1311 return isARMLowRegister(Memory.BaseRegNum) &&
1312 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1314 bool isMemThumbRIs4() const {
1315 if (!isMem() || Memory.OffsetRegNum != 0 ||
1316 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1318 // Immediate offset, multiple of 4 in range [0, 124].
1319 if (!Memory.OffsetImm) return true;
1320 int64_t Val = Memory.OffsetImm->getValue();
1321 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1323 bool isMemThumbRIs2() const {
1324 if (!isMem() || Memory.OffsetRegNum != 0 ||
1325 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1327 // Immediate offset, multiple of 4 in range [0, 62].
1328 if (!Memory.OffsetImm) return true;
1329 int64_t Val = Memory.OffsetImm->getValue();
1330 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1332 bool isMemThumbRIs1() const {
1333 if (!isMem() || Memory.OffsetRegNum != 0 ||
1334 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1336 // Immediate offset in range [0, 31].
1337 if (!Memory.OffsetImm) return true;
1338 int64_t Val = Memory.OffsetImm->getValue();
1339 return Val >= 0 && Val <= 31;
1341 bool isMemThumbSPI() const {
1342 if (!isMem() || Memory.OffsetRegNum != 0 ||
1343 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1345 // Immediate offset, multiple of 4 in range [0, 1020].
1346 if (!Memory.OffsetImm) return true;
1347 int64_t Val = Memory.OffsetImm->getValue();
1348 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1350 bool isMemImm8s4Offset() const {
1351 // If we have an immediate that's not a constant, treat it as a label
1352 // reference needing a fixup. If it is a constant, it's something else
1353 // and we reject it.
1354 if (isImm() && !isa<MCConstantExpr>(getImm()))
1356 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1358 // Immediate offset a multiple of 4 in range [-1020, 1020].
1359 if (!Memory.OffsetImm) return true;
1360 int64_t Val = Memory.OffsetImm->getValue();
1361 // Special case, #-0 is INT32_MIN.
1362 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1364 bool isMemImm0_1020s4Offset() const {
1365 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1367 // Immediate offset a multiple of 4 in range [0, 1020].
1368 if (!Memory.OffsetImm) return true;
1369 int64_t Val = Memory.OffsetImm->getValue();
1370 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1372 bool isMemImm8Offset() const {
1373 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1375 // Base reg of PC isn't allowed for these encodings.
1376 if (Memory.BaseRegNum == ARM::PC) return false;
1377 // Immediate offset in range [-255, 255].
1378 if (!Memory.OffsetImm) return true;
1379 int64_t Val = Memory.OffsetImm->getValue();
1380 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1382 bool isMemPosImm8Offset() const {
1383 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1385 // Immediate offset in range [0, 255].
1386 if (!Memory.OffsetImm) return true;
1387 int64_t Val = Memory.OffsetImm->getValue();
1388 return Val >= 0 && Val < 256;
1390 bool isMemNegImm8Offset() const {
1391 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1393 // Base reg of PC isn't allowed for these encodings.
1394 if (Memory.BaseRegNum == ARM::PC) return false;
1395 // Immediate offset in range [-255, -1].
1396 if (!Memory.OffsetImm) return false;
1397 int64_t Val = Memory.OffsetImm->getValue();
1398 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1400 bool isMemUImm12Offset() const {
1401 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1403 // Immediate offset in range [0, 4095].
1404 if (!Memory.OffsetImm) return true;
1405 int64_t Val = Memory.OffsetImm->getValue();
1406 return (Val >= 0 && Val < 4096);
1408 bool isMemImm12Offset() const {
1409 // If we have an immediate that's not a constant, treat it as a label
1410 // reference needing a fixup. If it is a constant, it's something else
1411 // and we reject it.
1412 if (isImm() && !isa<MCConstantExpr>(getImm()))
1415 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1417 // Immediate offset in range [-4095, 4095].
1418 if (!Memory.OffsetImm) return true;
1419 int64_t Val = Memory.OffsetImm->getValue();
1420 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1422 bool isPostIdxImm8() const {
1423 if (!isImm()) return false;
1424 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1425 if (!CE) return false;
1426 int64_t Val = CE->getValue();
1427 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1429 bool isPostIdxImm8s4() const {
1430 if (!isImm()) return false;
1431 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1432 if (!CE) return false;
1433 int64_t Val = CE->getValue();
1434 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1438 bool isMSRMask() const { return Kind == k_MSRMask; }
1439 bool isBankedReg() const { return Kind == k_BankedReg; }
1440 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1443 bool isSingleSpacedVectorList() const {
1444 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1446 bool isDoubleSpacedVectorList() const {
1447 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1449 bool isVecListOneD() const {
1450 if (!isSingleSpacedVectorList()) return false;
1451 return VectorList.Count == 1;
1454 bool isVecListDPair() const {
1455 if (!isSingleSpacedVectorList()) return false;
1456 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1457 .contains(VectorList.RegNum));
1460 bool isVecListThreeD() const {
1461 if (!isSingleSpacedVectorList()) return false;
1462 return VectorList.Count == 3;
1465 bool isVecListFourD() const {
1466 if (!isSingleSpacedVectorList()) return false;
1467 return VectorList.Count == 4;
1470 bool isVecListDPairSpaced() const {
1471 if (Kind != k_VectorList) return false;
1472 if (isSingleSpacedVectorList()) return false;
1473 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1474 .contains(VectorList.RegNum));
1477 bool isVecListThreeQ() const {
1478 if (!isDoubleSpacedVectorList()) return false;
1479 return VectorList.Count == 3;
1482 bool isVecListFourQ() const {
1483 if (!isDoubleSpacedVectorList()) return false;
1484 return VectorList.Count == 4;
1487 bool isSingleSpacedVectorAllLanes() const {
1488 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1490 bool isDoubleSpacedVectorAllLanes() const {
1491 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1493 bool isVecListOneDAllLanes() const {
1494 if (!isSingleSpacedVectorAllLanes()) return false;
1495 return VectorList.Count == 1;
1498 bool isVecListDPairAllLanes() const {
1499 if (!isSingleSpacedVectorAllLanes()) return false;
1500 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1501 .contains(VectorList.RegNum));
1504 bool isVecListDPairSpacedAllLanes() const {
1505 if (!isDoubleSpacedVectorAllLanes()) return false;
1506 return VectorList.Count == 2;
1509 bool isVecListThreeDAllLanes() const {
1510 if (!isSingleSpacedVectorAllLanes()) return false;
1511 return VectorList.Count == 3;
1514 bool isVecListThreeQAllLanes() const {
1515 if (!isDoubleSpacedVectorAllLanes()) return false;
1516 return VectorList.Count == 3;
1519 bool isVecListFourDAllLanes() const {
1520 if (!isSingleSpacedVectorAllLanes()) return false;
1521 return VectorList.Count == 4;
1524 bool isVecListFourQAllLanes() const {
1525 if (!isDoubleSpacedVectorAllLanes()) return false;
1526 return VectorList.Count == 4;
1529 bool isSingleSpacedVectorIndexed() const {
1530 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1532 bool isDoubleSpacedVectorIndexed() const {
1533 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1535 bool isVecListOneDByteIndexed() const {
1536 if (!isSingleSpacedVectorIndexed()) return false;
1537 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1540 bool isVecListOneDHWordIndexed() const {
1541 if (!isSingleSpacedVectorIndexed()) return false;
1542 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1545 bool isVecListOneDWordIndexed() const {
1546 if (!isSingleSpacedVectorIndexed()) return false;
1547 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1550 bool isVecListTwoDByteIndexed() const {
1551 if (!isSingleSpacedVectorIndexed()) return false;
1552 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1555 bool isVecListTwoDHWordIndexed() const {
1556 if (!isSingleSpacedVectorIndexed()) return false;
1557 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1560 bool isVecListTwoQWordIndexed() const {
1561 if (!isDoubleSpacedVectorIndexed()) return false;
1562 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1565 bool isVecListTwoQHWordIndexed() const {
1566 if (!isDoubleSpacedVectorIndexed()) return false;
1567 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1570 bool isVecListTwoDWordIndexed() const {
1571 if (!isSingleSpacedVectorIndexed()) return false;
1572 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1575 bool isVecListThreeDByteIndexed() const {
1576 if (!isSingleSpacedVectorIndexed()) return false;
1577 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1580 bool isVecListThreeDHWordIndexed() const {
1581 if (!isSingleSpacedVectorIndexed()) return false;
1582 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1585 bool isVecListThreeQWordIndexed() const {
1586 if (!isDoubleSpacedVectorIndexed()) return false;
1587 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1590 bool isVecListThreeQHWordIndexed() const {
1591 if (!isDoubleSpacedVectorIndexed()) return false;
1592 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1595 bool isVecListThreeDWordIndexed() const {
1596 if (!isSingleSpacedVectorIndexed()) return false;
1597 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1600 bool isVecListFourDByteIndexed() const {
1601 if (!isSingleSpacedVectorIndexed()) return false;
1602 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1605 bool isVecListFourDHWordIndexed() const {
1606 if (!isSingleSpacedVectorIndexed()) return false;
1607 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1610 bool isVecListFourQWordIndexed() const {
1611 if (!isDoubleSpacedVectorIndexed()) return false;
1612 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1615 bool isVecListFourQHWordIndexed() const {
1616 if (!isDoubleSpacedVectorIndexed()) return false;
1617 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1620 bool isVecListFourDWordIndexed() const {
1621 if (!isSingleSpacedVectorIndexed()) return false;
1622 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1625 bool isVectorIndex8() const {
1626 if (Kind != k_VectorIndex) return false;
1627 return VectorIndex.Val < 8;
1629 bool isVectorIndex16() const {
1630 if (Kind != k_VectorIndex) return false;
1631 return VectorIndex.Val < 4;
1633 bool isVectorIndex32() const {
1634 if (Kind != k_VectorIndex) return false;
1635 return VectorIndex.Val < 2;
1638 bool isNEONi8splat() const {
1639 if (!isImm()) return false;
1640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1641 // Must be a constant.
1642 if (!CE) return false;
1643 int64_t Value = CE->getValue();
1644 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1646 return Value >= 0 && Value < 256;
1649 bool isNEONi16splat() const {
1650 if (isNEONByteReplicate(2))
1651 return false; // Leave that for bytes replication and forbid by default.
1654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1655 // Must be a constant.
1656 if (!CE) return false;
1657 unsigned Value = CE->getValue();
1658 return ARM_AM::isNEONi16splat(Value);
1661 bool isNEONi16splatNot() const {
1664 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1665 // Must be a constant.
1666 if (!CE) return false;
1667 unsigned Value = CE->getValue();
1668 return ARM_AM::isNEONi16splat(~Value & 0xffff);
1671 bool isNEONi32splat() const {
1672 if (isNEONByteReplicate(4))
1673 return false; // Leave that for bytes replication and forbid by default.
1676 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1677 // Must be a constant.
1678 if (!CE) return false;
1679 unsigned Value = CE->getValue();
1680 return ARM_AM::isNEONi32splat(Value);
1683 bool isNEONi32splatNot() const {
1686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1687 // Must be a constant.
1688 if (!CE) return false;
1689 unsigned Value = CE->getValue();
1690 return ARM_AM::isNEONi32splat(~Value);
1693 bool isNEONByteReplicate(unsigned NumBytes) const {
1696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1697 // Must be a constant.
1700 int64_t Value = CE->getValue();
1702 return false; // Don't bother with zero.
1704 unsigned char B = Value & 0xff;
1705 for (unsigned i = 1; i < NumBytes; ++i) {
1707 if ((Value & 0xff) != B)
1712 bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); }
1713 bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); }
1714 bool isNEONi32vmov() const {
1715 if (isNEONByteReplicate(4))
1716 return false; // Let it to be classified as byte-replicate case.
1719 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1720 // Must be a constant.
1723 int64_t Value = CE->getValue();
1724 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1725 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1726 // FIXME: This is probably wrong and a copy and paste from previous example
1727 return (Value >= 0 && Value < 256) ||
1728 (Value >= 0x0100 && Value <= 0xff00) ||
1729 (Value >= 0x010000 && Value <= 0xff0000) ||
1730 (Value >= 0x01000000 && Value <= 0xff000000) ||
1731 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1732 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1734 bool isNEONi32vmovNeg() const {
1735 if (!isImm()) return false;
1736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1737 // Must be a constant.
1738 if (!CE) return false;
1739 int64_t Value = ~CE->getValue();
1740 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1741 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1742 // FIXME: This is probably wrong and a copy and paste from previous example
1743 return (Value >= 0 && Value < 256) ||
1744 (Value >= 0x0100 && Value <= 0xff00) ||
1745 (Value >= 0x010000 && Value <= 0xff0000) ||
1746 (Value >= 0x01000000 && Value <= 0xff000000) ||
1747 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1748 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1751 bool isNEONi64splat() const {
1752 if (!isImm()) return false;
1753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1754 // Must be a constant.
1755 if (!CE) return false;
1756 uint64_t Value = CE->getValue();
1757 // i64 value with each byte being either 0 or 0xff.
1758 for (unsigned i = 0; i < 8; ++i)
1759 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1763 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1764 // Add as immediates when possible. Null MCExpr = 0.
1766 Inst.addOperand(MCOperand::CreateImm(0));
1767 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1768 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1770 Inst.addOperand(MCOperand::CreateExpr(Expr));
1773 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1774 assert(N == 2 && "Invalid number of operands!");
1775 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1776 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1777 Inst.addOperand(MCOperand::CreateReg(RegNum));
1780 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1781 assert(N == 1 && "Invalid number of operands!");
1782 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1785 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1786 assert(N == 1 && "Invalid number of operands!");
1787 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1790 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1791 assert(N == 1 && "Invalid number of operands!");
1792 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1795 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1796 assert(N == 1 && "Invalid number of operands!");
1797 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1800 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1801 assert(N == 1 && "Invalid number of operands!");
1802 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1805 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1806 assert(N == 1 && "Invalid number of operands!");
1807 Inst.addOperand(MCOperand::CreateReg(getReg()));
1810 void addRegOperands(MCInst &Inst, unsigned N) const {
1811 assert(N == 1 && "Invalid number of operands!");
1812 Inst.addOperand(MCOperand::CreateReg(getReg()));
1815 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1816 assert(N == 3 && "Invalid number of operands!");
1817 assert(isRegShiftedReg() &&
1818 "addRegShiftedRegOperands() on non-RegShiftedReg!");
1819 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1820 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1821 Inst.addOperand(MCOperand::CreateImm(
1822 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1825 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1826 assert(N == 2 && "Invalid number of operands!");
1827 assert(isRegShiftedImm() &&
1828 "addRegShiftedImmOperands() on non-RegShiftedImm!");
1829 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1830 // Shift of #32 is encoded as 0 where permitted
1831 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1832 Inst.addOperand(MCOperand::CreateImm(
1833 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1836 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1837 assert(N == 1 && "Invalid number of operands!");
1838 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1842 void addRegListOperands(MCInst &Inst, unsigned N) const {
1843 assert(N == 1 && "Invalid number of operands!");
1844 const SmallVectorImpl<unsigned> &RegList = getRegList();
1845 for (SmallVectorImpl<unsigned>::const_iterator
1846 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1847 Inst.addOperand(MCOperand::CreateReg(*I));
1850 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1851 addRegListOperands(Inst, N);
1854 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1855 addRegListOperands(Inst, N);
1858 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1859 assert(N == 1 && "Invalid number of operands!");
1860 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1861 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1864 void addModImmOperands(MCInst &Inst, unsigned N) const {
1865 assert(N == 1 && "Invalid number of operands!");
1867 // Support for fixups (MCFixup)
1869 return addImmOperands(Inst, N);
1871 Inst.addOperand(MCOperand::CreateImm(ModImm.Bits | (ModImm.Rot << 7)));
1874 void addModImmNotOperands(MCInst &Inst, unsigned N) const {
1875 assert(N == 1 && "Invalid number of operands!");
1876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1877 uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue());
1878 Inst.addOperand(MCOperand::CreateImm(Enc));
1881 void addModImmNegOperands(MCInst &Inst, unsigned N) const {
1882 assert(N == 1 && "Invalid number of operands!");
1883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1884 uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue());
1885 Inst.addOperand(MCOperand::CreateImm(Enc));
1888 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1889 assert(N == 1 && "Invalid number of operands!");
1890 // Munge the lsb/width into a bitfield mask.
1891 unsigned lsb = Bitfield.LSB;
1892 unsigned width = Bitfield.Width;
1893 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1894 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1895 (32 - (lsb + width)));
1896 Inst.addOperand(MCOperand::CreateImm(Mask));
1899 void addImmOperands(MCInst &Inst, unsigned N) const {
1900 assert(N == 1 && "Invalid number of operands!");
1901 addExpr(Inst, getImm());
1904 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1905 assert(N == 1 && "Invalid number of operands!");
1906 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1907 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1910 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1911 assert(N == 1 && "Invalid number of operands!");
1912 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1913 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1916 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1917 assert(N == 1 && "Invalid number of operands!");
1918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1919 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1920 Inst.addOperand(MCOperand::CreateImm(Val));
1923 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1924 assert(N == 1 && "Invalid number of operands!");
1925 // FIXME: We really want to scale the value here, but the LDRD/STRD
1926 // instruction don't encode operands that way yet.
1927 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1928 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1931 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1932 assert(N == 1 && "Invalid number of operands!");
1933 // The immediate is scaled by four in the encoding and is stored
1934 // in the MCInst as such. Lop off the low two bits here.
1935 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1936 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1939 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1940 assert(N == 1 && "Invalid number of operands!");
1941 // The immediate is scaled by four in the encoding and is stored
1942 // in the MCInst as such. Lop off the low two bits here.
1943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1944 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1947 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1948 assert(N == 1 && "Invalid number of operands!");
1949 // The immediate is scaled by four in the encoding and is stored
1950 // in the MCInst as such. Lop off the low two bits here.
1951 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1952 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1955 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1956 assert(N == 1 && "Invalid number of operands!");
1957 // The constant encodes as the immediate-1, and we store in the instruction
1958 // the bits as encoded, so subtract off one here.
1959 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1960 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1963 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1964 assert(N == 1 && "Invalid number of operands!");
1965 // The constant encodes as the immediate-1, and we store in the instruction
1966 // the bits as encoded, so subtract off one here.
1967 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1968 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1971 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1972 assert(N == 1 && "Invalid number of operands!");
1973 // The constant encodes as the immediate, except for 32, which encodes as
1975 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1976 unsigned Imm = CE->getValue();
1977 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1980 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1981 assert(N == 1 && "Invalid number of operands!");
1982 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1983 // the instruction as well.
1984 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1985 int Val = CE->getValue();
1986 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1989 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1990 assert(N == 1 && "Invalid number of operands!");
1991 // The operand is actually a t2_so_imm, but we have its bitwise
1992 // negation in the assembly source, so twiddle it here.
1993 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1994 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1997 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1998 assert(N == 1 && "Invalid number of operands!");
1999 // The operand is actually a t2_so_imm, but we have its
2000 // negation in the assembly source, so twiddle it here.
2001 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2002 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
2005 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
2006 assert(N == 1 && "Invalid number of operands!");
2007 // The operand is actually an imm0_4095, but we have its
2008 // negation in the assembly source, so twiddle it here.
2009 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2010 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
2013 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
2014 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
2015 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
2019 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2020 assert(SR && "Unknown value type!");
2021 Inst.addOperand(MCOperand::CreateExpr(SR));
2024 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
2025 assert(N == 1 && "Invalid number of operands!");
2027 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2029 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
2033 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2034 assert(SR && "Unknown value type!");
2035 Inst.addOperand(MCOperand::CreateExpr(SR));
2039 assert(isMem() && "Unknown value type!");
2040 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
2041 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
2044 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
2045 assert(N == 1 && "Invalid number of operands!");
2046 // The operand is actually a so_imm, but we have its bitwise
2047 // negation in the assembly source, so twiddle it here.
2048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2049 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
2052 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
2053 assert(N == 1 && "Invalid number of operands!");
2054 // The operand is actually a so_imm, but we have its
2055 // negation in the assembly source, so twiddle it here.
2056 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2057 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
2060 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
2061 assert(N == 1 && "Invalid number of operands!");
2062 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
2065 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
2066 assert(N == 1 && "Invalid number of operands!");
2067 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
2070 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
2071 assert(N == 1 && "Invalid number of operands!");
2072 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2075 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
2076 assert(N == 1 && "Invalid number of operands!");
2077 int32_t Imm = Memory.OffsetImm->getValue();
2078 Inst.addOperand(MCOperand::CreateImm(Imm));
2081 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
2082 assert(N == 1 && "Invalid number of operands!");
2083 assert(isImm() && "Not an immediate!");
2085 // If we have an immediate that's not a constant, treat it as a label
2086 // reference needing a fixup.
2087 if (!isa<MCConstantExpr>(getImm())) {
2088 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2092 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2093 int Val = CE->getValue();
2094 Inst.addOperand(MCOperand::CreateImm(Val));
2097 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
2098 assert(N == 2 && "Invalid number of operands!");
2099 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2100 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
2103 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2104 addAlignedMemoryOperands(Inst, N);
2107 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2108 addAlignedMemoryOperands(Inst, N);
2111 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2112 addAlignedMemoryOperands(Inst, N);
2115 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2116 addAlignedMemoryOperands(Inst, N);
2119 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2120 addAlignedMemoryOperands(Inst, N);
2123 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2124 addAlignedMemoryOperands(Inst, N);
2127 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2128 addAlignedMemoryOperands(Inst, N);
2131 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2132 addAlignedMemoryOperands(Inst, N);
2135 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2136 addAlignedMemoryOperands(Inst, N);
2139 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2140 addAlignedMemoryOperands(Inst, N);
2143 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2144 addAlignedMemoryOperands(Inst, N);
2147 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2148 assert(N == 3 && "Invalid number of operands!");
2149 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2150 if (!Memory.OffsetRegNum) {
2151 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2152 // Special case for #-0
2153 if (Val == INT32_MIN) Val = 0;
2154 if (Val < 0) Val = -Val;
2155 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2157 // For register offset, we encode the shift type and negation flag
2159 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2160 Memory.ShiftImm, Memory.ShiftType);
2162 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2163 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2164 Inst.addOperand(MCOperand::CreateImm(Val));
2167 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
2168 assert(N == 2 && "Invalid number of operands!");
2169 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2170 assert(CE && "non-constant AM2OffsetImm operand!");
2171 int32_t Val = CE->getValue();
2172 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2173 // Special case for #-0
2174 if (Val == INT32_MIN) Val = 0;
2175 if (Val < 0) Val = -Val;
2176 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2177 Inst.addOperand(MCOperand::CreateReg(0));
2178 Inst.addOperand(MCOperand::CreateImm(Val));
2181 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
2182 assert(N == 3 && "Invalid number of operands!");
2183 // If we have an immediate that's not a constant, treat it as a label
2184 // reference needing a fixup. If it is a constant, it's something else
2185 // and we reject it.
2187 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2188 Inst.addOperand(MCOperand::CreateReg(0));
2189 Inst.addOperand(MCOperand::CreateImm(0));
2193 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2194 if (!Memory.OffsetRegNum) {
2195 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2196 // Special case for #-0
2197 if (Val == INT32_MIN) Val = 0;
2198 if (Val < 0) Val = -Val;
2199 Val = ARM_AM::getAM3Opc(AddSub, Val);
2201 // For register offset, we encode the shift type and negation flag
2203 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
2205 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2206 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2207 Inst.addOperand(MCOperand::CreateImm(Val));
2210 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2211 assert(N == 2 && "Invalid number of operands!");
2212 if (Kind == k_PostIndexRegister) {
2214 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2215 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2216 Inst.addOperand(MCOperand::CreateImm(Val));
2221 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2222 int32_t Val = CE->getValue();
2223 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2224 // Special case for #-0
2225 if (Val == INT32_MIN) Val = 0;
2226 if (Val < 0) Val = -Val;
2227 Val = ARM_AM::getAM3Opc(AddSub, Val);
2228 Inst.addOperand(MCOperand::CreateReg(0));
2229 Inst.addOperand(MCOperand::CreateImm(Val));
2232 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2233 assert(N == 2 && "Invalid number of operands!");
2234 // If we have an immediate that's not a constant, treat it as a label
2235 // reference needing a fixup. If it is a constant, it's something else
2236 // and we reject it.
2238 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2239 Inst.addOperand(MCOperand::CreateImm(0));
2243 // The lower two bits are always zero and as such are not encoded.
2244 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2245 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2246 // Special case for #-0
2247 if (Val == INT32_MIN) Val = 0;
2248 if (Val < 0) Val = -Val;
2249 Val = ARM_AM::getAM5Opc(AddSub, Val);
2250 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2251 Inst.addOperand(MCOperand::CreateImm(Val));
2254 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2255 assert(N == 2 && "Invalid number of operands!");
2256 // If we have an immediate that's not a constant, treat it as a label
2257 // reference needing a fixup. If it is a constant, it's something else
2258 // and we reject it.
2260 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2261 Inst.addOperand(MCOperand::CreateImm(0));
2265 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2266 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2267 Inst.addOperand(MCOperand::CreateImm(Val));
2270 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2271 assert(N == 2 && "Invalid number of operands!");
2272 // The lower two bits are always zero and as such are not encoded.
2273 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2274 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2275 Inst.addOperand(MCOperand::CreateImm(Val));
2278 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2279 assert(N == 2 && "Invalid number of operands!");
2280 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2281 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2282 Inst.addOperand(MCOperand::CreateImm(Val));
2285 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2286 addMemImm8OffsetOperands(Inst, N);
2289 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2290 addMemImm8OffsetOperands(Inst, N);
2293 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2294 assert(N == 2 && "Invalid number of operands!");
2295 // If this is an immediate, it's a label reference.
2297 addExpr(Inst, getImm());
2298 Inst.addOperand(MCOperand::CreateImm(0));
2302 // Otherwise, it's a normal memory reg+offset.
2303 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2304 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2305 Inst.addOperand(MCOperand::CreateImm(Val));
2308 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2309 assert(N == 2 && "Invalid number of operands!");
2310 // If this is an immediate, it's a label reference.
2312 addExpr(Inst, getImm());
2313 Inst.addOperand(MCOperand::CreateImm(0));
2317 // Otherwise, it's a normal memory reg+offset.
2318 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2319 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2320 Inst.addOperand(MCOperand::CreateImm(Val));
2323 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2324 assert(N == 2 && "Invalid number of operands!");
2325 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2326 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2329 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2330 assert(N == 2 && "Invalid number of operands!");
2331 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2332 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2335 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2336 assert(N == 3 && "Invalid number of operands!");
2338 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2339 Memory.ShiftImm, Memory.ShiftType);
2340 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2341 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2342 Inst.addOperand(MCOperand::CreateImm(Val));
2345 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2346 assert(N == 3 && "Invalid number of operands!");
2347 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2348 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2349 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2352 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2353 assert(N == 2 && "Invalid number of operands!");
2354 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2355 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2358 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2359 assert(N == 2 && "Invalid number of operands!");
2360 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2361 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2362 Inst.addOperand(MCOperand::CreateImm(Val));
2365 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2366 assert(N == 2 && "Invalid number of operands!");
2367 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2368 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2369 Inst.addOperand(MCOperand::CreateImm(Val));
2372 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2373 assert(N == 2 && "Invalid number of operands!");
2374 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2375 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2376 Inst.addOperand(MCOperand::CreateImm(Val));
2379 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2380 assert(N == 2 && "Invalid number of operands!");
2381 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2382 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2383 Inst.addOperand(MCOperand::CreateImm(Val));
2386 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2387 assert(N == 1 && "Invalid number of operands!");
2388 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2389 assert(CE && "non-constant post-idx-imm8 operand!");
2390 int Imm = CE->getValue();
2391 bool isAdd = Imm >= 0;
2392 if (Imm == INT32_MIN) Imm = 0;
2393 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2394 Inst.addOperand(MCOperand::CreateImm(Imm));
2397 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2398 assert(N == 1 && "Invalid number of operands!");
2399 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2400 assert(CE && "non-constant post-idx-imm8s4 operand!");
2401 int Imm = CE->getValue();
2402 bool isAdd = Imm >= 0;
2403 if (Imm == INT32_MIN) Imm = 0;
2404 // Immediate is scaled by 4.
2405 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2406 Inst.addOperand(MCOperand::CreateImm(Imm));
2409 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2410 assert(N == 2 && "Invalid number of operands!");
2411 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2412 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2415 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2416 assert(N == 2 && "Invalid number of operands!");
2417 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2418 // The sign, shift type, and shift amount are encoded in a single operand
2419 // using the AM2 encoding helpers.
2420 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2421 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2422 PostIdxReg.ShiftTy);
2423 Inst.addOperand(MCOperand::CreateImm(Imm));
2426 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2427 assert(N == 1 && "Invalid number of operands!");
2428 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2431 void addBankedRegOperands(MCInst &Inst, unsigned N) const {
2432 assert(N == 1 && "Invalid number of operands!");
2433 Inst.addOperand(MCOperand::CreateImm(unsigned(getBankedReg())));
2436 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2437 assert(N == 1 && "Invalid number of operands!");
2438 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2441 void addVecListOperands(MCInst &Inst, unsigned N) const {
2442 assert(N == 1 && "Invalid number of operands!");
2443 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2446 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2447 assert(N == 2 && "Invalid number of operands!");
2448 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2449 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2452 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2453 assert(N == 1 && "Invalid number of operands!");
2454 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2457 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2458 assert(N == 1 && "Invalid number of operands!");
2459 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2462 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2463 assert(N == 1 && "Invalid number of operands!");
2464 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2467 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2468 assert(N == 1 && "Invalid number of operands!");
2469 // The immediate encodes the type of constant as well as the value.
2470 // Mask in that this is an i8 splat.
2471 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2472 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2475 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2476 assert(N == 1 && "Invalid number of operands!");
2477 // The immediate encodes the type of constant as well as the value.
2478 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2479 unsigned Value = CE->getValue();
2480 Value = ARM_AM::encodeNEONi16splat(Value);
2481 Inst.addOperand(MCOperand::CreateImm(Value));
2484 void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const {
2485 assert(N == 1 && "Invalid number of operands!");
2486 // The immediate encodes the type of constant as well as the value.
2487 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2488 unsigned Value = CE->getValue();
2489 Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff);
2490 Inst.addOperand(MCOperand::CreateImm(Value));
2493 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2494 assert(N == 1 && "Invalid number of operands!");
2495 // The immediate encodes the type of constant as well as the value.
2496 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2497 unsigned Value = CE->getValue();
2498 Value = ARM_AM::encodeNEONi32splat(Value);
2499 Inst.addOperand(MCOperand::CreateImm(Value));
2502 void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const {
2503 assert(N == 1 && "Invalid number of operands!");
2504 // The immediate encodes the type of constant as well as the value.
2505 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2506 unsigned Value = CE->getValue();
2507 Value = ARM_AM::encodeNEONi32splat(~Value);
2508 Inst.addOperand(MCOperand::CreateImm(Value));
2511 void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const {
2512 assert(N == 1 && "Invalid number of operands!");
2513 // The immediate encodes the type of constant as well as the value.
2514 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2515 unsigned Value = CE->getValue();
2516 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2517 Inst.getOpcode() == ARM::VMOVv16i8) &&
2518 "All vmvn instructions that wants to replicate non-zero byte "
2519 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2520 unsigned B = ((~Value) & 0xff);
2521 B |= 0xe00; // cmode = 0b1110
2522 Inst.addOperand(MCOperand::CreateImm(B));
2524 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2525 assert(N == 1 && "Invalid number of operands!");
2526 // The immediate encodes the type of constant as well as the value.
2527 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2528 unsigned Value = CE->getValue();
2529 if (Value >= 256 && Value <= 0xffff)
2530 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2531 else if (Value > 0xffff && Value <= 0xffffff)
2532 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2533 else if (Value > 0xffffff)
2534 Value = (Value >> 24) | 0x600;
2535 Inst.addOperand(MCOperand::CreateImm(Value));
2538 void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const {
2539 assert(N == 1 && "Invalid number of operands!");
2540 // The immediate encodes the type of constant as well as the value.
2541 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2542 unsigned Value = CE->getValue();
2543 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2544 Inst.getOpcode() == ARM::VMOVv16i8) &&
2545 "All instructions that wants to replicate non-zero byte "
2546 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2547 unsigned B = Value & 0xff;
2548 B |= 0xe00; // cmode = 0b1110
2549 Inst.addOperand(MCOperand::CreateImm(B));
2551 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2552 assert(N == 1 && "Invalid number of operands!");
2553 // The immediate encodes the type of constant as well as the value.
2554 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2555 unsigned Value = ~CE->getValue();
2556 if (Value >= 256 && Value <= 0xffff)
2557 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2558 else if (Value > 0xffff && Value <= 0xffffff)
2559 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2560 else if (Value > 0xffffff)
2561 Value = (Value >> 24) | 0x600;
2562 Inst.addOperand(MCOperand::CreateImm(Value));
2565 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2566 assert(N == 1 && "Invalid number of operands!");
2567 // The immediate encodes the type of constant as well as the value.
2568 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2569 uint64_t Value = CE->getValue();
2571 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2572 Imm |= (Value & 1) << i;
2574 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2577 void print(raw_ostream &OS) const override;
2579 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) {
2580 auto Op = make_unique<ARMOperand>(k_ITCondMask);
2581 Op->ITMask.Mask = Mask;
2587 static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC,
2589 auto Op = make_unique<ARMOperand>(k_CondCode);
2596 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) {
2597 auto Op = make_unique<ARMOperand>(k_CoprocNum);
2598 Op->Cop.Val = CopVal;
2604 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) {
2605 auto Op = make_unique<ARMOperand>(k_CoprocReg);
2606 Op->Cop.Val = CopVal;
2612 static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S,
2614 auto Op = make_unique<ARMOperand>(k_CoprocOption);
2621 static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) {
2622 auto Op = make_unique<ARMOperand>(k_CCOut);
2623 Op->Reg.RegNum = RegNum;
2629 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) {
2630 auto Op = make_unique<ARMOperand>(k_Token);
2631 Op->Tok.Data = Str.data();
2632 Op->Tok.Length = Str.size();
2638 static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S,
2640 auto Op = make_unique<ARMOperand>(k_Register);
2641 Op->Reg.RegNum = RegNum;
2647 static std::unique_ptr<ARMOperand>
2648 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2649 unsigned ShiftReg, unsigned ShiftImm, SMLoc S,
2651 auto Op = make_unique<ARMOperand>(k_ShiftedRegister);
2652 Op->RegShiftedReg.ShiftTy = ShTy;
2653 Op->RegShiftedReg.SrcReg = SrcReg;
2654 Op->RegShiftedReg.ShiftReg = ShiftReg;
2655 Op->RegShiftedReg.ShiftImm = ShiftImm;
2661 static std::unique_ptr<ARMOperand>
2662 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2663 unsigned ShiftImm, SMLoc S, SMLoc E) {
2664 auto Op = make_unique<ARMOperand>(k_ShiftedImmediate);
2665 Op->RegShiftedImm.ShiftTy = ShTy;
2666 Op->RegShiftedImm.SrcReg = SrcReg;
2667 Op->RegShiftedImm.ShiftImm = ShiftImm;
2673 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm,
2675 auto Op = make_unique<ARMOperand>(k_ShifterImmediate);
2676 Op->ShifterImm.isASR = isASR;
2677 Op->ShifterImm.Imm = Imm;
2683 static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S,
2685 auto Op = make_unique<ARMOperand>(k_RotateImmediate);
2686 Op->RotImm.Imm = Imm;
2692 static std::unique_ptr<ARMOperand> CreateModImm(unsigned Bits, unsigned Rot,
2694 auto Op = make_unique<ARMOperand>(k_ModifiedImmediate);
2695 Op->ModImm.Bits = Bits;
2696 Op->ModImm.Rot = Rot;
2702 static std::unique_ptr<ARMOperand>
2703 CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) {
2704 auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor);
2705 Op->Bitfield.LSB = LSB;
2706 Op->Bitfield.Width = Width;
2712 static std::unique_ptr<ARMOperand>
2713 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs,
2714 SMLoc StartLoc, SMLoc EndLoc) {
2715 assert (Regs.size() > 0 && "RegList contains no registers?");
2716 KindTy Kind = k_RegisterList;
2718 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2719 Kind = k_DPRRegisterList;
2720 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2721 contains(Regs.front().second))
2722 Kind = k_SPRRegisterList;
2724 // Sort based on the register encoding values.
2725 array_pod_sort(Regs.begin(), Regs.end());
2727 auto Op = make_unique<ARMOperand>(Kind);
2728 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2729 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2730 Op->Registers.push_back(I->second);
2731 Op->StartLoc = StartLoc;
2732 Op->EndLoc = EndLoc;
2736 static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum,
2738 bool isDoubleSpaced,
2740 auto Op = make_unique<ARMOperand>(k_VectorList);
2741 Op->VectorList.RegNum = RegNum;
2742 Op->VectorList.Count = Count;
2743 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2749 static std::unique_ptr<ARMOperand>
2750 CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced,
2752 auto Op = make_unique<ARMOperand>(k_VectorListAllLanes);
2753 Op->VectorList.RegNum = RegNum;
2754 Op->VectorList.Count = Count;
2755 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2761 static std::unique_ptr<ARMOperand>
2762 CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index,
2763 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2764 auto Op = make_unique<ARMOperand>(k_VectorListIndexed);
2765 Op->VectorList.RegNum = RegNum;
2766 Op->VectorList.Count = Count;
2767 Op->VectorList.LaneIndex = Index;
2768 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2774 static std::unique_ptr<ARMOperand>
2775 CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) {
2776 auto Op = make_unique<ARMOperand>(k_VectorIndex);
2777 Op->VectorIndex.Val = Idx;
2783 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S,
2785 auto Op = make_unique<ARMOperand>(k_Immediate);
2792 static std::unique_ptr<ARMOperand>
2793 CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm,
2794 unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType,
2795 unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S,
2796 SMLoc E, SMLoc AlignmentLoc = SMLoc()) {
2797 auto Op = make_unique<ARMOperand>(k_Memory);
2798 Op->Memory.BaseRegNum = BaseRegNum;
2799 Op->Memory.OffsetImm = OffsetImm;
2800 Op->Memory.OffsetRegNum = OffsetRegNum;
2801 Op->Memory.ShiftType = ShiftType;
2802 Op->Memory.ShiftImm = ShiftImm;
2803 Op->Memory.Alignment = Alignment;
2804 Op->Memory.isNegative = isNegative;
2807 Op->AlignmentLoc = AlignmentLoc;
2811 static std::unique_ptr<ARMOperand>
2812 CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy,
2813 unsigned ShiftImm, SMLoc S, SMLoc E) {
2814 auto Op = make_unique<ARMOperand>(k_PostIndexRegister);
2815 Op->PostIdxReg.RegNum = RegNum;
2816 Op->PostIdxReg.isAdd = isAdd;
2817 Op->PostIdxReg.ShiftTy = ShiftTy;
2818 Op->PostIdxReg.ShiftImm = ShiftImm;
2824 static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt,
2826 auto Op = make_unique<ARMOperand>(k_MemBarrierOpt);
2827 Op->MBOpt.Val = Opt;
2833 static std::unique_ptr<ARMOperand>
2834 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) {
2835 auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt);
2836 Op->ISBOpt.Val = Opt;
2842 static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags,
2844 auto Op = make_unique<ARMOperand>(k_ProcIFlags);
2845 Op->IFlags.Val = IFlags;
2851 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) {
2852 auto Op = make_unique<ARMOperand>(k_MSRMask);
2853 Op->MMask.Val = MMask;
2859 static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) {
2860 auto Op = make_unique<ARMOperand>(k_BankedReg);
2861 Op->BankedReg.Val = Reg;
2868 } // end anonymous namespace.
2870 void ARMOperand::print(raw_ostream &OS) const {
2873 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2876 OS << "<ccout " << getReg() << ">";
2878 case k_ITCondMask: {
2879 static const char *const MaskStr[] = {
2880 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2881 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2883 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2884 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2888 OS << "<coprocessor number: " << getCoproc() << ">";
2891 OS << "<coprocessor register: " << getCoproc() << ">";
2893 case k_CoprocOption:
2894 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2897 OS << "<mask: " << getMSRMask() << ">";
2900 OS << "<banked reg: " << getBankedReg() << ">";
2903 getImm()->print(OS);
2905 case k_MemBarrierOpt:
2906 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2908 case k_InstSyncBarrierOpt:
2909 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2913 << " base:" << Memory.BaseRegNum;
2916 case k_PostIndexRegister:
2917 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2918 << PostIdxReg.RegNum;
2919 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2920 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2921 << PostIdxReg.ShiftImm;
2924 case k_ProcIFlags: {
2925 OS << "<ARM_PROC::";
2926 unsigned IFlags = getProcIFlags();
2927 for (int i=2; i >= 0; --i)
2928 if (IFlags & (1 << i))
2929 OS << ARM_PROC::IFlagsToString(1 << i);
2934 OS << "<register " << getReg() << ">";
2936 case k_ShifterImmediate:
2937 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2938 << " #" << ShifterImm.Imm << ">";
2940 case k_ShiftedRegister:
2941 OS << "<so_reg_reg "
2942 << RegShiftedReg.SrcReg << " "
2943 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2944 << " " << RegShiftedReg.ShiftReg << ">";
2946 case k_ShiftedImmediate:
2947 OS << "<so_reg_imm "
2948 << RegShiftedImm.SrcReg << " "
2949 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2950 << " #" << RegShiftedImm.ShiftImm << ">";
2952 case k_RotateImmediate:
2953 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2955 case k_ModifiedImmediate:
2956 OS << "<mod_imm #" << ModImm.Bits << ", #"
2957 << ModImm.Rot << ")>";
2959 case k_BitfieldDescriptor:
2960 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2961 << ", width: " << Bitfield.Width << ">";
2963 case k_RegisterList:
2964 case k_DPRRegisterList:
2965 case k_SPRRegisterList: {
2966 OS << "<register_list ";
2968 const SmallVectorImpl<unsigned> &RegList = getRegList();
2969 for (SmallVectorImpl<unsigned>::const_iterator
2970 I = RegList.begin(), E = RegList.end(); I != E; ) {
2972 if (++I < E) OS << ", ";
2979 OS << "<vector_list " << VectorList.Count << " * "
2980 << VectorList.RegNum << ">";
2982 case k_VectorListAllLanes:
2983 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2984 << VectorList.RegNum << ">";
2986 case k_VectorListIndexed:
2987 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2988 << VectorList.Count << " * " << VectorList.RegNum << ">";
2991 OS << "'" << getToken() << "'";
2994 OS << "<vectorindex " << getVectorIndex() << ">";
2999 /// @name Auto-generated Match Functions
3002 static unsigned MatchRegisterName(StringRef Name);
3006 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
3007 SMLoc &StartLoc, SMLoc &EndLoc) {
3008 const AsmToken &Tok = getParser().getTok();
3009 StartLoc = Tok.getLoc();
3010 EndLoc = Tok.getEndLoc();
3011 RegNo = tryParseRegister();
3013 return (RegNo == (unsigned)-1);
3016 /// Try to parse a register name. The token must be an Identifier when called,
3017 /// and if it is a register name the token is eaten and the register number is
3018 /// returned. Otherwise return -1.
3020 int ARMAsmParser::tryParseRegister() {
3021 MCAsmParser &Parser = getParser();
3022 const AsmToken &Tok = Parser.getTok();
3023 if (Tok.isNot(AsmToken::Identifier)) return -1;
3025 std::string lowerCase = Tok.getString().lower();
3026 unsigned RegNum = MatchRegisterName(lowerCase);
3028 RegNum = StringSwitch<unsigned>(lowerCase)
3029 .Case("r13", ARM::SP)
3030 .Case("r14", ARM::LR)
3031 .Case("r15", ARM::PC)
3032 .Case("ip", ARM::R12)
3033 // Additional register name aliases for 'gas' compatibility.
3034 .Case("a1", ARM::R0)
3035 .Case("a2", ARM::R1)
3036 .Case("a3", ARM::R2)
3037 .Case("a4", ARM::R3)
3038 .Case("v1", ARM::R4)
3039 .Case("v2", ARM::R5)
3040 .Case("v3", ARM::R6)
3041 .Case("v4", ARM::R7)
3042 .Case("v5", ARM::R8)
3043 .Case("v6", ARM::R9)
3044 .Case("v7", ARM::R10)
3045 .Case("v8", ARM::R11)
3046 .Case("sb", ARM::R9)
3047 .Case("sl", ARM::R10)
3048 .Case("fp", ARM::R11)
3052 // Check for aliases registered via .req. Canonicalize to lower case.
3053 // That's more consistent since register names are case insensitive, and
3054 // it's how the original entry was passed in from MC/MCParser/AsmParser.
3055 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
3056 // If no match, return failure.
3057 if (Entry == RegisterReqs.end())
3059 Parser.Lex(); // Eat identifier token.
3060 return Entry->getValue();
3063 // Some FPUs only have 16 D registers, so D16-D31 are invalid
3064 if (hasD16() && RegNum >= ARM::D16 && RegNum <= ARM::D31)
3067 Parser.Lex(); // Eat identifier token.
3072 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
3073 // If a recoverable error occurs, return 1. If an irrecoverable error
3074 // occurs, return -1. An irrecoverable error is one where tokens have been
3075 // consumed in the process of trying to parse the shifter (i.e., when it is
3076 // indeed a shifter operand, but malformed).
3077 int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
3078 MCAsmParser &Parser = getParser();
3079 SMLoc S = Parser.getTok().getLoc();
3080 const AsmToken &Tok = Parser.getTok();
3081 if (Tok.isNot(AsmToken::Identifier))
3084 std::string lowerCase = Tok.getString().lower();
3085 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
3086 .Case("asl", ARM_AM::lsl)
3087 .Case("lsl", ARM_AM::lsl)
3088 .Case("lsr", ARM_AM::lsr)
3089 .Case("asr", ARM_AM::asr)
3090 .Case("ror", ARM_AM::ror)
3091 .Case("rrx", ARM_AM::rrx)
3092 .Default(ARM_AM::no_shift);
3094 if (ShiftTy == ARM_AM::no_shift)
3097 Parser.Lex(); // Eat the operator.
3099 // The source register for the shift has already been added to the
3100 // operand list, so we need to pop it off and combine it into the shifted
3101 // register operand instead.
3102 std::unique_ptr<ARMOperand> PrevOp(
3103 (ARMOperand *)Operands.pop_back_val().release());
3104 if (!PrevOp->isReg())
3105 return Error(PrevOp->getStartLoc(), "shift must be of a register");
3106 int SrcReg = PrevOp->getReg();
3111 if (ShiftTy == ARM_AM::rrx) {
3112 // RRX Doesn't have an explicit shift amount. The encoder expects
3113 // the shift register to be the same as the source register. Seems odd,
3117 // Figure out if this is shifted by a constant or a register (for non-RRX).
3118 if (Parser.getTok().is(AsmToken::Hash) ||
3119 Parser.getTok().is(AsmToken::Dollar)) {
3120 Parser.Lex(); // Eat hash.
3121 SMLoc ImmLoc = Parser.getTok().getLoc();
3122 const MCExpr *ShiftExpr = nullptr;
3123 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
3124 Error(ImmLoc, "invalid immediate shift value");
3127 // The expression must be evaluatable as an immediate.
3128 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
3130 Error(ImmLoc, "invalid immediate shift value");
3133 // Range check the immediate.
3134 // lsl, ror: 0 <= imm <= 31
3135 // lsr, asr: 0 <= imm <= 32
3136 Imm = CE->getValue();
3138 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
3139 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
3140 Error(ImmLoc, "immediate shift value out of range");
3143 // shift by zero is a nop. Always send it through as lsl.
3144 // ('as' compatibility)
3146 ShiftTy = ARM_AM::lsl;
3147 } else if (Parser.getTok().is(AsmToken::Identifier)) {
3148 SMLoc L = Parser.getTok().getLoc();
3149 EndLoc = Parser.getTok().getEndLoc();
3150 ShiftReg = tryParseRegister();
3151 if (ShiftReg == -1) {
3152 Error(L, "expected immediate or register in shift operand");
3156 Error(Parser.getTok().getLoc(),
3157 "expected immediate or register in shift operand");
3162 if (ShiftReg && ShiftTy != ARM_AM::rrx)
3163 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
3167 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
3174 /// Try to parse a register name. The token must be an Identifier when called.
3175 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
3176 /// if there is a "writeback". 'true' if it's not a register.
3178 /// TODO this is likely to change to allow different register types and or to
3179 /// parse for a specific register type.
3180 bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
3181 MCAsmParser &Parser = getParser();
3182 const AsmToken &RegTok = Parser.getTok();
3183 int RegNo = tryParseRegister();
3187 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3188 RegTok.getEndLoc()));
3190 const AsmToken &ExclaimTok = Parser.getTok();
3191 if (ExclaimTok.is(AsmToken::Exclaim)) {
3192 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
3193 ExclaimTok.getLoc()));
3194 Parser.Lex(); // Eat exclaim token
3198 // Also check for an index operand. This is only legal for vector registers,
3199 // but that'll get caught OK in operand matching, so we don't need to
3200 // explicitly filter everything else out here.
3201 if (Parser.getTok().is(AsmToken::LBrac)) {
3202 SMLoc SIdx = Parser.getTok().getLoc();
3203 Parser.Lex(); // Eat left bracket token.
3205 const MCExpr *ImmVal;
3206 if (getParser().parseExpression(ImmVal))
3208 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
3210 return TokError("immediate value expected for vector index");
3212 if (Parser.getTok().isNot(AsmToken::RBrac))
3213 return Error(Parser.getTok().getLoc(), "']' expected");
3215 SMLoc E = Parser.getTok().getEndLoc();
3216 Parser.Lex(); // Eat right bracket token.
3218 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
3226 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
3227 /// instruction with a symbolic operand name.
3228 /// We accept "crN" syntax for GAS compatibility.
3229 /// <operand-name> ::= <prefix><number>
3230 /// If CoprocOp is 'c', then:
3231 /// <prefix> ::= c | cr
3232 /// If CoprocOp is 'p', then :
3234 /// <number> ::= integer in range [0, 15]
3235 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
3236 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3238 if (Name.size() < 2 || Name[0] != CoprocOp)
3240 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front();
3242 switch (Name.size()) {
3263 // CP10 and CP11 are VFP/NEON and so vector instructions should be used.
3264 // However, old cores (v5/v6) did use them in that way.
3265 case '0': return 10;
3266 case '1': return 11;
3267 case '2': return 12;
3268 case '3': return 13;
3269 case '4': return 14;
3270 case '5': return 15;
3275 /// parseITCondCode - Try to parse a condition code for an IT instruction.
3276 ARMAsmParser::OperandMatchResultTy
3277 ARMAsmParser::parseITCondCode(OperandVector &Operands) {
3278 MCAsmParser &Parser = getParser();
3279 SMLoc S = Parser.getTok().getLoc();
3280 const AsmToken &Tok = Parser.getTok();
3281 if (!Tok.is(AsmToken::Identifier))
3282 return MatchOperand_NoMatch;
3283 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
3284 .Case("eq", ARMCC::EQ)
3285 .Case("ne", ARMCC::NE)
3286 .Case("hs", ARMCC::HS)
3287 .Case("cs", ARMCC::HS)
3288 .Case("lo", ARMCC::LO)
3289 .Case("cc", ARMCC::LO)
3290 .Case("mi", ARMCC::MI)
3291 .Case("pl", ARMCC::PL)
3292 .Case("vs", ARMCC::VS)
3293 .Case("vc", ARMCC::VC)
3294 .Case("hi", ARMCC::HI)
3295 .Case("ls", ARMCC::LS)
3296 .Case("ge", ARMCC::GE)
3297 .Case("lt", ARMCC::LT)
3298 .Case("gt", ARMCC::GT)
3299 .Case("le", ARMCC::LE)
3300 .Case("al", ARMCC::AL)
3303 return MatchOperand_NoMatch;
3304 Parser.Lex(); // Eat the token.
3306 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3308 return MatchOperand_Success;
3311 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
3312 /// token must be an Identifier when called, and if it is a coprocessor
3313 /// number, the token is eaten and the operand is added to the operand list.
3314 ARMAsmParser::OperandMatchResultTy
3315 ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
3316 MCAsmParser &Parser = getParser();
3317 SMLoc S = Parser.getTok().getLoc();
3318 const AsmToken &Tok = Parser.getTok();
3319 if (Tok.isNot(AsmToken::Identifier))
3320 return MatchOperand_NoMatch;
3322 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
3324 return MatchOperand_NoMatch;
3325 // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions
3326 if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11))
3327 return MatchOperand_NoMatch;
3329 Parser.Lex(); // Eat identifier token.
3330 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
3331 return MatchOperand_Success;
3334 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
3335 /// token must be an Identifier when called, and if it is a coprocessor
3336 /// number, the token is eaten and the operand is added to the operand list.
3337 ARMAsmParser::OperandMatchResultTy
3338 ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
3339 MCAsmParser &Parser = getParser();
3340 SMLoc S = Parser.getTok().getLoc();
3341 const AsmToken &Tok = Parser.getTok();
3342 if (Tok.isNot(AsmToken::Identifier))
3343 return MatchOperand_NoMatch;
3345 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3347 return MatchOperand_NoMatch;
3349 Parser.Lex(); // Eat identifier token.
3350 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
3351 return MatchOperand_Success;
3354 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3355 /// coproc_option : '{' imm0_255 '}'
3356 ARMAsmParser::OperandMatchResultTy
3357 ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
3358 MCAsmParser &Parser = getParser();
3359 SMLoc S = Parser.getTok().getLoc();
3361 // If this isn't a '{', this isn't a coprocessor immediate operand.
3362 if (Parser.getTok().isNot(AsmToken::LCurly))
3363 return MatchOperand_NoMatch;
3364 Parser.Lex(); // Eat the '{'
3367 SMLoc Loc = Parser.getTok().getLoc();
3368 if (getParser().parseExpression(Expr)) {
3369 Error(Loc, "illegal expression");
3370 return MatchOperand_ParseFail;
3372 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3373 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3374 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3375 return MatchOperand_ParseFail;
3377 int Val = CE->getValue();
3379 // Check for and consume the closing '}'
3380 if (Parser.getTok().isNot(AsmToken::RCurly))
3381 return MatchOperand_ParseFail;
3382 SMLoc E = Parser.getTok().getEndLoc();
3383 Parser.Lex(); // Eat the '}'
3385 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3386 return MatchOperand_Success;
3389 // For register list parsing, we need to map from raw GPR register numbering
3390 // to the enumeration values. The enumeration values aren't sorted by
3391 // register number due to our using "sp", "lr" and "pc" as canonical names.
3392 static unsigned getNextRegister(unsigned Reg) {
3393 // If this is a GPR, we need to do it manually, otherwise we can rely
3394 // on the sort ordering of the enumeration since the other reg-classes
3396 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3399 default: llvm_unreachable("Invalid GPR number!");
3400 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3401 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3402 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3403 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3404 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3405 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3406 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3407 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3411 // Return the low-subreg of a given Q register.
3412 static unsigned getDRegFromQReg(unsigned QReg) {
3414 default: llvm_unreachable("expected a Q register!");
3415 case ARM::Q0: return ARM::D0;
3416 case ARM::Q1: return ARM::D2;
3417 case ARM::Q2: return ARM::D4;
3418 case ARM::Q3: return ARM::D6;
3419 case ARM::Q4: return ARM::D8;
3420 case ARM::Q5: return ARM::D10;
3421 case ARM::Q6: return ARM::D12;
3422 case ARM::Q7: return ARM::D14;
3423 case ARM::Q8: return ARM::D16;
3424 case ARM::Q9: return ARM::D18;
3425 case ARM::Q10: return ARM::D20;
3426 case ARM::Q11: return ARM::D22;
3427 case ARM::Q12: return ARM::D24;
3428 case ARM::Q13: return ARM::D26;
3429 case ARM::Q14: return ARM::D28;
3430 case ARM::Q15: return ARM::D30;
3434 /// Parse a register list.
3435 bool ARMAsmParser::parseRegisterList(OperandVector &Operands) {
3436 MCAsmParser &Parser = getParser();
3437 assert(Parser.getTok().is(AsmToken::LCurly) &&
3438 "Token is not a Left Curly Brace");
3439 SMLoc S = Parser.getTok().getLoc();
3440 Parser.Lex(); // Eat '{' token.
3441 SMLoc RegLoc = Parser.getTok().getLoc();
3443 // Check the first register in the list to see what register class
3444 // this is a list of.
3445 int Reg = tryParseRegister();
3447 return Error(RegLoc, "register expected");
3449 // The reglist instructions have at most 16 registers, so reserve
3450 // space for that many.
3452 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3454 // Allow Q regs and just interpret them as the two D sub-registers.
3455 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3456 Reg = getDRegFromQReg(Reg);
3457 EReg = MRI->getEncodingValue(Reg);
3458 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3461 const MCRegisterClass *RC;
3462 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3463 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3464 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3465 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3466 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3467 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3469 return Error(RegLoc, "invalid register in register list");
3471 // Store the register.
3472 EReg = MRI->getEncodingValue(Reg);
3473 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3475 // This starts immediately after the first register token in the list,
3476 // so we can see either a comma or a minus (range separator) as a legal
3478 while (Parser.getTok().is(AsmToken::Comma) ||
3479 Parser.getTok().is(AsmToken::Minus)) {
3480 if (Parser.getTok().is(AsmToken::Minus)) {
3481 Parser.Lex(); // Eat the minus.
3482 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3483 int EndReg = tryParseRegister();
3485 return Error(AfterMinusLoc, "register expected");
3486 // Allow Q regs and just interpret them as the two D sub-registers.
3487 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3488 EndReg = getDRegFromQReg(EndReg) + 1;
3489 // If the register is the same as the start reg, there's nothing
3493 // The register must be in the same register class as the first.
3494 if (!RC->contains(EndReg))
3495 return Error(AfterMinusLoc, "invalid register in register list");
3496 // Ranges must go from low to high.
3497 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3498 return Error(AfterMinusLoc, "bad range in register list");
3500 // Add all the registers in the range to the register list.
3501 while (Reg != EndReg) {
3502 Reg = getNextRegister(Reg);
3503 EReg = MRI->getEncodingValue(Reg);
3504 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3508 Parser.Lex(); // Eat the comma.
3509 RegLoc = Parser.getTok().getLoc();
3511 const AsmToken RegTok = Parser.getTok();
3512 Reg = tryParseRegister();
3514 return Error(RegLoc, "register expected");
3515 // Allow Q regs and just interpret them as the two D sub-registers.
3516 bool isQReg = false;
3517 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3518 Reg = getDRegFromQReg(Reg);
3521 // The register must be in the same register class as the first.
3522 if (!RC->contains(Reg))
3523 return Error(RegLoc, "invalid register in register list");
3524 // List must be monotonically increasing.
3525 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3526 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3527 Warning(RegLoc, "register list not in ascending order");
3529 return Error(RegLoc, "register list not in ascending order");
3531 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3532 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3533 ") in register list");
3536 // VFP register lists must also be contiguous.
3537 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3539 return Error(RegLoc, "non-contiguous register range");
3540 EReg = MRI->getEncodingValue(Reg);
3541 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3543 EReg = MRI->getEncodingValue(++Reg);
3544 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3548 if (Parser.getTok().isNot(AsmToken::RCurly))
3549 return Error(Parser.getTok().getLoc(), "'}' expected");
3550 SMLoc E = Parser.getTok().getEndLoc();
3551 Parser.Lex(); // Eat '}' token.
3553 // Push the register list operand.
3554 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3556 // The ARM system instruction variants for LDM/STM have a '^' token here.
3557 if (Parser.getTok().is(AsmToken::Caret)) {
3558 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3559 Parser.Lex(); // Eat '^' token.
3565 // Helper function to parse the lane index for vector lists.
3566 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3567 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3568 MCAsmParser &Parser = getParser();
3569 Index = 0; // Always return a defined index value.
3570 if (Parser.getTok().is(AsmToken::LBrac)) {
3571 Parser.Lex(); // Eat the '['.
3572 if (Parser.getTok().is(AsmToken::RBrac)) {
3573 // "Dn[]" is the 'all lanes' syntax.
3574 LaneKind = AllLanes;
3575 EndLoc = Parser.getTok().getEndLoc();
3576 Parser.Lex(); // Eat the ']'.
3577 return MatchOperand_Success;
3580 // There's an optional '#' token here. Normally there wouldn't be, but
3581 // inline assemble puts one in, and it's friendly to accept that.
3582 if (Parser.getTok().is(AsmToken::Hash))
3583 Parser.Lex(); // Eat '#' or '$'.
3585 const MCExpr *LaneIndex;
3586 SMLoc Loc = Parser.getTok().getLoc();
3587 if (getParser().parseExpression(LaneIndex)) {
3588 Error(Loc, "illegal expression");
3589 return MatchOperand_ParseFail;
3591 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3593 Error(Loc, "lane index must be empty or an integer");
3594 return MatchOperand_ParseFail;
3596 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3597 Error(Parser.getTok().getLoc(), "']' expected");
3598 return MatchOperand_ParseFail;
3600 EndLoc = Parser.getTok().getEndLoc();
3601 Parser.Lex(); // Eat the ']'.
3602 int64_t Val = CE->getValue();
3604 // FIXME: Make this range check context sensitive for .8, .16, .32.
3605 if (Val < 0 || Val > 7) {
3606 Error(Parser.getTok().getLoc(), "lane index out of range");
3607 return MatchOperand_ParseFail;
3610 LaneKind = IndexedLane;
3611 return MatchOperand_Success;
3614 return MatchOperand_Success;
3617 // parse a vector register list
3618 ARMAsmParser::OperandMatchResultTy
3619 ARMAsmParser::parseVectorList(OperandVector &Operands) {
3620 MCAsmParser &Parser = getParser();
3621 VectorLaneTy LaneKind;
3623 SMLoc S = Parser.getTok().getLoc();
3624 // As an extension (to match gas), support a plain D register or Q register
3625 // (without encosing curly braces) as a single or double entry list,
3627 if (Parser.getTok().is(AsmToken::Identifier)) {
3628 SMLoc E = Parser.getTok().getEndLoc();
3629 int Reg = tryParseRegister();
3631 return MatchOperand_NoMatch;
3632 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3633 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3634 if (Res != MatchOperand_Success)
3638 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3641 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3645 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3650 return MatchOperand_Success;
3652 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3653 Reg = getDRegFromQReg(Reg);
3654 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3655 if (Res != MatchOperand_Success)
3659 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3660 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3661 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3664 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3665 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3666 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3670 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3675 return MatchOperand_Success;
3677 Error(S, "vector register expected");
3678 return MatchOperand_ParseFail;
3681 if (Parser.getTok().isNot(AsmToken::LCurly))
3682 return MatchOperand_NoMatch;
3684 Parser.Lex(); // Eat '{' token.
3685 SMLoc RegLoc = Parser.getTok().getLoc();
3687 int Reg = tryParseRegister();
3689 Error(RegLoc, "register expected");
3690 return MatchOperand_ParseFail;
3694 unsigned FirstReg = Reg;
3695 // The list is of D registers, but we also allow Q regs and just interpret
3696 // them as the two D sub-registers.
3697 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3698 FirstReg = Reg = getDRegFromQReg(Reg);
3699 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3700 // it's ambiguous with four-register single spaced.
3706 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3707 return MatchOperand_ParseFail;
3709 while (Parser.getTok().is(AsmToken::Comma) ||
3710 Parser.getTok().is(AsmToken::Minus)) {
3711 if (Parser.getTok().is(AsmToken::Minus)) {
3713 Spacing = 1; // Register range implies a single spaced list.
3714 else if (Spacing == 2) {
3715 Error(Parser.getTok().getLoc(),
3716 "sequential registers in double spaced list");
3717 return MatchOperand_ParseFail;
3719 Parser.Lex(); // Eat the minus.
3720 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3721 int EndReg = tryParseRegister();
3723 Error(AfterMinusLoc, "register expected");
3724 return MatchOperand_ParseFail;
3726 // Allow Q regs and just interpret them as the two D sub-registers.
3727 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3728 EndReg = getDRegFromQReg(EndReg) + 1;
3729 // If the register is the same as the start reg, there's nothing
3733 // The register must be in the same register class as the first.
3734 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3735 Error(AfterMinusLoc, "invalid register in register list");
3736 return MatchOperand_ParseFail;
3738 // Ranges must go from low to high.
3740 Error(AfterMinusLoc, "bad range in register list");
3741 return MatchOperand_ParseFail;
3743 // Parse the lane specifier if present.
3744 VectorLaneTy NextLaneKind;
3745 unsigned NextLaneIndex;
3746 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3747 MatchOperand_Success)
3748 return MatchOperand_ParseFail;
3749 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3750 Error(AfterMinusLoc, "mismatched lane index in register list");
3751 return MatchOperand_ParseFail;
3754 // Add all the registers in the range to the register list.
3755 Count += EndReg - Reg;
3759 Parser.Lex(); // Eat the comma.
3760 RegLoc = Parser.getTok().getLoc();
3762 Reg = tryParseRegister();
3764 Error(RegLoc, "register expected");
3765 return MatchOperand_ParseFail;
3767 // vector register lists must be contiguous.
3768 // It's OK to use the enumeration values directly here rather, as the
3769 // VFP register classes have the enum sorted properly.
3771 // The list is of D registers, but we also allow Q regs and just interpret
3772 // them as the two D sub-registers.
3773 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3775 Spacing = 1; // Register range implies a single spaced list.
3776 else if (Spacing == 2) {
3778 "invalid register in double-spaced list (must be 'D' register')");
3779 return MatchOperand_ParseFail;
3781 Reg = getDRegFromQReg(Reg);
3782 if (Reg != OldReg + 1) {
3783 Error(RegLoc, "non-contiguous register range");
3784 return MatchOperand_ParseFail;
3788 // Parse the lane specifier if present.
3789 VectorLaneTy NextLaneKind;
3790 unsigned NextLaneIndex;
3791 SMLoc LaneLoc = Parser.getTok().getLoc();
3792 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3793 MatchOperand_Success)
3794 return MatchOperand_ParseFail;
3795 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3796 Error(LaneLoc, "mismatched lane index in register list");
3797 return MatchOperand_ParseFail;
3801 // Normal D register.
3802 // Figure out the register spacing (single or double) of the list if
3803 // we don't know it already.
3805 Spacing = 1 + (Reg == OldReg + 2);
3807 // Just check that it's contiguous and keep going.
3808 if (Reg != OldReg + Spacing) {
3809 Error(RegLoc, "non-contiguous register range");
3810 return MatchOperand_ParseFail;
3813 // Parse the lane specifier if present.
3814 VectorLaneTy NextLaneKind;
3815 unsigned NextLaneIndex;
3816 SMLoc EndLoc = Parser.getTok().getLoc();
3817 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3818 return MatchOperand_ParseFail;
3819 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3820 Error(EndLoc, "mismatched lane index in register list");
3821 return MatchOperand_ParseFail;
3825 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3826 Error(Parser.getTok().getLoc(), "'}' expected");
3827 return MatchOperand_ParseFail;
3829 E = Parser.getTok().getEndLoc();
3830 Parser.Lex(); // Eat '}' token.
3834 // Two-register operands have been converted to the
3835 // composite register classes.
3837 const MCRegisterClass *RC = (Spacing == 1) ?
3838 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3839 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3840 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3843 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3844 (Spacing == 2), S, E));
3847 // Two-register operands have been converted to the
3848 // composite register classes.
3850 const MCRegisterClass *RC = (Spacing == 1) ?
3851 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3852 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3853 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3855 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3860 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3866 return MatchOperand_Success;
3869 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3870 ARMAsmParser::OperandMatchResultTy
3871 ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
3872 MCAsmParser &Parser = getParser();
3873 SMLoc S = Parser.getTok().getLoc();
3874 const AsmToken &Tok = Parser.getTok();
3877 if (Tok.is(AsmToken::Identifier)) {
3878 StringRef OptStr = Tok.getString();
3880 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3881 .Case("sy", ARM_MB::SY)
3882 .Case("st", ARM_MB::ST)
3883 .Case("ld", ARM_MB::LD)
3884 .Case("sh", ARM_MB::ISH)
3885 .Case("ish", ARM_MB::ISH)
3886 .Case("shst", ARM_MB::ISHST)
3887 .Case("ishst", ARM_MB::ISHST)
3888 .Case("ishld", ARM_MB::ISHLD)
3889 .Case("nsh", ARM_MB::NSH)
3890 .Case("un", ARM_MB::NSH)
3891 .Case("nshst", ARM_MB::NSHST)
3892 .Case("nshld", ARM_MB::NSHLD)
3893 .Case("unst", ARM_MB::NSHST)
3894 .Case("osh", ARM_MB::OSH)
3895 .Case("oshst", ARM_MB::OSHST)
3896 .Case("oshld", ARM_MB::OSHLD)
3899 // ishld, oshld, nshld and ld are only available from ARMv8.
3900 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3901 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3905 return MatchOperand_NoMatch;
3907 Parser.Lex(); // Eat identifier token.
3908 } else if (Tok.is(AsmToken::Hash) ||
3909 Tok.is(AsmToken::Dollar) ||
3910 Tok.is(AsmToken::Integer)) {
3911 if (Parser.getTok().isNot(AsmToken::Integer))
3912 Parser.Lex(); // Eat '#' or '$'.
3913 SMLoc Loc = Parser.getTok().getLoc();
3915 const MCExpr *MemBarrierID;
3916 if (getParser().parseExpression(MemBarrierID)) {
3917 Error(Loc, "illegal expression");
3918 return MatchOperand_ParseFail;
3921 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3923 Error(Loc, "constant expression expected");
3924 return MatchOperand_ParseFail;
3927 int Val = CE->getValue();
3929 Error(Loc, "immediate value out of range");
3930 return MatchOperand_ParseFail;
3933 Opt = ARM_MB::RESERVED_0 + Val;
3935 return MatchOperand_ParseFail;
3937 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3938 return MatchOperand_Success;
3941 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3942 ARMAsmParser::OperandMatchResultTy
3943 ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
3944 MCAsmParser &Parser = getParser();
3945 SMLoc S = Parser.getTok().getLoc();
3946 const AsmToken &Tok = Parser.getTok();
3949 if (Tok.is(AsmToken::Identifier)) {
3950 StringRef OptStr = Tok.getString();
3952 if (OptStr.equals_lower("sy"))
3955 return MatchOperand_NoMatch;
3957 Parser.Lex(); // Eat identifier token.
3958 } else if (Tok.is(AsmToken::Hash) ||
3959 Tok.is(AsmToken::Dollar) ||
3960 Tok.is(AsmToken::Integer)) {
3961 if (Parser.getTok().isNot(AsmToken::Integer))
3962 Parser.Lex(); // Eat '#' or '$'.
3963 SMLoc Loc = Parser.getTok().getLoc();
3965 const MCExpr *ISBarrierID;
3966 if (getParser().parseExpression(ISBarrierID)) {
3967 Error(Loc, "illegal expression");
3968 return MatchOperand_ParseFail;
3971 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3973 Error(Loc, "constant expression expected");
3974 return MatchOperand_ParseFail;
3977 int Val = CE->getValue();
3979 Error(Loc, "immediate value out of range");
3980 return MatchOperand_ParseFail;
3983 Opt = ARM_ISB::RESERVED_0 + Val;
3985 return MatchOperand_ParseFail;
3987 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3988 (ARM_ISB::InstSyncBOpt)Opt, S));
3989 return MatchOperand_Success;
3993 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3994 ARMAsmParser::OperandMatchResultTy
3995 ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
3996 MCAsmParser &Parser = getParser();
3997 SMLoc S = Parser.getTok().getLoc();
3998 const AsmToken &Tok = Parser.getTok();
3999 if (!Tok.is(AsmToken::Identifier))
4000 return MatchOperand_NoMatch;
4001 StringRef IFlagsStr = Tok.getString();
4003 // An iflags string of "none" is interpreted to mean that none of the AIF
4004 // bits are set. Not a terribly useful instruction, but a valid encoding.
4005 unsigned IFlags = 0;
4006 if (IFlagsStr != "none") {
4007 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
4008 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
4009 .Case("a", ARM_PROC::A)
4010 .Case("i", ARM_PROC::I)
4011 .Case("f", ARM_PROC::F)
4014 // If some specific iflag is already set, it means that some letter is
4015 // present more than once, this is not acceptable.
4016 if (Flag == ~0U || (IFlags & Flag))
4017 return MatchOperand_NoMatch;
4023 Parser.Lex(); // Eat identifier token.
4024 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
4025 return MatchOperand_Success;
4028 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
4029 ARMAsmParser::OperandMatchResultTy
4030 ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
4031 MCAsmParser &Parser = getParser();
4032 SMLoc S = Parser.getTok().getLoc();
4033 const AsmToken &Tok = Parser.getTok();
4034 if (!Tok.is(AsmToken::Identifier))
4035 return MatchOperand_NoMatch;
4036 StringRef Mask = Tok.getString();
4039 // See ARMv6-M 10.1.1
4040 std::string Name = Mask.lower();
4041 unsigned FlagsVal = StringSwitch<unsigned>(Name)
4042 // Note: in the documentation:
4043 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
4044 // for MSR APSR_nzcvq.
4045 // but we do make it an alias here. This is so to get the "mask encoding"
4046 // bits correct on MSR APSR writes.
4048 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
4049 // should really only be allowed when writing a special register. Note
4050 // they get dropped in the MRS instruction reading a special register as
4051 // the SYSm field is only 8 bits.
4052 .Case("apsr", 0x800)
4053 .Case("apsr_nzcvq", 0x800)
4054 .Case("apsr_g", 0x400)
4055 .Case("apsr_nzcvqg", 0xc00)
4056 .Case("iapsr", 0x801)
4057 .Case("iapsr_nzcvq", 0x801)
4058 .Case("iapsr_g", 0x401)
4059 .Case("iapsr_nzcvqg", 0xc01)
4060 .Case("eapsr", 0x802)
4061 .Case("eapsr_nzcvq", 0x802)
4062 .Case("eapsr_g", 0x402)
4063 .Case("eapsr_nzcvqg", 0xc02)
4064 .Case("xpsr", 0x803)
4065 .Case("xpsr_nzcvq", 0x803)
4066 .Case("xpsr_g", 0x403)
4067 .Case("xpsr_nzcvqg", 0xc03)
4068 .Case("ipsr", 0x805)
4069 .Case("epsr", 0x806)
4070 .Case("iepsr", 0x807)
4073 .Case("primask", 0x810)
4074 .Case("basepri", 0x811)
4075 .Case("basepri_max", 0x812)
4076 .Case("faultmask", 0x813)
4077 .Case("control", 0x814)
4080 if (FlagsVal == ~0U)
4081 return MatchOperand_NoMatch;
4083 if (!hasThumb2DSP() && (FlagsVal & 0x400))
4084 // The _g and _nzcvqg versions are only valid if the DSP extension is
4086 return MatchOperand_NoMatch;
4088 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
4089 // basepri, basepri_max and faultmask only valid for V7m.
4090 return MatchOperand_NoMatch;
4092 Parser.Lex(); // Eat identifier token.
4093 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4094 return MatchOperand_Success;
4097 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
4098 size_t Start = 0, Next = Mask.find('_');
4099 StringRef Flags = "";
4100 std::string SpecReg = Mask.slice(Start, Next).lower();
4101 if (Next != StringRef::npos)
4102 Flags = Mask.slice(Next+1, Mask.size());
4104 // FlagsVal contains the complete mask:
4106 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4107 unsigned FlagsVal = 0;
4109 if (SpecReg == "apsr") {
4110 FlagsVal = StringSwitch<unsigned>(Flags)
4111 .Case("nzcvq", 0x8) // same as CPSR_f
4112 .Case("g", 0x4) // same as CPSR_s
4113 .Case("nzcvqg", 0xc) // same as CPSR_fs
4116 if (FlagsVal == ~0U) {
4118 return MatchOperand_NoMatch;
4120 FlagsVal = 8; // No flag
4122 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
4123 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
4124 if (Flags == "all" || Flags == "")
4126 for (int i = 0, e = Flags.size(); i != e; ++i) {
4127 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
4134 // If some specific flag is already set, it means that some letter is
4135 // present more than once, this is not acceptable.
4136 if (FlagsVal == ~0U || (FlagsVal & Flag))
4137 return MatchOperand_NoMatch;
4140 } else // No match for special register.
4141 return MatchOperand_NoMatch;
4143 // Special register without flags is NOT equivalent to "fc" flags.
4144 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
4145 // two lines would enable gas compatibility at the expense of breaking
4151 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4152 if (SpecReg == "spsr")
4155 Parser.Lex(); // Eat identifier token.
4156 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4157 return MatchOperand_Success;
4160 /// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for
4161 /// use in the MRS/MSR instructions added to support virtualization.
4162 ARMAsmParser::OperandMatchResultTy
4163 ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) {
4164 MCAsmParser &Parser = getParser();
4165 SMLoc S = Parser.getTok().getLoc();
4166 const AsmToken &Tok = Parser.getTok();
4167 if (!Tok.is(AsmToken::Identifier))
4168 return MatchOperand_NoMatch;
4169 StringRef RegName = Tok.getString();
4171 // The values here come from B9.2.3 of the ARM ARM, where bits 4-0 are SysM
4173 unsigned Encoding = StringSwitch<unsigned>(RegName.lower())
4174 .Case("r8_usr", 0x00)
4175 .Case("r9_usr", 0x01)
4176 .Case("r10_usr", 0x02)
4177 .Case("r11_usr", 0x03)
4178 .Case("r12_usr", 0x04)
4179 .Case("sp_usr", 0x05)
4180 .Case("lr_usr", 0x06)
4181 .Case("r8_fiq", 0x08)
4182 .Case("r9_fiq", 0x09)
4183 .Case("r10_fiq", 0x0a)
4184 .Case("r11_fiq", 0x0b)
4185 .Case("r12_fiq", 0x0c)
4186 .Case("sp_fiq", 0x0d)
4187 .Case("lr_fiq", 0x0e)
4188 .Case("lr_irq", 0x10)
4189 .Case("sp_irq", 0x11)
4190 .Case("lr_svc", 0x12)
4191 .Case("sp_svc", 0x13)
4192 .Case("lr_abt", 0x14)
4193 .Case("sp_abt", 0x15)
4194 .Case("lr_und", 0x16)
4195 .Case("sp_und", 0x17)
4196 .Case("lr_mon", 0x1c)
4197 .Case("sp_mon", 0x1d)
4198 .Case("elr_hyp", 0x1e)
4199 .Case("sp_hyp", 0x1f)
4200 .Case("spsr_fiq", 0x2e)
4201 .Case("spsr_irq", 0x30)
4202 .Case("spsr_svc", 0x32)
4203 .Case("spsr_abt", 0x34)
4204 .Case("spsr_und", 0x36)
4205 .Case("spsr_mon", 0x3c)
4206 .Case("spsr_hyp", 0x3e)
4209 if (Encoding == ~0U)
4210 return MatchOperand_NoMatch;
4212 Parser.Lex(); // Eat identifier token.
4213 Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S));
4214 return MatchOperand_Success;
4217 ARMAsmParser::OperandMatchResultTy
4218 ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low,
4220 MCAsmParser &Parser = getParser();
4221 const AsmToken &Tok = Parser.getTok();
4222 if (Tok.isNot(AsmToken::Identifier)) {
4223 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4224 return MatchOperand_ParseFail;
4226 StringRef ShiftName = Tok.getString();
4227 std::string LowerOp = Op.lower();
4228 std::string UpperOp = Op.upper();
4229 if (ShiftName != LowerOp && ShiftName != UpperOp) {
4230 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4231 return MatchOperand_ParseFail;
4233 Parser.Lex(); // Eat shift type token.
4235 // There must be a '#' and a shift amount.
4236 if (Parser.getTok().isNot(AsmToken::Hash) &&
4237 Parser.getTok().isNot(AsmToken::Dollar)) {
4238 Error(Parser.getTok().getLoc(), "'#' expected");
4239 return MatchOperand_ParseFail;
4241 Parser.Lex(); // Eat hash token.
4243 const MCExpr *ShiftAmount;
4244 SMLoc Loc = Parser.getTok().getLoc();
4246 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
4247 Error(Loc, "illegal expression");
4248 return MatchOperand_ParseFail;
4250 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4252 Error(Loc, "constant expression expected");
4253 return MatchOperand_ParseFail;
4255 int Val = CE->getValue();
4256 if (Val < Low || Val > High) {
4257 Error(Loc, "immediate value out of range");
4258 return MatchOperand_ParseFail;
4261 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
4263 return MatchOperand_Success;
4266 ARMAsmParser::OperandMatchResultTy
4267 ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
4268 MCAsmParser &Parser = getParser();
4269 const AsmToken &Tok = Parser.getTok();
4270 SMLoc S = Tok.getLoc();
4271 if (Tok.isNot(AsmToken::Identifier)) {
4272 Error(S, "'be' or 'le' operand expected");
4273 return MatchOperand_ParseFail;
4275 int Val = StringSwitch<int>(Tok.getString().lower())
4279 Parser.Lex(); // Eat the token.
4282 Error(S, "'be' or 'le' operand expected");
4283 return MatchOperand_ParseFail;
4285 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4287 S, Tok.getEndLoc()));
4288 return MatchOperand_Success;
4291 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4292 /// instructions. Legal values are:
4293 /// lsl #n 'n' in [0,31]
4294 /// asr #n 'n' in [1,32]
4295 /// n == 32 encoded as n == 0.
4296 ARMAsmParser::OperandMatchResultTy
4297 ARMAsmParser::parseShifterImm(OperandVector &Operands) {
4298 MCAsmParser &Parser = getParser();
4299 const AsmToken &Tok = Parser.getTok();
4300 SMLoc S = Tok.getLoc();
4301 if (Tok.isNot(AsmToken::Identifier)) {
4302 Error(S, "shift operator 'asr' or 'lsl' expected");
4303 return MatchOperand_ParseFail;
4305 StringRef ShiftName = Tok.getString();
4307 if (ShiftName == "lsl" || ShiftName == "LSL")
4309 else if (ShiftName == "asr" || ShiftName == "ASR")
4312 Error(S, "shift operator 'asr' or 'lsl' expected");
4313 return MatchOperand_ParseFail;
4315 Parser.Lex(); // Eat the operator.
4317 // A '#' and a shift amount.
4318 if (Parser.getTok().isNot(AsmToken::Hash) &&
4319 Parser.getTok().isNot(AsmToken::Dollar)) {
4320 Error(Parser.getTok().getLoc(), "'#' expected");
4321 return MatchOperand_ParseFail;
4323 Parser.Lex(); // Eat hash token.
4324 SMLoc ExLoc = Parser.getTok().getLoc();
4326 const MCExpr *ShiftAmount;
4328 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
4329 Error(ExLoc, "malformed shift expression");
4330 return MatchOperand_ParseFail;
4332 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4334 Error(ExLoc, "shift amount must be an immediate");
4335 return MatchOperand_ParseFail;
4338 int64_t Val = CE->getValue();
4340 // Shift amount must be in [1,32]
4341 if (Val < 1 || Val > 32) {
4342 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
4343 return MatchOperand_ParseFail;
4345 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4346 if (isThumb() && Val == 32) {
4347 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
4348 return MatchOperand_ParseFail;
4350 if (Val == 32) Val = 0;
4352 // Shift amount must be in [1,32]
4353 if (Val < 0 || Val > 31) {
4354 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
4355 return MatchOperand_ParseFail;
4359 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
4361 return MatchOperand_Success;
4364 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4365 /// of instructions. Legal values are:
4366 /// ror #n 'n' in {0, 8, 16, 24}
4367 ARMAsmParser::OperandMatchResultTy
4368 ARMAsmParser::parseRotImm(OperandVector &Operands) {
4369 MCAsmParser &Parser = getParser();
4370 const AsmToken &Tok = Parser.getTok();
4371 SMLoc S = Tok.getLoc();
4372 if (Tok.isNot(AsmToken::Identifier))
4373 return MatchOperand_NoMatch;
4374 StringRef ShiftName = Tok.getString();
4375 if (ShiftName != "ror" && ShiftName != "ROR")
4376 return MatchOperand_NoMatch;
4377 Parser.Lex(); // Eat the operator.
4379 // A '#' and a rotate amount.
4380 if (Parser.getTok().isNot(AsmToken::Hash) &&
4381 Parser.getTok().isNot(AsmToken::Dollar)) {
4382 Error(Parser.getTok().getLoc(), "'#' expected");
4383 return MatchOperand_ParseFail;
4385 Parser.Lex(); // Eat hash token.
4386 SMLoc ExLoc = Parser.getTok().getLoc();
4388 const MCExpr *ShiftAmount;
4390 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
4391 Error(ExLoc, "malformed rotate expression");
4392 return MatchOperand_ParseFail;
4394 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4396 Error(ExLoc, "rotate amount must be an immediate");
4397 return MatchOperand_ParseFail;
4400 int64_t Val = CE->getValue();
4401 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4402 // normally, zero is represented in asm by omitting the rotate operand
4404 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
4405 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
4406 return MatchOperand_ParseFail;
4409 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
4411 return MatchOperand_Success;
4414 ARMAsmParser::OperandMatchResultTy
4415 ARMAsmParser::parseModImm(OperandVector &Operands) {
4416 MCAsmParser &Parser = getParser();
4417 MCAsmLexer &Lexer = getLexer();
4420 SMLoc S = Parser.getTok().getLoc();
4422 // 1) A mod_imm operand can appear in the place of a register name:
4424 // add r0, r0, #mod_imm
4425 // to correctly handle the latter, we bail out as soon as we see an
4428 // 2) Similarly, we do not want to parse into complex operands:
4430 // mov r0, :lower16:(_foo)
4431 if (Parser.getTok().is(AsmToken::Identifier) ||
4432 Parser.getTok().is(AsmToken::Colon))
4433 return MatchOperand_NoMatch;
4435 // Hash (dollar) is optional as per the ARMARM
4436 if (Parser.getTok().is(AsmToken::Hash) ||
4437 Parser.getTok().is(AsmToken::Dollar)) {
4438 // Avoid parsing into complex operands (#:)
4439 if (Lexer.peekTok().is(AsmToken::Colon))
4440 return MatchOperand_NoMatch;
4442 // Eat the hash (dollar)
4447 Sx1 = Parser.getTok().getLoc();
4448 const MCExpr *Imm1Exp;
4449 if (getParser().parseExpression(Imm1Exp, Ex1)) {
4450 Error(Sx1, "malformed expression");
4451 return MatchOperand_ParseFail;
4454 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp);
4457 // Immediate must fit within 32-bits
4458 Imm1 = CE->getValue();
4459 if (Imm1 < INT32_MIN || Imm1 > UINT32_MAX) {
4460 Error(Sx1, "immediate operand must be representable with 32 bits");
4461 return MatchOperand_ParseFail;
4464 int Enc = ARM_AM::getSOImmVal(Imm1);
4465 if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) {
4467 Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF),
4470 return MatchOperand_Success;
4473 // We have parsed an immediate which is not for us, fallback to a plain
4474 // immediate. This can happen for instruction aliases. For an example,
4475 // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform
4476 // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite
4477 // instruction with a mod_imm operand. The alias is defined such that the
4478 // parser method is shared, that's why we have to do this here.
4479 if (Parser.getTok().is(AsmToken::EndOfStatement)) {
4480 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4481 return MatchOperand_Success;
4484 // Operands like #(l1 - l2) can only be evaluated at a later stage (via an
4485 // MCFixup). Fallback to a plain immediate.
4486 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4487 return MatchOperand_Success;
4490 // From this point onward, we expect the input to be a (#bits, #rot) pair
4491 if (Parser.getTok().isNot(AsmToken::Comma)) {
4492 Error(Sx1, "expected modified immediate operand: #[0, 255], #even[0-30]");
4493 return MatchOperand_ParseFail;
4497 Error(Sx1, "immediate operand must a number in the range [0, 255]");
4498 return MatchOperand_ParseFail;
4506 Sx2 = Parser.getTok().getLoc();
4508 // Eat the optional hash (dollar)
4509 if (Parser.getTok().is(AsmToken::Hash) ||
4510 Parser.getTok().is(AsmToken::Dollar))
4513 const MCExpr *Imm2Exp;
4514 if (getParser().parseExpression(Imm2Exp, Ex2)) {
4515 Error(Sx2, "malformed expression");
4516 return MatchOperand_ParseFail;
4519 CE = dyn_cast<MCConstantExpr>(Imm2Exp);
4522 Imm2 = CE->getValue();
4523 if (!(Imm2 & ~0x1E)) {
4525 Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2));
4526 return MatchOperand_Success;
4528 Error(Sx2, "immediate operand must an even number in the range [0, 30]");
4529 return MatchOperand_ParseFail;
4531 Error(Sx2, "constant expression expected");
4532 return MatchOperand_ParseFail;
4536 ARMAsmParser::OperandMatchResultTy
4537 ARMAsmParser::parseBitfield(OperandVector &Operands) {
4538 MCAsmParser &Parser = getParser();
4539 SMLoc S = Parser.getTok().getLoc();
4540 // The bitfield descriptor is really two operands, the LSB and the width.
4541 if (Parser.getTok().isNot(AsmToken::Hash) &&
4542 Parser.getTok().isNot(AsmToken::Dollar)) {
4543 Error(Parser.getTok().getLoc(), "'#' expected");
4544 return MatchOperand_ParseFail;
4546 Parser.Lex(); // Eat hash token.
4548 const MCExpr *LSBExpr;
4549 SMLoc E = Parser.getTok().getLoc();
4550 if (getParser().parseExpression(LSBExpr)) {
4551 Error(E, "malformed immediate expression");
4552 return MatchOperand_ParseFail;
4554 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4556 Error(E, "'lsb' operand must be an immediate");
4557 return MatchOperand_ParseFail;
4560 int64_t LSB = CE->getValue();
4561 // The LSB must be in the range [0,31]
4562 if (LSB < 0 || LSB > 31) {
4563 Error(E, "'lsb' operand must be in the range [0,31]");
4564 return MatchOperand_ParseFail;
4566 E = Parser.getTok().getLoc();
4568 // Expect another immediate operand.
4569 if (Parser.getTok().isNot(AsmToken::Comma)) {
4570 Error(Parser.getTok().getLoc(), "too few operands");
4571 return MatchOperand_ParseFail;
4573 Parser.Lex(); // Eat hash token.
4574 if (Parser.getTok().isNot(AsmToken::Hash) &&
4575 Parser.getTok().isNot(AsmToken::Dollar)) {
4576 Error(Parser.getTok().getLoc(), "'#' expected");
4577 return MatchOperand_ParseFail;
4579 Parser.Lex(); // Eat hash token.
4581 const MCExpr *WidthExpr;
4583 if (getParser().parseExpression(WidthExpr, EndLoc)) {
4584 Error(E, "malformed immediate expression");
4585 return MatchOperand_ParseFail;
4587 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4589 Error(E, "'width' operand must be an immediate");
4590 return MatchOperand_ParseFail;
4593 int64_t Width = CE->getValue();
4594 // The LSB must be in the range [1,32-lsb]
4595 if (Width < 1 || Width > 32 - LSB) {
4596 Error(E, "'width' operand must be in the range [1,32-lsb]");
4597 return MatchOperand_ParseFail;
4600 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
4602 return MatchOperand_Success;
4605 ARMAsmParser::OperandMatchResultTy
4606 ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
4607 // Check for a post-index addressing register operand. Specifically:
4608 // postidx_reg := '+' register {, shift}
4609 // | '-' register {, shift}
4610 // | register {, shift}
4612 // This method must return MatchOperand_NoMatch without consuming any tokens
4613 // in the case where there is no match, as other alternatives take other
4615 MCAsmParser &Parser = getParser();
4616 AsmToken Tok = Parser.getTok();
4617 SMLoc S = Tok.getLoc();
4618 bool haveEaten = false;
4620 if (Tok.is(AsmToken::Plus)) {
4621 Parser.Lex(); // Eat the '+' token.
4623 } else if (Tok.is(AsmToken::Minus)) {
4624 Parser.Lex(); // Eat the '-' token.
4629 SMLoc E = Parser.getTok().getEndLoc();
4630 int Reg = tryParseRegister();
4633 return MatchOperand_NoMatch;
4634 Error(Parser.getTok().getLoc(), "register expected");
4635 return MatchOperand_ParseFail;
4638 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4639 unsigned ShiftImm = 0;
4640 if (Parser.getTok().is(AsmToken::Comma)) {
4641 Parser.Lex(); // Eat the ','.
4642 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4643 return MatchOperand_ParseFail;
4645 // FIXME: Only approximates end...may include intervening whitespace.
4646 E = Parser.getTok().getLoc();
4649 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4652 return MatchOperand_Success;
4655 ARMAsmParser::OperandMatchResultTy
4656 ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
4657 // Check for a post-index addressing register operand. Specifically:
4658 // am3offset := '+' register
4665 // This method must return MatchOperand_NoMatch without consuming any tokens
4666 // in the case where there is no match, as other alternatives take other
4668 MCAsmParser &Parser = getParser();
4669 AsmToken Tok = Parser.getTok();
4670 SMLoc S = Tok.getLoc();
4672 // Do immediates first, as we always parse those if we have a '#'.
4673 if (Parser.getTok().is(AsmToken::Hash) ||
4674 Parser.getTok().is(AsmToken::Dollar)) {
4675 Parser.Lex(); // Eat '#' or '$'.
4676 // Explicitly look for a '-', as we need to encode negative zero
4678 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4679 const MCExpr *Offset;
4681 if (getParser().parseExpression(Offset, E))
4682 return MatchOperand_ParseFail;
4683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4685 Error(S, "constant expression expected");
4686 return MatchOperand_ParseFail;
4688 // Negative zero is encoded as the flag value INT32_MIN.
4689 int32_t Val = CE->getValue();
4690 if (isNegative && Val == 0)
4694 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4696 return MatchOperand_Success;
4700 bool haveEaten = false;
4702 if (Tok.is(AsmToken::Plus)) {
4703 Parser.Lex(); // Eat the '+' token.
4705 } else if (Tok.is(AsmToken::Minus)) {
4706 Parser.Lex(); // Eat the '-' token.
4711 Tok = Parser.getTok();
4712 int Reg = tryParseRegister();
4715 return MatchOperand_NoMatch;
4716 Error(Tok.getLoc(), "register expected");
4717 return MatchOperand_ParseFail;
4720 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4721 0, S, Tok.getEndLoc()));
4723 return MatchOperand_Success;
4726 /// Convert parsed operands to MCInst. Needed here because this instruction
4727 /// only has two register operands, but multiplication is commutative so
4728 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4729 void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
4730 const OperandVector &Operands) {
4731 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
4732 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
4733 // If we have a three-operand form, make sure to set Rn to be the operand
4734 // that isn't the same as Rd.
4736 if (Operands.size() == 6 &&
4737 ((ARMOperand &)*Operands[4]).getReg() ==
4738 ((ARMOperand &)*Operands[3]).getReg())
4740 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
4741 Inst.addOperand(Inst.getOperand(0));
4742 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
4745 void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
4746 const OperandVector &Operands) {
4747 int CondOp = -1, ImmOp = -1;
4748 switch(Inst.getOpcode()) {
4750 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4753 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4755 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4757 // first decide whether or not the branch should be conditional
4758 // by looking at it's location relative to an IT block
4760 // inside an IT block we cannot have any conditional branches. any
4761 // such instructions needs to be converted to unconditional form
4762 switch(Inst.getOpcode()) {
4763 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4764 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4767 // outside IT blocks we can only have unconditional branches with AL
4768 // condition code or conditional branches with non-AL condition code
4769 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
4770 switch(Inst.getOpcode()) {
4773 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4777 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4782 // now decide on encoding size based on branch target range
4783 switch(Inst.getOpcode()) {
4784 // classify tB as either t2B or t1B based on range of immediate operand
4786 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4787 if (!op.isSignedOffset<11, 1>() && isThumbTwo())
4788 Inst.setOpcode(ARM::t2B);
4791 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4793 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4794 if (!op.isSignedOffset<8, 1>() && isThumbTwo())
4795 Inst.setOpcode(ARM::t2Bcc);
4799 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
4800 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
4803 /// Parse an ARM memory expression, return false if successful else return true
4804 /// or an error. The first token must be a '[' when called.
4805 bool ARMAsmParser::parseMemory(OperandVector &Operands) {
4806 MCAsmParser &Parser = getParser();
4808 assert(Parser.getTok().is(AsmToken::LBrac) &&
4809 "Token is not a Left Bracket");
4810 S = Parser.getTok().getLoc();
4811 Parser.Lex(); // Eat left bracket token.
4813 const AsmToken &BaseRegTok = Parser.getTok();
4814 int BaseRegNum = tryParseRegister();
4815 if (BaseRegNum == -1)
4816 return Error(BaseRegTok.getLoc(), "register expected");
4818 // The next token must either be a comma, a colon or a closing bracket.
4819 const AsmToken &Tok = Parser.getTok();
4820 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4821 !Tok.is(AsmToken::RBrac))
4822 return Error(Tok.getLoc(), "malformed memory operand");
4824 if (Tok.is(AsmToken::RBrac)) {
4825 E = Tok.getEndLoc();
4826 Parser.Lex(); // Eat right bracket token.
4828 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4829 ARM_AM::no_shift, 0, 0, false,
4832 // If there's a pre-indexing writeback marker, '!', just add it as a token
4833 // operand. It's rather odd, but syntactically valid.
4834 if (Parser.getTok().is(AsmToken::Exclaim)) {
4835 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4836 Parser.Lex(); // Eat the '!'.
4842 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4843 "Lost colon or comma in memory operand?!");
4844 if (Tok.is(AsmToken::Comma)) {
4845 Parser.Lex(); // Eat the comma.
4848 // If we have a ':', it's an alignment specifier.
4849 if (Parser.getTok().is(AsmToken::Colon)) {
4850 Parser.Lex(); // Eat the ':'.
4851 E = Parser.getTok().getLoc();
4852 SMLoc AlignmentLoc = Tok.getLoc();
4855 if (getParser().parseExpression(Expr))
4858 // The expression has to be a constant. Memory references with relocations
4859 // don't come through here, as they use the <label> forms of the relevant
4861 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4863 return Error (E, "constant expression expected");
4866 switch (CE->getValue()) {
4869 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4870 case 16: Align = 2; break;
4871 case 32: Align = 4; break;
4872 case 64: Align = 8; break;
4873 case 128: Align = 16; break;
4874 case 256: Align = 32; break;
4877 // Now we should have the closing ']'
4878 if (Parser.getTok().isNot(AsmToken::RBrac))
4879 return Error(Parser.getTok().getLoc(), "']' expected");
4880 E = Parser.getTok().getEndLoc();
4881 Parser.Lex(); // Eat right bracket token.
4883 // Don't worry about range checking the value here. That's handled by
4884 // the is*() predicates.
4885 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4886 ARM_AM::no_shift, 0, Align,
4887 false, S, E, AlignmentLoc));
4889 // If there's a pre-indexing writeback marker, '!', just add it as a token
4891 if (Parser.getTok().is(AsmToken::Exclaim)) {
4892 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4893 Parser.Lex(); // Eat the '!'.
4899 // If we have a '#', it's an immediate offset, else assume it's a register
4900 // offset. Be friendly and also accept a plain integer (without a leading
4901 // hash) for gas compatibility.
4902 if (Parser.getTok().is(AsmToken::Hash) ||
4903 Parser.getTok().is(AsmToken::Dollar) ||
4904 Parser.getTok().is(AsmToken::Integer)) {
4905 if (Parser.getTok().isNot(AsmToken::Integer))
4906 Parser.Lex(); // Eat '#' or '$'.
4907 E = Parser.getTok().getLoc();
4909 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4910 const MCExpr *Offset;
4911 if (getParser().parseExpression(Offset))
4914 // The expression has to be a constant. Memory references with relocations
4915 // don't come through here, as they use the <label> forms of the relevant
4917 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4919 return Error (E, "constant expression expected");
4921 // If the constant was #-0, represent it as INT32_MIN.
4922 int32_t Val = CE->getValue();
4923 if (isNegative && Val == 0)
4924 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4926 // Now we should have the closing ']'
4927 if (Parser.getTok().isNot(AsmToken::RBrac))
4928 return Error(Parser.getTok().getLoc(), "']' expected");
4929 E = Parser.getTok().getEndLoc();
4930 Parser.Lex(); // Eat right bracket token.
4932 // Don't worry about range checking the value here. That's handled by
4933 // the is*() predicates.
4934 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4935 ARM_AM::no_shift, 0, 0,
4938 // If there's a pre-indexing writeback marker, '!', just add it as a token
4940 if (Parser.getTok().is(AsmToken::Exclaim)) {
4941 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4942 Parser.Lex(); // Eat the '!'.
4948 // The register offset is optionally preceded by a '+' or '-'
4949 bool isNegative = false;
4950 if (Parser.getTok().is(AsmToken::Minus)) {
4952 Parser.Lex(); // Eat the '-'.
4953 } else if (Parser.getTok().is(AsmToken::Plus)) {
4955 Parser.Lex(); // Eat the '+'.
4958 E = Parser.getTok().getLoc();
4959 int OffsetRegNum = tryParseRegister();
4960 if (OffsetRegNum == -1)
4961 return Error(E, "register expected");
4963 // If there's a shift operator, handle it.
4964 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4965 unsigned ShiftImm = 0;
4966 if (Parser.getTok().is(AsmToken::Comma)) {
4967 Parser.Lex(); // Eat the ','.
4968 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4972 // Now we should have the closing ']'
4973 if (Parser.getTok().isNot(AsmToken::RBrac))
4974 return Error(Parser.getTok().getLoc(), "']' expected");
4975 E = Parser.getTok().getEndLoc();
4976 Parser.Lex(); // Eat right bracket token.
4978 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
4979 ShiftType, ShiftImm, 0, isNegative,
4982 // If there's a pre-indexing writeback marker, '!', just add it as a token
4984 if (Parser.getTok().is(AsmToken::Exclaim)) {
4985 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4986 Parser.Lex(); // Eat the '!'.
4992 /// parseMemRegOffsetShift - one of these two:
4993 /// ( lsl | lsr | asr | ror ) , # shift_amount
4995 /// return true if it parses a shift otherwise it returns false.
4996 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4998 MCAsmParser &Parser = getParser();
4999 SMLoc Loc = Parser.getTok().getLoc();
5000 const AsmToken &Tok = Parser.getTok();
5001 if (Tok.isNot(AsmToken::Identifier))
5003 StringRef ShiftName = Tok.getString();
5004 if (ShiftName == "lsl" || ShiftName == "LSL" ||
5005 ShiftName == "asl" || ShiftName == "ASL")
5007 else if (ShiftName == "lsr" || ShiftName == "LSR")
5009 else if (ShiftName == "asr" || ShiftName == "ASR")
5011 else if (ShiftName == "ror" || ShiftName == "ROR")
5013 else if (ShiftName == "rrx" || ShiftName == "RRX")
5016 return Error(Loc, "illegal shift operator");
5017 Parser.Lex(); // Eat shift type token.
5019 // rrx stands alone.
5021 if (St != ARM_AM::rrx) {
5022 Loc = Parser.getTok().getLoc();
5023 // A '#' and a shift amount.
5024 const AsmToken &HashTok = Parser.getTok();
5025 if (HashTok.isNot(AsmToken::Hash) &&
5026 HashTok.isNot(AsmToken::Dollar))
5027 return Error(HashTok.getLoc(), "'#' expected");
5028 Parser.Lex(); // Eat hash token.
5031 if (getParser().parseExpression(Expr))
5033 // Range check the immediate.
5034 // lsl, ror: 0 <= imm <= 31
5035 // lsr, asr: 0 <= imm <= 32
5036 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
5038 return Error(Loc, "shift amount must be an immediate");
5039 int64_t Imm = CE->getValue();
5041 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
5042 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
5043 return Error(Loc, "immediate shift value out of range");
5044 // If <ShiftTy> #0, turn it into a no_shift.
5047 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
5056 /// parseFPImm - A floating point immediate expression operand.
5057 ARMAsmParser::OperandMatchResultTy
5058 ARMAsmParser::parseFPImm(OperandVector &Operands) {
5059 MCAsmParser &Parser = getParser();
5060 // Anything that can accept a floating point constant as an operand
5061 // needs to go through here, as the regular parseExpression is
5064 // This routine still creates a generic Immediate operand, containing
5065 // a bitcast of the 64-bit floating point value. The various operands
5066 // that accept floats can check whether the value is valid for them
5067 // via the standard is*() predicates.
5069 SMLoc S = Parser.getTok().getLoc();
5071 if (Parser.getTok().isNot(AsmToken::Hash) &&
5072 Parser.getTok().isNot(AsmToken::Dollar))
5073 return MatchOperand_NoMatch;
5075 // Disambiguate the VMOV forms that can accept an FP immediate.
5076 // vmov.f32 <sreg>, #imm
5077 // vmov.f64 <dreg>, #imm
5078 // vmov.f32 <dreg>, #imm @ vector f32x2
5079 // vmov.f32 <qreg>, #imm @ vector f32x4
5081 // There are also the NEON VMOV instructions which expect an
5082 // integer constant. Make sure we don't try to parse an FPImm
5084 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
5085 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
5086 bool isVmovf = TyOp.isToken() &&
5087 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64");
5088 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
5089 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
5090 Mnemonic.getToken() == "fconsts");
5091 if (!(isVmovf || isFconst))
5092 return MatchOperand_NoMatch;
5094 Parser.Lex(); // Eat '#' or '$'.
5096 // Handle negation, as that still comes through as a separate token.
5097 bool isNegative = false;
5098 if (Parser.getTok().is(AsmToken::Minus)) {
5102 const AsmToken &Tok = Parser.getTok();
5103 SMLoc Loc = Tok.getLoc();
5104 if (Tok.is(AsmToken::Real) && isVmovf) {
5105 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
5106 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
5107 // If we had a '-' in front, toggle the sign bit.
5108 IntVal ^= (uint64_t)isNegative << 31;
5109 Parser.Lex(); // Eat the token.
5110 Operands.push_back(ARMOperand::CreateImm(
5111 MCConstantExpr::Create(IntVal, getContext()),
5112 S, Parser.getTok().getLoc()));
5113 return MatchOperand_Success;
5115 // Also handle plain integers. Instructions which allow floating point
5116 // immediates also allow a raw encoded 8-bit value.
5117 if (Tok.is(AsmToken::Integer) && isFconst) {
5118 int64_t Val = Tok.getIntVal();
5119 Parser.Lex(); // Eat the token.
5120 if (Val > 255 || Val < 0) {
5121 Error(Loc, "encoded floating point value out of range");
5122 return MatchOperand_ParseFail;
5124 float RealVal = ARM_AM::getFPImmFloat(Val);
5125 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
5127 Operands.push_back(ARMOperand::CreateImm(
5128 MCConstantExpr::Create(Val, getContext()), S,
5129 Parser.getTok().getLoc()));
5130 return MatchOperand_Success;
5133 Error(Loc, "invalid floating point immediate");
5134 return MatchOperand_ParseFail;
5137 /// Parse a arm instruction operand. For now this parses the operand regardless
5138 /// of the mnemonic.
5139 bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
5140 MCAsmParser &Parser = getParser();
5143 // Check if the current operand has a custom associated parser, if so, try to
5144 // custom parse the operand, or fallback to the general approach.
5145 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
5146 if (ResTy == MatchOperand_Success)
5148 // If there wasn't a custom match, try the generic matcher below. Otherwise,
5149 // there was a match, but an error occurred, in which case, just return that
5150 // the operand parsing failed.
5151 if (ResTy == MatchOperand_ParseFail)
5154 switch (getLexer().getKind()) {
5156 Error(Parser.getTok().getLoc(), "unexpected token in operand");
5158 case AsmToken::Identifier: {
5159 // If we've seen a branch mnemonic, the next operand must be a label. This
5160 // is true even if the label is a register name. So "br r1" means branch to
5162 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
5164 if (!tryParseRegisterWithWriteBack(Operands))
5166 int Res = tryParseShiftRegister(Operands);
5167 if (Res == 0) // success
5169 else if (Res == -1) // irrecoverable error
5171 // If this is VMRS, check for the apsr_nzcv operand.
5172 if (Mnemonic == "vmrs" &&
5173 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
5174 S = Parser.getTok().getLoc();
5176 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
5181 // Fall though for the Identifier case that is not a register or a
5184 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
5185 case AsmToken::Integer: // things like 1f and 2b as a branch targets
5186 case AsmToken::String: // quoted label names.
5187 case AsmToken::Dot: { // . as a branch target
5188 // This was not a register so parse other operands that start with an
5189 // identifier (like labels) as expressions and create them as immediates.
5190 const MCExpr *IdVal;
5191 S = Parser.getTok().getLoc();
5192 if (getParser().parseExpression(IdVal))
5194 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5195 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
5198 case AsmToken::LBrac:
5199 return parseMemory(Operands);
5200 case AsmToken::LCurly:
5201 return parseRegisterList(Operands);
5202 case AsmToken::Dollar:
5203 case AsmToken::Hash: {
5204 // #42 -> immediate.
5205 S = Parser.getTok().getLoc();
5208 if (Parser.getTok().isNot(AsmToken::Colon)) {
5209 bool isNegative = Parser.getTok().is(AsmToken::Minus);
5210 const MCExpr *ImmVal;
5211 if (getParser().parseExpression(ImmVal))
5213 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
5215 int32_t Val = CE->getValue();
5216 if (isNegative && Val == 0)
5217 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
5219 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5220 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
5222 // There can be a trailing '!' on operands that we want as a separate
5223 // '!' Token operand. Handle that here. For example, the compatibility
5224 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
5225 if (Parser.getTok().is(AsmToken::Exclaim)) {
5226 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
5227 Parser.getTok().getLoc()));
5228 Parser.Lex(); // Eat exclaim token
5232 // w/ a ':' after the '#', it's just like a plain ':'.
5235 case AsmToken::Colon: {
5236 // ":lower16:" and ":upper16:" expression prefixes
5237 // FIXME: Check it's an expression prefix,
5238 // e.g. (FOO - :lower16:BAR) isn't legal.
5239 ARMMCExpr::VariantKind RefKind;
5240 if (parsePrefix(RefKind))
5243 const MCExpr *SubExprVal;
5244 if (getParser().parseExpression(SubExprVal))
5247 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
5249 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5250 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
5253 case AsmToken::Equal: {
5254 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
5255 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
5257 Parser.Lex(); // Eat '='
5258 const MCExpr *SubExprVal;
5259 if (getParser().parseExpression(SubExprVal))
5261 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5263 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
5264 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
5270 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
5271 // :lower16: and :upper16:.
5272 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
5273 MCAsmParser &Parser = getParser();
5274 RefKind = ARMMCExpr::VK_ARM_None;
5276 // consume an optional '#' (GNU compatibility)
5277 if (getLexer().is(AsmToken::Hash))
5280 // :lower16: and :upper16: modifiers
5281 assert(getLexer().is(AsmToken::Colon) && "expected a :");
5282 Parser.Lex(); // Eat ':'
5284 if (getLexer().isNot(AsmToken::Identifier)) {
5285 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
5289 StringRef IDVal = Parser.getTok().getIdentifier();
5290 if (IDVal == "lower16") {
5291 RefKind = ARMMCExpr::VK_ARM_LO16;
5292 } else if (IDVal == "upper16") {
5293 RefKind = ARMMCExpr::VK_ARM_HI16;
5295 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
5300 if (getLexer().isNot(AsmToken::Colon)) {
5301 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
5304 Parser.Lex(); // Eat the last ':'
5308 /// \brief Given a mnemonic, split out possible predication code and carry
5309 /// setting letters to form a canonical mnemonic and flags.
5311 // FIXME: Would be nice to autogen this.
5312 // FIXME: This is a bit of a maze of special cases.
5313 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
5314 unsigned &PredicationCode,
5316 unsigned &ProcessorIMod,
5317 StringRef &ITMask) {
5318 PredicationCode = ARMCC::AL;
5319 CarrySetting = false;
5322 // Ignore some mnemonics we know aren't predicated forms.
5324 // FIXME: Would be nice to autogen this.
5325 if ((Mnemonic == "movs" && isThumb()) ||
5326 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
5327 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
5328 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
5329 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
5330 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
5331 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
5332 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
5333 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
5334 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
5335 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
5336 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
5337 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic == "hvc" ||
5338 Mnemonic.startswith("vsel"))
5341 // First, split out any predication code. Ignore mnemonics we know aren't
5342 // predicated but do have a carry-set and so weren't caught above.
5343 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
5344 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
5345 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
5346 Mnemonic != "sbcs" && Mnemonic != "rscs") {
5347 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
5348 .Case("eq", ARMCC::EQ)
5349 .Case("ne", ARMCC::NE)
5350 .Case("hs", ARMCC::HS)
5351 .Case("cs", ARMCC::HS)
5352 .Case("lo", ARMCC::LO)
5353 .Case("cc", ARMCC::LO)
5354 .Case("mi", ARMCC::MI)
5355 .Case("pl", ARMCC::PL)
5356 .Case("vs", ARMCC::VS)
5357 .Case("vc", ARMCC::VC)
5358 .Case("hi", ARMCC::HI)
5359 .Case("ls", ARMCC::LS)
5360 .Case("ge", ARMCC::GE)
5361 .Case("lt", ARMCC::LT)
5362 .Case("gt", ARMCC::GT)
5363 .Case("le", ARMCC::LE)
5364 .Case("al", ARMCC::AL)
5367 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5368 PredicationCode = CC;
5372 // Next, determine if we have a carry setting bit. We explicitly ignore all
5373 // the instructions we know end in 's'.
5374 if (Mnemonic.endswith("s") &&
5375 !(Mnemonic == "cps" || Mnemonic == "mls" ||
5376 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5377 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5378 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
5379 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
5380 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
5381 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
5382 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
5383 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
5384 (Mnemonic == "movs" && isThumb()))) {
5385 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5386 CarrySetting = true;
5389 // The "cps" instruction can have a interrupt mode operand which is glued into
5390 // the mnemonic. Check if this is the case, split it and parse the imod op
5391 if (Mnemonic.startswith("cps")) {
5392 // Split out any imod code.
5394 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5395 .Case("ie", ARM_PROC::IE)
5396 .Case("id", ARM_PROC::ID)
5399 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5400 ProcessorIMod = IMod;
5404 // The "it" instruction has the condition mask on the end of the mnemonic.
5405 if (Mnemonic.startswith("it")) {
5406 ITMask = Mnemonic.slice(2, Mnemonic.size());
5407 Mnemonic = Mnemonic.slice(0, 2);
5413 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
5414 /// inclusion of carry set or predication code operands.
5416 // FIXME: It would be nice to autogen this.
5418 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5419 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
5420 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5421 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
5422 Mnemonic == "add" || Mnemonic == "adc" ||
5423 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
5424 Mnemonic == "orr" || Mnemonic == "mvn" ||
5425 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
5426 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
5427 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
5428 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
5429 Mnemonic == "mla" || Mnemonic == "smlal" ||
5430 Mnemonic == "umlal" || Mnemonic == "umull"))) {
5431 CanAcceptCarrySet = true;
5433 CanAcceptCarrySet = false;
5435 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5436 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
5437 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5438 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
5439 Mnemonic.startswith("vsel") ||
5440 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
5441 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5442 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
5443 Mnemonic == "vrintm" || Mnemonic.startswith("aes") || Mnemonic == "hvc" ||
5444 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5445 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
5446 // These mnemonics are never predicable
5447 CanAcceptPredicationCode = false;
5448 } else if (!isThumb()) {
5449 // Some instructions are only predicable in Thumb mode
5450 CanAcceptPredicationCode
5451 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5452 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5453 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5454 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5455 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5456 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5457 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5458 } else if (isThumbOne()) {
5460 CanAcceptPredicationCode = Mnemonic != "movs";
5462 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
5464 CanAcceptPredicationCode = true;
5467 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
5468 OperandVector &Operands) {
5469 // FIXME: This is all horribly hacky. We really need a better way to deal
5470 // with optional operands like this in the matcher table.
5472 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5473 // another does not. Specifically, the MOVW instruction does not. So we
5474 // special case it here and remove the defaulted (non-setting) cc_out
5475 // operand if that's the instruction we're trying to match.
5477 // We do this as post-processing of the explicit operands rather than just
5478 // conditionally adding the cc_out in the first place because we need
5479 // to check the type of the parsed immediate operand.
5480 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
5481 !static_cast<ARMOperand &>(*Operands[4]).isARMSOImm() &&
5482 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5483 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
5486 // Register-register 'add' for thumb does not have a cc_out operand
5487 // when there are only two register operands.
5488 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
5489 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5490 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5491 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
5493 // Register-register 'add' for thumb does not have a cc_out operand
5494 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5495 // have to check the immediate range here since Thumb2 has a variant
5496 // that can handle a different range and has a cc_out operand.
5497 if (((isThumb() && Mnemonic == "add") ||
5498 (isThumbTwo() && Mnemonic == "sub")) &&
5499 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5500 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5501 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5502 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5503 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5504 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
5506 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5507 // imm0_4095 variant. That's the least-preferred variant when
5508 // selecting via the generic "add" mnemonic, so to know that we
5509 // should remove the cc_out operand, we have to explicitly check that
5510 // it's not one of the other variants. Ugh.
5511 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5512 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5513 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5514 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5515 // Nest conditions rather than one big 'if' statement for readability.
5517 // If both registers are low, we're in an IT block, and the immediate is
5518 // in range, we should use encoding T1 instead, which has a cc_out.
5520 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5521 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5522 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
5524 // Check against T3. If the second register is the PC, this is an
5525 // alternate form of ADR, which uses encoding T4, so check for that too.
5526 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5527 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
5530 // Otherwise, we use encoding T4, which does not have a cc_out
5535 // The thumb2 multiply instruction doesn't have a CCOut register, so
5536 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5537 // use the 16-bit encoding or not.
5538 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5539 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5540 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5541 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5542 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
5543 // If the registers aren't low regs, the destination reg isn't the
5544 // same as one of the source regs, or the cc_out operand is zero
5545 // outside of an IT block, we have to use the 32-bit encoding, so
5546 // remove the cc_out operand.
5547 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5548 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5549 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5550 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5551 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5552 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5553 static_cast<ARMOperand &>(*Operands[4]).getReg())))
5556 // Also check the 'mul' syntax variant that doesn't specify an explicit
5557 // destination register.
5558 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5559 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5560 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5561 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5562 // If the registers aren't low regs or the cc_out operand is zero
5563 // outside of an IT block, we have to use the 32-bit encoding, so
5564 // remove the cc_out operand.
5565 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5566 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5572 // Register-register 'add/sub' for thumb does not have a cc_out operand
5573 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5574 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5575 // right, this will result in better diagnostics (which operand is off)
5577 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5578 (Operands.size() == 5 || Operands.size() == 6) &&
5579 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5580 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5581 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5582 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
5583 (Operands.size() == 6 &&
5584 static_cast<ARMOperand &>(*Operands[5]).isImm())))
5590 bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5591 OperandVector &Operands) {
5592 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5593 unsigned RegIdx = 3;
5594 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5595 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5596 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5597 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
5600 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5601 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5602 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5603 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5604 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
5610 static bool isDataTypeToken(StringRef Tok) {
5611 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5612 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5613 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5614 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5615 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5616 Tok == ".f" || Tok == ".d";
5619 // FIXME: This bit should probably be handled via an explicit match class
5620 // in the .td files that matches the suffix instead of having it be
5621 // a literal string token the way it is now.
5622 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5623 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5625 static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features,
5626 unsigned VariantID);
5628 static bool RequiresVFPRegListValidation(StringRef Inst,
5629 bool &AcceptSinglePrecisionOnly,
5630 bool &AcceptDoublePrecisionOnly) {
5631 if (Inst.size() < 7)
5634 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5635 StringRef AddressingMode = Inst.substr(4, 2);
5636 if (AddressingMode == "ia" || AddressingMode == "db" ||
5637 AddressingMode == "ea" || AddressingMode == "fd") {
5638 AcceptSinglePrecisionOnly = Inst[6] == 's';
5639 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5647 /// Parse an arm instruction mnemonic followed by its operands.
5648 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5649 SMLoc NameLoc, OperandVector &Operands) {
5650 MCAsmParser &Parser = getParser();
5651 // FIXME: Can this be done via tablegen in some fashion?
5652 bool RequireVFPRegisterListCheck;
5653 bool AcceptSinglePrecisionOnly;
5654 bool AcceptDoublePrecisionOnly;
5655 RequireVFPRegisterListCheck =
5656 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5657 AcceptDoublePrecisionOnly);
5659 // Apply mnemonic aliases before doing anything else, as the destination
5660 // mnemonic may include suffices and we want to handle them normally.
5661 // The generic tblgen'erated code does this later, at the start of
5662 // MatchInstructionImpl(), but that's too late for aliases that include
5663 // any sort of suffix.
5664 uint64_t AvailableFeatures = getAvailableFeatures();
5665 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5666 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5668 // First check for the ARM-specific .req directive.
5669 if (Parser.getTok().is(AsmToken::Identifier) &&
5670 Parser.getTok().getIdentifier() == ".req") {
5671 parseDirectiveReq(Name, NameLoc);
5672 // We always return 'error' for this, as we're done with this
5673 // statement and don't need to match the 'instruction."
5677 // Create the leading tokens for the mnemonic, split by '.' characters.
5678 size_t Start = 0, Next = Name.find('.');
5679 StringRef Mnemonic = Name.slice(Start, Next);
5681 // Split out the predication code and carry setting flag from the mnemonic.
5682 unsigned PredicationCode;
5683 unsigned ProcessorIMod;
5686 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5687 ProcessorIMod, ITMask);
5689 // In Thumb1, only the branch (B) instruction can be predicated.
5690 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5691 Parser.eatToEndOfStatement();
5692 return Error(NameLoc, "conditional execution not supported in Thumb1");
5695 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5697 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5698 // is the mask as it will be for the IT encoding if the conditional
5699 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5700 // where the conditional bit0 is zero, the instruction post-processing
5701 // will adjust the mask accordingly.
5702 if (Mnemonic == "it") {
5703 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5704 if (ITMask.size() > 3) {
5705 Parser.eatToEndOfStatement();
5706 return Error(Loc, "too many conditions on IT instruction");
5709 for (unsigned i = ITMask.size(); i != 0; --i) {
5710 char pos = ITMask[i - 1];
5711 if (pos != 't' && pos != 'e') {
5712 Parser.eatToEndOfStatement();
5713 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5716 if (ITMask[i - 1] == 't')
5719 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5722 // FIXME: This is all a pretty gross hack. We should automatically handle
5723 // optional operands like this via tblgen.
5725 // Next, add the CCOut and ConditionCode operands, if needed.
5727 // For mnemonics which can ever incorporate a carry setting bit or predication
5728 // code, our matching model involves us always generating CCOut and
5729 // ConditionCode operands to match the mnemonic "as written" and then we let
5730 // the matcher deal with finding the right instruction or generating an
5731 // appropriate error.
5732 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5733 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5735 // If we had a carry-set on an instruction that can't do that, issue an
5737 if (!CanAcceptCarrySet && CarrySetting) {
5738 Parser.eatToEndOfStatement();
5739 return Error(NameLoc, "instruction '" + Mnemonic +
5740 "' can not set flags, but 's' suffix specified");
5742 // If we had a predication code on an instruction that can't do that, issue an
5744 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5745 Parser.eatToEndOfStatement();
5746 return Error(NameLoc, "instruction '" + Mnemonic +
5747 "' is not predicable, but condition code specified");
5750 // Add the carry setting operand, if necessary.
5751 if (CanAcceptCarrySet) {
5752 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5753 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5757 // Add the predication code operand, if necessary.
5758 if (CanAcceptPredicationCode) {
5759 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5761 Operands.push_back(ARMOperand::CreateCondCode(
5762 ARMCC::CondCodes(PredicationCode), Loc));
5765 // Add the processor imod operand, if necessary.
5766 if (ProcessorIMod) {
5767 Operands.push_back(ARMOperand::CreateImm(
5768 MCConstantExpr::Create(ProcessorIMod, getContext()),
5770 } else if (Mnemonic == "cps" && isMClass()) {
5771 return Error(NameLoc, "instruction 'cps' requires effect for M-class");
5774 // Add the remaining tokens in the mnemonic.
5775 while (Next != StringRef::npos) {
5777 Next = Name.find('.', Start + 1);
5778 StringRef ExtraToken = Name.slice(Start, Next);
5780 // Some NEON instructions have an optional datatype suffix that is
5781 // completely ignored. Check for that.
5782 if (isDataTypeToken(ExtraToken) &&
5783 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5786 // For for ARM mode generate an error if the .n qualifier is used.
5787 if (ExtraToken == ".n" && !isThumb()) {
5788 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5789 Parser.eatToEndOfStatement();
5790 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5794 // The .n qualifier is always discarded as that is what the tables
5795 // and matcher expect. In ARM mode the .w qualifier has no effect,
5796 // so discard it to avoid errors that can be caused by the matcher.
5797 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5798 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5799 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5803 // Read the remaining operands.
5804 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5805 // Read the first operand.
5806 if (parseOperand(Operands, Mnemonic)) {
5807 Parser.eatToEndOfStatement();
5811 while (getLexer().is(AsmToken::Comma)) {
5812 Parser.Lex(); // Eat the comma.
5814 // Parse and remember the operand.
5815 if (parseOperand(Operands, Mnemonic)) {
5816 Parser.eatToEndOfStatement();
5822 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5823 SMLoc Loc = getLexer().getLoc();
5824 Parser.eatToEndOfStatement();
5825 return Error(Loc, "unexpected token in argument list");
5828 Parser.Lex(); // Consume the EndOfStatement
5830 if (RequireVFPRegisterListCheck) {
5831 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5832 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5833 return Error(Op.getStartLoc(),
5834 "VFP/Neon single precision register expected");
5835 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5836 return Error(Op.getStartLoc(),
5837 "VFP/Neon double precision register expected");
5840 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5841 // do and don't have a cc_out optional-def operand. With some spot-checks
5842 // of the operand list, we can figure out which variant we're trying to
5843 // parse and adjust accordingly before actually matching. We shouldn't ever
5844 // try to remove a cc_out operand that was explicitly set on the the
5845 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5846 // table driven matcher doesn't fit well with the ARM instruction set.
5847 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
5848 Operands.erase(Operands.begin() + 1);
5850 // Some instructions have the same mnemonic, but don't always
5851 // have a predicate. Distinguish them here and delete the
5852 // predicate if needed.
5853 if (shouldOmitPredicateOperand(Mnemonic, Operands))
5854 Operands.erase(Operands.begin() + 1);
5856 // ARM mode 'blx' need special handling, as the register operand version
5857 // is predicable, but the label operand version is not. So, we can't rely
5858 // on the Mnemonic based checking to correctly figure out when to put
5859 // a k_CondCode operand in the list. If we're trying to match the label
5860 // version, remove the k_CondCode operand here.
5861 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5862 static_cast<ARMOperand &>(*Operands[2]).isImm())
5863 Operands.erase(Operands.begin() + 1);
5865 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5866 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5867 // a single GPRPair reg operand is used in the .td file to replace the two
5868 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5869 // expressed as a GPRPair, so we have to manually merge them.
5870 // FIXME: We would really like to be able to tablegen'erate this.
5871 if (!isThumb() && Operands.size() > 4 &&
5872 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5873 Mnemonic == "stlexd")) {
5874 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5875 unsigned Idx = isLoad ? 2 : 3;
5876 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5877 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
5879 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5880 // Adjust only if Op1 and Op2 are GPRs.
5881 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5882 MRC.contains(Op2.getReg())) {
5883 unsigned Reg1 = Op1.getReg();
5884 unsigned Reg2 = Op2.getReg();
5885 unsigned Rt = MRI->getEncodingValue(Reg1);
5886 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5888 // Rt2 must be Rt + 1 and Rt must be even.
5889 if (Rt + 1 != Rt2 || (Rt & 1)) {
5890 Error(Op2.getStartLoc(), isLoad
5891 ? "destination operands must be sequential"
5892 : "source operands must be sequential");
5895 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5896 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5898 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5899 Operands.erase(Operands.begin() + Idx + 1);
5903 // If first 2 operands of a 3 operand instruction are the same
5904 // then transform to 2 operand version of the same instruction
5905 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1'
5906 // FIXME: We would really like to be able to tablegen'erate this.
5907 if (isThumbOne() && Operands.size() == 6 &&
5908 (Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" ||
5909 Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5910 Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" ||
5911 Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) {
5912 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5913 ARMOperand &Op4 = static_cast<ARMOperand &>(*Operands[4]);
5914 ARMOperand &Op5 = static_cast<ARMOperand &>(*Operands[5]);
5916 // If both registers are the same then remove one of them from
5917 // the operand list.
5918 if (Op3.isReg() && Op4.isReg() && Op3.getReg() == Op4.getReg()) {
5919 // If 3rd operand (variable Op5) is a register and the instruction is adds/sub
5920 // then do not transform as the backend already handles this instruction
5922 if (!Op5.isReg() || !((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub")) {
5923 Operands.erase(Operands.begin() + 3);
5924 if (Mnemonic == "add" && !CarrySetting) {
5925 // Special case for 'add' (not 'adds') instruction must
5926 // remove the CCOut operand as well.
5927 Operands.erase(Operands.begin() + 1);
5933 // If instruction is 'add' and first two register operands
5934 // use SP register, then remove one of the SP registers from
5936 // FIXME: We would really like to be able to tablegen'erate this.
5937 if (isThumbOne() && Operands.size() == 5 && Mnemonic == "add" && !CarrySetting) {
5938 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5939 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5940 if (Op2.isReg() && Op3.isReg() && Op2.getReg() == ARM::SP && Op3.getReg() == ARM::SP) {
5941 Operands.erase(Operands.begin() + 2);
5945 // GNU Assembler extension (compatibility)
5946 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
5947 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5948 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5950 assert(Op2.isReg() && "expected register argument");
5952 unsigned SuperReg = MRI->getMatchingSuperReg(
5953 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
5955 assert(SuperReg && "expected register pair");
5957 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
5960 Operands.begin() + 3,
5961 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
5965 // FIXME: As said above, this is all a pretty gross hack. This instruction
5966 // does not fit with other "subs" and tblgen.
5967 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5968 // so the Mnemonic is the original name "subs" and delete the predicate
5969 // operand so it will match the table entry.
5970 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5971 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5972 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5973 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5974 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5975 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5976 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
5977 Operands.erase(Operands.begin() + 1);
5982 // Validate context-sensitive operand constraints.
5984 // return 'true' if register list contains non-low GPR registers,
5985 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5986 // 'containsReg' to true.
5987 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5988 unsigned HiReg, bool &containsReg) {
5989 containsReg = false;
5990 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5991 unsigned OpReg = Inst.getOperand(i).getReg();
5994 // Anything other than a low register isn't legal here.
5995 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
6001 // Check if the specified regisgter is in the register list of the inst,
6002 // starting at the indicated operand number.
6003 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
6004 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
6005 unsigned OpReg = Inst.getOperand(i).getReg();
6012 // Return true if instruction has the interesting property of being
6013 // allowed in IT blocks, but not being predicable.
6014 static bool instIsBreakpoint(const MCInst &Inst) {
6015 return Inst.getOpcode() == ARM::tBKPT ||
6016 Inst.getOpcode() == ARM::BKPT ||
6017 Inst.getOpcode() == ARM::tHLT ||
6018 Inst.getOpcode() == ARM::HLT;
6022 bool ARMAsmParser::validatetLDMRegList(MCInst Inst,
6023 const OperandVector &Operands,
6024 unsigned ListNo, bool IsPop) {
6025 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
6026 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
6028 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
6029 bool ListContainsLR = listContainsReg(Inst, ListNo, ARM::LR);
6030 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
6032 if (!IsPop && ListContainsSP)
6033 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6034 "SP may not be in the register list");
6035 else if (ListContainsPC && ListContainsLR)
6036 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6037 "PC and LR may not be in the register list simultaneously");
6038 else if (inITBlock() && !lastInITBlock() && ListContainsPC)
6039 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6040 "instruction must be outside of IT block or the last "
6041 "instruction in an IT block");
6045 bool ARMAsmParser::validatetSTMRegList(MCInst Inst,
6046 const OperandVector &Operands,
6048 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
6049 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
6051 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
6052 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
6054 if (ListContainsSP && ListContainsPC)
6055 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6056 "SP and PC may not be in the register list");
6057 else if (ListContainsSP)
6058 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6059 "SP may not be in the register list");
6060 else if (ListContainsPC)
6061 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6062 "PC may not be in the register list");
6066 // FIXME: We would really like to be able to tablegen'erate this.
6067 bool ARMAsmParser::validateInstruction(MCInst &Inst,
6068 const OperandVector &Operands) {
6069 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
6070 SMLoc Loc = Operands[0]->getStartLoc();
6072 // Check the IT block state first.
6073 // NOTE: BKPT and HLT instructions have the interesting property of being
6074 // allowed in IT blocks, but not being predicable. They just always execute.
6075 if (inITBlock() && !instIsBreakpoint(Inst)) {
6077 if (ITState.FirstCond)
6078 ITState.FirstCond = false;
6080 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
6081 // The instruction must be predicable.
6082 if (!MCID.isPredicable())
6083 return Error(Loc, "instructions in IT block must be predicable");
6084 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
6085 unsigned ITCond = Bit ? ITState.Cond :
6086 ARMCC::getOppositeCondition(ITState.Cond);
6087 if (Cond != ITCond) {
6088 // Find the condition code Operand to get its SMLoc information.
6090 for (unsigned I = 1; I < Operands.size(); ++I)
6091 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
6092 CondLoc = Operands[I]->getStartLoc();
6093 return Error(CondLoc, "incorrect condition in IT block; got '" +
6094 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
6095 "', but expected '" +
6096 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
6098 // Check for non-'al' condition codes outside of the IT block.
6099 } else if (isThumbTwo() && MCID.isPredicable() &&
6100 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
6101 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
6102 Inst.getOpcode() != ARM::t2Bcc)
6103 return Error(Loc, "predicated instructions must be in IT block");
6105 const unsigned Opcode = Inst.getOpcode();
6109 case ARM::LDRD_POST: {
6110 const unsigned RtReg = Inst.getOperand(0).getReg();
6113 if (RtReg == ARM::LR)
6114 return Error(Operands[3]->getStartLoc(),
6117 const unsigned Rt = MRI->getEncodingValue(RtReg);
6118 // Rt must be even-numbered.
6120 return Error(Operands[3]->getStartLoc(),
6121 "Rt must be even-numbered");
6123 // Rt2 must be Rt + 1.
6124 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6126 return Error(Operands[3]->getStartLoc(),
6127 "destination operands must be sequential");
6129 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
6130 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
6131 // For addressing modes with writeback, the base register needs to be
6132 // different from the destination registers.
6133 if (Rn == Rt || Rn == Rt2)
6134 return Error(Operands[3]->getStartLoc(),
6135 "base register needs to be different from destination "
6142 case ARM::t2LDRD_PRE:
6143 case ARM::t2LDRD_POST: {
6144 // Rt2 must be different from Rt.
6145 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6146 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6148 return Error(Operands[3]->getStartLoc(),
6149 "destination operands can't be identical");
6153 // Rt2 must be Rt + 1.
6154 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6155 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6157 return Error(Operands[3]->getStartLoc(),
6158 "source operands must be sequential");
6162 case ARM::STRD_POST: {
6163 // Rt2 must be Rt + 1.
6164 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6165 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6167 return Error(Operands[3]->getStartLoc(),
6168 "source operands must be sequential");
6171 case ARM::STR_PRE_IMM:
6172 case ARM::STR_PRE_REG:
6173 case ARM::STR_POST_IMM:
6174 case ARM::STR_POST_REG:
6176 case ARM::STRH_POST:
6177 case ARM::STRB_PRE_IMM:
6178 case ARM::STRB_PRE_REG:
6179 case ARM::STRB_POST_IMM:
6180 case ARM::STRB_POST_REG: {
6181 // Rt must be different from Rn.
6182 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6183 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6186 return Error(Operands[3]->getStartLoc(),
6187 "source register and base register can't be identical");
6190 case ARM::LDR_PRE_IMM:
6191 case ARM::LDR_PRE_REG:
6192 case ARM::LDR_POST_IMM:
6193 case ARM::LDR_POST_REG:
6195 case ARM::LDRH_POST:
6196 case ARM::LDRSH_PRE:
6197 case ARM::LDRSH_POST:
6198 case ARM::LDRB_PRE_IMM:
6199 case ARM::LDRB_PRE_REG:
6200 case ARM::LDRB_POST_IMM:
6201 case ARM::LDRB_POST_REG:
6202 case ARM::LDRSB_PRE:
6203 case ARM::LDRSB_POST: {
6204 // Rt must be different from Rn.
6205 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6206 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6209 return Error(Operands[3]->getStartLoc(),
6210 "destination register and base register can't be identical");
6215 // Width must be in range [1, 32-lsb].
6216 unsigned LSB = Inst.getOperand(2).getImm();
6217 unsigned Widthm1 = Inst.getOperand(3).getImm();
6218 if (Widthm1 >= 32 - LSB)
6219 return Error(Operands[5]->getStartLoc(),
6220 "bitfield width must be in range [1,32-lsb]");
6223 // Notionally handles ARM::tLDMIA_UPD too.
6225 // If we're parsing Thumb2, the .w variant is available and handles
6226 // most cases that are normally illegal for a Thumb1 LDM instruction.
6227 // We'll make the transformation in processInstruction() if necessary.
6229 // Thumb LDM instructions are writeback iff the base register is not
6230 // in the register list.
6231 unsigned Rn = Inst.getOperand(0).getReg();
6232 bool HasWritebackToken =
6233 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
6234 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
6235 bool ListContainsBase;
6236 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
6237 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
6238 "registers must be in range r0-r7");
6239 // If we should have writeback, then there should be a '!' token.
6240 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
6241 return Error(Operands[2]->getStartLoc(),
6242 "writeback operator '!' expected");
6243 // If we should not have writeback, there must not be a '!'. This is
6244 // true even for the 32-bit wide encodings.
6245 if (ListContainsBase && HasWritebackToken)
6246 return Error(Operands[3]->getStartLoc(),
6247 "writeback operator '!' not allowed when base register "
6248 "in register list");
6250 if (validatetLDMRegList(Inst, Operands, 3))
6254 case ARM::LDMIA_UPD:
6255 case ARM::LDMDB_UPD:
6256 case ARM::LDMIB_UPD:
6257 case ARM::LDMDA_UPD:
6258 // ARM variants loading and updating the same register are only officially
6259 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
6262 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6263 return Error(Operands.back()->getStartLoc(),
6264 "writeback register not allowed in register list");
6268 if (validatetLDMRegList(Inst, Operands, 3))
6273 if (validatetSTMRegList(Inst, Operands, 3))
6276 case ARM::t2LDMIA_UPD:
6277 case ARM::t2LDMDB_UPD:
6278 case ARM::t2STMIA_UPD:
6279 case ARM::t2STMDB_UPD: {
6280 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6281 return Error(Operands.back()->getStartLoc(),
6282 "writeback register not allowed in register list");
6284 if (Opcode == ARM::t2LDMIA_UPD || Opcode == ARM::t2LDMDB_UPD) {
6285 if (validatetLDMRegList(Inst, Operands, 4))
6288 if (validatetSTMRegList(Inst, Operands, 4))
6293 case ARM::sysLDMIA_UPD:
6294 case ARM::sysLDMDA_UPD:
6295 case ARM::sysLDMDB_UPD:
6296 case ARM::sysLDMIB_UPD:
6297 if (!listContainsReg(Inst, 3, ARM::PC))
6298 return Error(Operands[4]->getStartLoc(),
6299 "writeback register only allowed on system LDM "
6300 "if PC in register-list");
6302 case ARM::sysSTMIA_UPD:
6303 case ARM::sysSTMDA_UPD:
6304 case ARM::sysSTMDB_UPD:
6305 case ARM::sysSTMIB_UPD:
6306 return Error(Operands[2]->getStartLoc(),
6307 "system STM cannot have writeback register");
6309 // The second source operand must be the same register as the destination
6312 // In this case, we must directly check the parsed operands because the
6313 // cvtThumbMultiply() function is written in such a way that it guarantees
6314 // this first statement is always true for the new Inst. Essentially, the
6315 // destination is unconditionally copied into the second source operand
6316 // without checking to see if it matches what we actually parsed.
6317 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
6318 ((ARMOperand &)*Operands[5]).getReg()) &&
6319 (((ARMOperand &)*Operands[3]).getReg() !=
6320 ((ARMOperand &)*Operands[4]).getReg())) {
6321 return Error(Operands[3]->getStartLoc(),
6322 "destination register must match source register");
6326 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
6327 // so only issue a diagnostic for thumb1. The instructions will be
6328 // switched to the t2 encodings in processInstruction() if necessary.
6330 bool ListContainsBase;
6331 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
6333 return Error(Operands[2]->getStartLoc(),
6334 "registers must be in range r0-r7 or pc");
6335 if (validatetLDMRegList(Inst, Operands, 2, /*IsPop=*/true))
6340 bool ListContainsBase;
6341 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
6343 return Error(Operands[2]->getStartLoc(),
6344 "registers must be in range r0-r7 or lr");
6345 if (validatetSTMRegList(Inst, Operands, 2))
6349 case ARM::tSTMIA_UPD: {
6350 bool ListContainsBase, InvalidLowList;
6351 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
6352 0, ListContainsBase);
6353 if (InvalidLowList && !isThumbTwo())
6354 return Error(Operands[4]->getStartLoc(),
6355 "registers must be in range r0-r7");
6357 // This would be converted to a 32-bit stm, but that's not valid if the
6358 // writeback register is in the list.
6359 if (InvalidLowList && ListContainsBase)
6360 return Error(Operands[4]->getStartLoc(),
6361 "writeback operator '!' not allowed when base register "
6362 "in register list");
6364 if (validatetSTMRegList(Inst, Operands, 4))
6368 case ARM::tADDrSP: {
6369 // If the non-SP source operand and the destination operand are not the
6370 // same, we need thumb2 (for the wide encoding), or we have an error.
6371 if (!isThumbTwo() &&
6372 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
6373 return Error(Operands[4]->getStartLoc(),
6374 "source register must be the same as destination");
6378 // Final range checking for Thumb unconditional branch instructions.
6380 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
6381 return Error(Operands[2]->getStartLoc(), "branch target out of range");
6384 int op = (Operands[2]->isImm()) ? 2 : 3;
6385 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
6386 return Error(Operands[op]->getStartLoc(), "branch target out of range");
6389 // Final range checking for Thumb conditional branch instructions.
6391 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
6392 return Error(Operands[2]->getStartLoc(), "branch target out of range");
6395 int Op = (Operands[2]->isImm()) ? 2 : 3;
6396 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
6397 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
6402 case ARM::t2MOVTi16:
6404 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
6405 // especially when we turn it into a movw and the expression <symbol> does
6406 // not have a :lower16: or :upper16 as part of the expression. We don't
6407 // want the behavior of silently truncating, which can be unexpected and
6408 // lead to bugs that are difficult to find since this is an easy mistake
6410 int i = (Operands[3]->isImm()) ? 3 : 4;
6411 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
6412 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
6414 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
6416 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
6417 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
6418 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
6421 "immediate expression for mov requires :lower16: or :upper16");
6429 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
6431 default: llvm_unreachable("unexpected opcode!");
6433 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6434 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6435 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6436 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6437 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6438 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6439 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
6440 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
6441 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
6444 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6445 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6446 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6447 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6448 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
6450 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6451 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6452 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6453 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6454 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
6456 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
6457 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
6458 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
6459 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
6460 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
6463 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6464 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6465 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6466 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
6467 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6468 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6469 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6470 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6471 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
6472 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6473 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
6474 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
6475 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
6476 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6477 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
6480 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6481 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6482 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6483 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6484 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6485 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6486 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6487 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6488 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6489 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6490 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6491 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6492 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6493 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6494 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6495 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6496 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6497 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
6500 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6501 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6502 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6503 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6504 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6505 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6506 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6507 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6508 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6509 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6510 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6511 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6512 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6513 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6514 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6517 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6518 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6519 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6520 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6521 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6522 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6523 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6524 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6525 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6526 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6527 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6528 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6529 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6530 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6531 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6532 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6533 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6534 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
6538 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
6540 default: llvm_unreachable("unexpected opcode!");
6542 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6543 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6544 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6545 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6546 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6547 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6548 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6549 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6550 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
6553 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6554 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6555 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6556 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6557 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6558 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6559 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6560 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6561 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6562 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6563 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6564 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6565 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6566 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6567 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
6570 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6571 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6572 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6573 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
6574 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6575 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6576 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6577 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6578 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6579 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6580 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6581 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6582 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6583 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6584 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6585 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6586 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6587 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6590 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6591 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6592 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6593 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6594 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6595 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6596 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6597 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6598 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6599 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6600 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6601 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6602 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6603 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6604 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
6607 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6608 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6609 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6610 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6611 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6612 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6613 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6614 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6615 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6616 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6617 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6618 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6619 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6620 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6621 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6622 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6623 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6624 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
6627 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6628 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6629 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6630 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6631 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6632 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6633 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6634 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6635 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6636 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6637 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6638 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6639 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6640 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6641 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6644 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6645 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6646 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6647 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6648 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6649 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6650 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6651 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6652 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6653 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6654 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6655 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6656 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6657 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6658 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6659 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6660 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6661 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6664 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6665 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6666 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6667 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6668 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6669 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6670 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6671 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6672 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6673 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6674 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6675 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6676 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6677 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6678 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6679 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6680 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6681 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
6685 bool ARMAsmParser::processInstruction(MCInst &Inst,
6686 const OperandVector &Operands,
6688 switch (Inst.getOpcode()) {
6689 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6690 case ARM::LDRT_POST:
6691 case ARM::LDRBT_POST: {
6692 const unsigned Opcode =
6693 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6694 : ARM::LDRBT_POST_IMM;
6696 TmpInst.setOpcode(Opcode);
6697 TmpInst.addOperand(Inst.getOperand(0));
6698 TmpInst.addOperand(Inst.getOperand(1));
6699 TmpInst.addOperand(Inst.getOperand(1));
6700 TmpInst.addOperand(MCOperand::CreateReg(0));
6701 TmpInst.addOperand(MCOperand::CreateImm(0));
6702 TmpInst.addOperand(Inst.getOperand(2));
6703 TmpInst.addOperand(Inst.getOperand(3));
6707 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6708 case ARM::STRT_POST:
6709 case ARM::STRBT_POST: {
6710 const unsigned Opcode =
6711 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6712 : ARM::STRBT_POST_IMM;
6714 TmpInst.setOpcode(Opcode);
6715 TmpInst.addOperand(Inst.getOperand(1));
6716 TmpInst.addOperand(Inst.getOperand(0));
6717 TmpInst.addOperand(Inst.getOperand(1));
6718 TmpInst.addOperand(MCOperand::CreateReg(0));
6719 TmpInst.addOperand(MCOperand::CreateImm(0));
6720 TmpInst.addOperand(Inst.getOperand(2));
6721 TmpInst.addOperand(Inst.getOperand(3));
6725 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6727 if (Inst.getOperand(1).getReg() != ARM::PC ||
6728 Inst.getOperand(5).getReg() != 0 ||
6729 !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm()))
6732 TmpInst.setOpcode(ARM::ADR);
6733 TmpInst.addOperand(Inst.getOperand(0));
6734 if (Inst.getOperand(2).isImm()) {
6735 // Immediate (mod_imm) will be in its encoded form, we must unencode it
6736 // before passing it to the ADR instruction.
6737 unsigned Enc = Inst.getOperand(2).getImm();
6738 TmpInst.addOperand(MCOperand::CreateImm(
6739 ARM_AM::rotr32(Enc & 0xFF, (Enc & 0xF00) >> 7)));
6741 // Turn PC-relative expression into absolute expression.
6742 // Reading PC provides the start of the current instruction + 8 and
6743 // the transform to adr is biased by that.
6744 MCSymbol *Dot = getContext().CreateTempSymbol();
6746 const MCExpr *OpExpr = Inst.getOperand(2).getExpr();
6747 const MCExpr *InstPC = MCSymbolRefExpr::Create(Dot,
6748 MCSymbolRefExpr::VK_None,
6750 const MCExpr *Const8 = MCConstantExpr::Create(8, getContext());
6751 const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8,
6753 const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr,
6755 TmpInst.addOperand(MCOperand::CreateExpr(FixupAddr));
6757 TmpInst.addOperand(Inst.getOperand(3));
6758 TmpInst.addOperand(Inst.getOperand(4));
6762 // Aliases for alternate PC+imm syntax of LDR instructions.
6763 case ARM::t2LDRpcrel:
6764 // Select the narrow version if the immediate will fit.
6765 if (Inst.getOperand(1).getImm() > 0 &&
6766 Inst.getOperand(1).getImm() <= 0xff &&
6767 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6768 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
6769 Inst.setOpcode(ARM::tLDRpci);
6771 Inst.setOpcode(ARM::t2LDRpci);
6773 case ARM::t2LDRBpcrel:
6774 Inst.setOpcode(ARM::t2LDRBpci);
6776 case ARM::t2LDRHpcrel:
6777 Inst.setOpcode(ARM::t2LDRHpci);
6779 case ARM::t2LDRSBpcrel:
6780 Inst.setOpcode(ARM::t2LDRSBpci);
6782 case ARM::t2LDRSHpcrel:
6783 Inst.setOpcode(ARM::t2LDRSHpci);
6785 // Handle NEON VST complex aliases.
6786 case ARM::VST1LNdWB_register_Asm_8:
6787 case ARM::VST1LNdWB_register_Asm_16:
6788 case ARM::VST1LNdWB_register_Asm_32: {
6790 // Shuffle the operands around so the lane index operand is in the
6793 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6794 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6795 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6796 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6797 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6798 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6799 TmpInst.addOperand(Inst.getOperand(1)); // lane
6800 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6801 TmpInst.addOperand(Inst.getOperand(6));
6806 case ARM::VST2LNdWB_register_Asm_8:
6807 case ARM::VST2LNdWB_register_Asm_16:
6808 case ARM::VST2LNdWB_register_Asm_32:
6809 case ARM::VST2LNqWB_register_Asm_16:
6810 case ARM::VST2LNqWB_register_Asm_32: {
6812 // Shuffle the operands around so the lane index operand is in the
6815 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6816 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6817 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6818 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6819 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6820 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6821 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6823 TmpInst.addOperand(Inst.getOperand(1)); // lane
6824 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6825 TmpInst.addOperand(Inst.getOperand(6));
6830 case ARM::VST3LNdWB_register_Asm_8:
6831 case ARM::VST3LNdWB_register_Asm_16:
6832 case ARM::VST3LNdWB_register_Asm_32:
6833 case ARM::VST3LNqWB_register_Asm_16:
6834 case ARM::VST3LNqWB_register_Asm_32: {
6836 // Shuffle the operands around so the lane index operand is in the
6839 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6840 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6841 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6842 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6843 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6844 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6845 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6847 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6849 TmpInst.addOperand(Inst.getOperand(1)); // lane
6850 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6851 TmpInst.addOperand(Inst.getOperand(6));
6856 case ARM::VST4LNdWB_register_Asm_8:
6857 case ARM::VST4LNdWB_register_Asm_16:
6858 case ARM::VST4LNdWB_register_Asm_32:
6859 case ARM::VST4LNqWB_register_Asm_16:
6860 case ARM::VST4LNqWB_register_Asm_32: {
6862 // Shuffle the operands around so the lane index operand is in the
6865 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6866 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6867 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6868 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6869 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6870 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6871 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6873 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6875 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6877 TmpInst.addOperand(Inst.getOperand(1)); // lane
6878 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6879 TmpInst.addOperand(Inst.getOperand(6));
6884 case ARM::VST1LNdWB_fixed_Asm_8:
6885 case ARM::VST1LNdWB_fixed_Asm_16:
6886 case ARM::VST1LNdWB_fixed_Asm_32: {
6888 // Shuffle the operands around so the lane index operand is in the
6891 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6892 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6893 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6894 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6895 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6896 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6897 TmpInst.addOperand(Inst.getOperand(1)); // lane
6898 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6899 TmpInst.addOperand(Inst.getOperand(5));
6904 case ARM::VST2LNdWB_fixed_Asm_8:
6905 case ARM::VST2LNdWB_fixed_Asm_16:
6906 case ARM::VST2LNdWB_fixed_Asm_32:
6907 case ARM::VST2LNqWB_fixed_Asm_16:
6908 case ARM::VST2LNqWB_fixed_Asm_32: {
6910 // Shuffle the operands around so the lane index operand is in the
6913 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6914 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6915 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6916 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6917 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6918 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6919 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6921 TmpInst.addOperand(Inst.getOperand(1)); // lane
6922 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6923 TmpInst.addOperand(Inst.getOperand(5));
6928 case ARM::VST3LNdWB_fixed_Asm_8:
6929 case ARM::VST3LNdWB_fixed_Asm_16:
6930 case ARM::VST3LNdWB_fixed_Asm_32:
6931 case ARM::VST3LNqWB_fixed_Asm_16:
6932 case ARM::VST3LNqWB_fixed_Asm_32: {
6934 // Shuffle the operands around so the lane index operand is in the
6937 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6938 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6939 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6940 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6941 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6942 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6943 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6945 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6947 TmpInst.addOperand(Inst.getOperand(1)); // lane
6948 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6949 TmpInst.addOperand(Inst.getOperand(5));
6954 case ARM::VST4LNdWB_fixed_Asm_8:
6955 case ARM::VST4LNdWB_fixed_Asm_16:
6956 case ARM::VST4LNdWB_fixed_Asm_32:
6957 case ARM::VST4LNqWB_fixed_Asm_16:
6958 case ARM::VST4LNqWB_fixed_Asm_32: {
6960 // Shuffle the operands around so the lane index operand is in the
6963 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6964 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6965 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6966 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6967 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6968 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6969 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6971 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6973 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6975 TmpInst.addOperand(Inst.getOperand(1)); // lane
6976 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6977 TmpInst.addOperand(Inst.getOperand(5));
6982 case ARM::VST1LNdAsm_8:
6983 case ARM::VST1LNdAsm_16:
6984 case ARM::VST1LNdAsm_32: {
6986 // Shuffle the operands around so the lane index operand is in the
6989 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6990 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6991 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6992 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6993 TmpInst.addOperand(Inst.getOperand(1)); // lane
6994 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6995 TmpInst.addOperand(Inst.getOperand(5));
7000 case ARM::VST2LNdAsm_8:
7001 case ARM::VST2LNdAsm_16:
7002 case ARM::VST2LNdAsm_32:
7003 case ARM::VST2LNqAsm_16:
7004 case ARM::VST2LNqAsm_32: {
7006 // Shuffle the operands around so the lane index operand is in the
7009 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7010 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7011 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7012 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7013 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7015 TmpInst.addOperand(Inst.getOperand(1)); // lane
7016 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7017 TmpInst.addOperand(Inst.getOperand(5));
7022 case ARM::VST3LNdAsm_8:
7023 case ARM::VST3LNdAsm_16:
7024 case ARM::VST3LNdAsm_32:
7025 case ARM::VST3LNqAsm_16:
7026 case ARM::VST3LNqAsm_32: {
7028 // Shuffle the operands around so the lane index operand is in the
7031 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7032 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7033 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7034 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7035 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7037 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7039 TmpInst.addOperand(Inst.getOperand(1)); // lane
7040 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7041 TmpInst.addOperand(Inst.getOperand(5));
7046 case ARM::VST4LNdAsm_8:
7047 case ARM::VST4LNdAsm_16:
7048 case ARM::VST4LNdAsm_32:
7049 case ARM::VST4LNqAsm_16:
7050 case ARM::VST4LNqAsm_32: {
7052 // Shuffle the operands around so the lane index operand is in the
7055 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7056 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7057 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7058 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7059 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7061 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7063 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7065 TmpInst.addOperand(Inst.getOperand(1)); // lane
7066 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7067 TmpInst.addOperand(Inst.getOperand(5));
7072 // Handle NEON VLD complex aliases.
7073 case ARM::VLD1LNdWB_register_Asm_8:
7074 case ARM::VLD1LNdWB_register_Asm_16:
7075 case ARM::VLD1LNdWB_register_Asm_32: {
7077 // Shuffle the operands around so the lane index operand is in the
7080 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7081 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7082 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7083 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7084 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7085 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7086 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7087 TmpInst.addOperand(Inst.getOperand(1)); // lane
7088 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7089 TmpInst.addOperand(Inst.getOperand(6));
7094 case ARM::VLD2LNdWB_register_Asm_8:
7095 case ARM::VLD2LNdWB_register_Asm_16:
7096 case ARM::VLD2LNdWB_register_Asm_32:
7097 case ARM::VLD2LNqWB_register_Asm_16:
7098 case ARM::VLD2LNqWB_register_Asm_32: {
7100 // Shuffle the operands around so the lane index operand is in the
7103 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7104 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7105 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7107 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7108 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7109 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7110 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7111 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7112 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7114 TmpInst.addOperand(Inst.getOperand(1)); // lane
7115 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7116 TmpInst.addOperand(Inst.getOperand(6));
7121 case ARM::VLD3LNdWB_register_Asm_8:
7122 case ARM::VLD3LNdWB_register_Asm_16:
7123 case ARM::VLD3LNdWB_register_Asm_32:
7124 case ARM::VLD3LNqWB_register_Asm_16:
7125 case ARM::VLD3LNqWB_register_Asm_32: {
7127 // Shuffle the operands around so the lane index operand is in the
7130 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7131 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7132 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7134 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7136 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7137 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7138 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7139 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7140 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7141 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7143 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7145 TmpInst.addOperand(Inst.getOperand(1)); // lane
7146 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7147 TmpInst.addOperand(Inst.getOperand(6));
7152 case ARM::VLD4LNdWB_register_Asm_8:
7153 case ARM::VLD4LNdWB_register_Asm_16:
7154 case ARM::VLD4LNdWB_register_Asm_32:
7155 case ARM::VLD4LNqWB_register_Asm_16:
7156 case ARM::VLD4LNqWB_register_Asm_32: {
7158 // Shuffle the operands around so the lane index operand is in the
7161 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7162 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7163 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7165 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7167 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7169 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7170 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7171 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7172 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7173 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7174 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7176 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7178 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7180 TmpInst.addOperand(Inst.getOperand(1)); // lane
7181 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7182 TmpInst.addOperand(Inst.getOperand(6));
7187 case ARM::VLD1LNdWB_fixed_Asm_8:
7188 case ARM::VLD1LNdWB_fixed_Asm_16:
7189 case ARM::VLD1LNdWB_fixed_Asm_32: {
7191 // Shuffle the operands around so the lane index operand is in the
7194 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7195 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7196 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7197 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7198 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7199 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7200 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7201 TmpInst.addOperand(Inst.getOperand(1)); // lane
7202 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7203 TmpInst.addOperand(Inst.getOperand(5));
7208 case ARM::VLD2LNdWB_fixed_Asm_8:
7209 case ARM::VLD2LNdWB_fixed_Asm_16:
7210 case ARM::VLD2LNdWB_fixed_Asm_32:
7211 case ARM::VLD2LNqWB_fixed_Asm_16:
7212 case ARM::VLD2LNqWB_fixed_Asm_32: {
7214 // Shuffle the operands around so the lane index operand is in the
7217 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7218 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7219 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7221 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7222 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7223 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7224 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7225 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7226 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7228 TmpInst.addOperand(Inst.getOperand(1)); // lane
7229 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7230 TmpInst.addOperand(Inst.getOperand(5));
7235 case ARM::VLD3LNdWB_fixed_Asm_8:
7236 case ARM::VLD3LNdWB_fixed_Asm_16:
7237 case ARM::VLD3LNdWB_fixed_Asm_32:
7238 case ARM::VLD3LNqWB_fixed_Asm_16:
7239 case ARM::VLD3LNqWB_fixed_Asm_32: {
7241 // Shuffle the operands around so the lane index operand is in the
7244 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7245 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7246 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7248 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7250 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7251 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7252 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7253 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7254 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7255 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7257 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7259 TmpInst.addOperand(Inst.getOperand(1)); // lane
7260 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7261 TmpInst.addOperand(Inst.getOperand(5));
7266 case ARM::VLD4LNdWB_fixed_Asm_8:
7267 case ARM::VLD4LNdWB_fixed_Asm_16:
7268 case ARM::VLD4LNdWB_fixed_Asm_32:
7269 case ARM::VLD4LNqWB_fixed_Asm_16:
7270 case ARM::VLD4LNqWB_fixed_Asm_32: {
7272 // Shuffle the operands around so the lane index operand is in the
7275 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7276 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7277 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7279 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7281 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7283 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7284 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7285 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7286 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7287 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7288 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7290 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7292 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7294 TmpInst.addOperand(Inst.getOperand(1)); // lane
7295 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7296 TmpInst.addOperand(Inst.getOperand(5));
7301 case ARM::VLD1LNdAsm_8:
7302 case ARM::VLD1LNdAsm_16:
7303 case ARM::VLD1LNdAsm_32: {
7305 // Shuffle the operands around so the lane index operand is in the
7308 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7309 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7310 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7311 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7312 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7313 TmpInst.addOperand(Inst.getOperand(1)); // lane
7314 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7315 TmpInst.addOperand(Inst.getOperand(5));
7320 case ARM::VLD2LNdAsm_8:
7321 case ARM::VLD2LNdAsm_16:
7322 case ARM::VLD2LNdAsm_32:
7323 case ARM::VLD2LNqAsm_16:
7324 case ARM::VLD2LNqAsm_32: {
7326 // Shuffle the operands around so the lane index operand is in the
7329 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7330 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7331 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7333 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7334 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7335 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7336 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7338 TmpInst.addOperand(Inst.getOperand(1)); // lane
7339 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7340 TmpInst.addOperand(Inst.getOperand(5));
7345 case ARM::VLD3LNdAsm_8:
7346 case ARM::VLD3LNdAsm_16:
7347 case ARM::VLD3LNdAsm_32:
7348 case ARM::VLD3LNqAsm_16:
7349 case ARM::VLD3LNqAsm_32: {
7351 // Shuffle the operands around so the lane index operand is in the
7354 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7355 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7356 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7360 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7361 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7362 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7363 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7365 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7367 TmpInst.addOperand(Inst.getOperand(1)); // lane
7368 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7369 TmpInst.addOperand(Inst.getOperand(5));
7374 case ARM::VLD4LNdAsm_8:
7375 case ARM::VLD4LNdAsm_16:
7376 case ARM::VLD4LNdAsm_32:
7377 case ARM::VLD4LNqAsm_16:
7378 case ARM::VLD4LNqAsm_32: {
7380 // Shuffle the operands around so the lane index operand is in the
7383 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7384 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7385 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7387 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7389 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7391 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7392 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7393 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7394 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7396 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7400 TmpInst.addOperand(Inst.getOperand(1)); // lane
7401 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7402 TmpInst.addOperand(Inst.getOperand(5));
7407 // VLD3DUP single 3-element structure to all lanes instructions.
7408 case ARM::VLD3DUPdAsm_8:
7409 case ARM::VLD3DUPdAsm_16:
7410 case ARM::VLD3DUPdAsm_32:
7411 case ARM::VLD3DUPqAsm_8:
7412 case ARM::VLD3DUPqAsm_16:
7413 case ARM::VLD3DUPqAsm_32: {
7416 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7417 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7418 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7422 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7423 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7424 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7425 TmpInst.addOperand(Inst.getOperand(4));
7430 case ARM::VLD3DUPdWB_fixed_Asm_8:
7431 case ARM::VLD3DUPdWB_fixed_Asm_16:
7432 case ARM::VLD3DUPdWB_fixed_Asm_32:
7433 case ARM::VLD3DUPqWB_fixed_Asm_8:
7434 case ARM::VLD3DUPqWB_fixed_Asm_16:
7435 case ARM::VLD3DUPqWB_fixed_Asm_32: {
7438 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7439 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7440 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7442 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7444 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7445 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7446 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7447 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7448 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7449 TmpInst.addOperand(Inst.getOperand(4));
7454 case ARM::VLD3DUPdWB_register_Asm_8:
7455 case ARM::VLD3DUPdWB_register_Asm_16:
7456 case ARM::VLD3DUPdWB_register_Asm_32:
7457 case ARM::VLD3DUPqWB_register_Asm_8:
7458 case ARM::VLD3DUPqWB_register_Asm_16:
7459 case ARM::VLD3DUPqWB_register_Asm_32: {
7462 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7463 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7464 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7466 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7468 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7469 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7470 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7471 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7472 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7473 TmpInst.addOperand(Inst.getOperand(5));
7478 // VLD3 multiple 3-element structure instructions.
7479 case ARM::VLD3dAsm_8:
7480 case ARM::VLD3dAsm_16:
7481 case ARM::VLD3dAsm_32:
7482 case ARM::VLD3qAsm_8:
7483 case ARM::VLD3qAsm_16:
7484 case ARM::VLD3qAsm_32: {
7487 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7488 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7489 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7491 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7493 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7494 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7495 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7496 TmpInst.addOperand(Inst.getOperand(4));
7501 case ARM::VLD3dWB_fixed_Asm_8:
7502 case ARM::VLD3dWB_fixed_Asm_16:
7503 case ARM::VLD3dWB_fixed_Asm_32:
7504 case ARM::VLD3qWB_fixed_Asm_8:
7505 case ARM::VLD3qWB_fixed_Asm_16:
7506 case ARM::VLD3qWB_fixed_Asm_32: {
7509 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7510 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7511 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7513 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7515 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7516 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7517 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7518 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7519 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7520 TmpInst.addOperand(Inst.getOperand(4));
7525 case ARM::VLD3dWB_register_Asm_8:
7526 case ARM::VLD3dWB_register_Asm_16:
7527 case ARM::VLD3dWB_register_Asm_32:
7528 case ARM::VLD3qWB_register_Asm_8:
7529 case ARM::VLD3qWB_register_Asm_16:
7530 case ARM::VLD3qWB_register_Asm_32: {
7533 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7534 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7535 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7537 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7539 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7540 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7541 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7542 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7543 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7544 TmpInst.addOperand(Inst.getOperand(5));
7549 // VLD4DUP single 3-element structure to all lanes instructions.
7550 case ARM::VLD4DUPdAsm_8:
7551 case ARM::VLD4DUPdAsm_16:
7552 case ARM::VLD4DUPdAsm_32:
7553 case ARM::VLD4DUPqAsm_8:
7554 case ARM::VLD4DUPqAsm_16:
7555 case ARM::VLD4DUPqAsm_32: {
7558 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7559 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7560 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7562 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7564 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7566 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7567 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7568 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7569 TmpInst.addOperand(Inst.getOperand(4));
7574 case ARM::VLD4DUPdWB_fixed_Asm_8:
7575 case ARM::VLD4DUPdWB_fixed_Asm_16:
7576 case ARM::VLD4DUPdWB_fixed_Asm_32:
7577 case ARM::VLD4DUPqWB_fixed_Asm_8:
7578 case ARM::VLD4DUPqWB_fixed_Asm_16:
7579 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7582 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7583 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7584 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7586 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7588 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7590 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7591 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7592 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7593 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7594 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7595 TmpInst.addOperand(Inst.getOperand(4));
7600 case ARM::VLD4DUPdWB_register_Asm_8:
7601 case ARM::VLD4DUPdWB_register_Asm_16:
7602 case ARM::VLD4DUPdWB_register_Asm_32:
7603 case ARM::VLD4DUPqWB_register_Asm_8:
7604 case ARM::VLD4DUPqWB_register_Asm_16:
7605 case ARM::VLD4DUPqWB_register_Asm_32: {
7608 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7609 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7610 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7612 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7614 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7616 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7617 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7618 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7619 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7620 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7621 TmpInst.addOperand(Inst.getOperand(5));
7626 // VLD4 multiple 4-element structure instructions.
7627 case ARM::VLD4dAsm_8:
7628 case ARM::VLD4dAsm_16:
7629 case ARM::VLD4dAsm_32:
7630 case ARM::VLD4qAsm_8:
7631 case ARM::VLD4qAsm_16:
7632 case ARM::VLD4qAsm_32: {
7635 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7636 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7637 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7639 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7643 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7644 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7645 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7646 TmpInst.addOperand(Inst.getOperand(4));
7651 case ARM::VLD4dWB_fixed_Asm_8:
7652 case ARM::VLD4dWB_fixed_Asm_16:
7653 case ARM::VLD4dWB_fixed_Asm_32:
7654 case ARM::VLD4qWB_fixed_Asm_8:
7655 case ARM::VLD4qWB_fixed_Asm_16:
7656 case ARM::VLD4qWB_fixed_Asm_32: {
7659 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7660 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7661 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7663 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7665 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7667 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7668 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7669 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7670 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7671 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7672 TmpInst.addOperand(Inst.getOperand(4));
7677 case ARM::VLD4dWB_register_Asm_8:
7678 case ARM::VLD4dWB_register_Asm_16:
7679 case ARM::VLD4dWB_register_Asm_32:
7680 case ARM::VLD4qWB_register_Asm_8:
7681 case ARM::VLD4qWB_register_Asm_16:
7682 case ARM::VLD4qWB_register_Asm_32: {
7685 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7686 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7687 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7689 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7691 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7693 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7694 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7695 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7696 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7697 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7698 TmpInst.addOperand(Inst.getOperand(5));
7703 // VST3 multiple 3-element structure instructions.
7704 case ARM::VST3dAsm_8:
7705 case ARM::VST3dAsm_16:
7706 case ARM::VST3dAsm_32:
7707 case ARM::VST3qAsm_8:
7708 case ARM::VST3qAsm_16:
7709 case ARM::VST3qAsm_32: {
7712 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7713 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7714 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7715 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7716 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7718 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7720 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7721 TmpInst.addOperand(Inst.getOperand(4));
7726 case ARM::VST3dWB_fixed_Asm_8:
7727 case ARM::VST3dWB_fixed_Asm_16:
7728 case ARM::VST3dWB_fixed_Asm_32:
7729 case ARM::VST3qWB_fixed_Asm_8:
7730 case ARM::VST3qWB_fixed_Asm_16:
7731 case ARM::VST3qWB_fixed_Asm_32: {
7734 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7735 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7736 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7737 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7738 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7739 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7740 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7742 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7744 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7745 TmpInst.addOperand(Inst.getOperand(4));
7750 case ARM::VST3dWB_register_Asm_8:
7751 case ARM::VST3dWB_register_Asm_16:
7752 case ARM::VST3dWB_register_Asm_32:
7753 case ARM::VST3qWB_register_Asm_8:
7754 case ARM::VST3qWB_register_Asm_16:
7755 case ARM::VST3qWB_register_Asm_32: {
7758 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7759 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7760 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7761 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7762 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7763 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7764 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7766 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7768 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7769 TmpInst.addOperand(Inst.getOperand(5));
7774 // VST4 multiple 3-element structure instructions.
7775 case ARM::VST4dAsm_8:
7776 case ARM::VST4dAsm_16:
7777 case ARM::VST4dAsm_32:
7778 case ARM::VST4qAsm_8:
7779 case ARM::VST4qAsm_16:
7780 case ARM::VST4qAsm_32: {
7783 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7784 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7785 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7786 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7787 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7789 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7791 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7793 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7794 TmpInst.addOperand(Inst.getOperand(4));
7799 case ARM::VST4dWB_fixed_Asm_8:
7800 case ARM::VST4dWB_fixed_Asm_16:
7801 case ARM::VST4dWB_fixed_Asm_32:
7802 case ARM::VST4qWB_fixed_Asm_8:
7803 case ARM::VST4qWB_fixed_Asm_16:
7804 case ARM::VST4qWB_fixed_Asm_32: {
7807 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7808 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7809 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7810 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7811 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7812 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7813 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7815 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7817 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7819 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7820 TmpInst.addOperand(Inst.getOperand(4));
7825 case ARM::VST4dWB_register_Asm_8:
7826 case ARM::VST4dWB_register_Asm_16:
7827 case ARM::VST4dWB_register_Asm_32:
7828 case ARM::VST4qWB_register_Asm_8:
7829 case ARM::VST4qWB_register_Asm_16:
7830 case ARM::VST4qWB_register_Asm_32: {
7833 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7834 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7835 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7836 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7837 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7838 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7839 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7841 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7843 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7845 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7846 TmpInst.addOperand(Inst.getOperand(5));
7851 // Handle encoding choice for the shift-immediate instructions.
7854 case ARM::t2ASRri: {
7855 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7856 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7857 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7858 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7859 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
7861 switch (Inst.getOpcode()) {
7862 default: llvm_unreachable("unexpected opcode");
7863 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7864 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7865 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7867 // The Thumb1 operands aren't in the same order. Awesome, eh?
7869 TmpInst.setOpcode(NewOpc);
7870 TmpInst.addOperand(Inst.getOperand(0));
7871 TmpInst.addOperand(Inst.getOperand(5));
7872 TmpInst.addOperand(Inst.getOperand(1));
7873 TmpInst.addOperand(Inst.getOperand(2));
7874 TmpInst.addOperand(Inst.getOperand(3));
7875 TmpInst.addOperand(Inst.getOperand(4));
7882 // Handle the Thumb2 mode MOV complex aliases.
7884 case ARM::t2MOVSsr: {
7885 // Which instruction to expand to depends on the CCOut operand and
7886 // whether we're in an IT block if the register operands are low
7888 bool isNarrow = false;
7889 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7890 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7891 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7892 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7893 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7897 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7898 default: llvm_unreachable("unexpected opcode!");
7899 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7900 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7901 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7902 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7904 TmpInst.setOpcode(newOpc);
7905 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7907 TmpInst.addOperand(MCOperand::CreateReg(
7908 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7909 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7910 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7911 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7912 TmpInst.addOperand(Inst.getOperand(5));
7914 TmpInst.addOperand(MCOperand::CreateReg(
7915 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7920 case ARM::t2MOVSsi: {
7921 // Which instruction to expand to depends on the CCOut operand and
7922 // whether we're in an IT block if the register operands are low
7924 bool isNarrow = false;
7925 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7926 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7927 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7931 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7932 default: llvm_unreachable("unexpected opcode!");
7933 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7934 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7935 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7936 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7937 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7939 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7940 if (Amount == 32) Amount = 0;
7941 TmpInst.setOpcode(newOpc);
7942 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7944 TmpInst.addOperand(MCOperand::CreateReg(
7945 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7946 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7947 if (newOpc != ARM::t2RRX)
7948 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7949 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7950 TmpInst.addOperand(Inst.getOperand(4));
7952 TmpInst.addOperand(MCOperand::CreateReg(
7953 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7957 // Handle the ARM mode MOV complex aliases.
7962 ARM_AM::ShiftOpc ShiftTy;
7963 switch(Inst.getOpcode()) {
7964 default: llvm_unreachable("unexpected opcode!");
7965 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7966 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7967 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7968 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7970 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7972 TmpInst.setOpcode(ARM::MOVsr);
7973 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7974 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7975 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7976 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7977 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7978 TmpInst.addOperand(Inst.getOperand(4));
7979 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7987 ARM_AM::ShiftOpc ShiftTy;
7988 switch(Inst.getOpcode()) {
7989 default: llvm_unreachable("unexpected opcode!");
7990 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7991 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7992 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7993 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7995 // A shift by zero is a plain MOVr, not a MOVsi.
7996 unsigned Amt = Inst.getOperand(2).getImm();
7997 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7998 // A shift by 32 should be encoded as 0 when permitted
7999 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
8001 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
8003 TmpInst.setOpcode(Opc);
8004 TmpInst.addOperand(Inst.getOperand(0)); // Rd
8005 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8006 if (Opc == ARM::MOVsi)
8007 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
8008 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
8009 TmpInst.addOperand(Inst.getOperand(4));
8010 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
8015 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
8017 TmpInst.setOpcode(ARM::MOVsi);
8018 TmpInst.addOperand(Inst.getOperand(0)); // Rd
8019 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8020 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
8021 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8022 TmpInst.addOperand(Inst.getOperand(3));
8023 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
8027 case ARM::t2LDMIA_UPD: {
8028 // If this is a load of a single register, then we should use
8029 // a post-indexed LDR instruction instead, per the ARM ARM.
8030 if (Inst.getNumOperands() != 5)
8033 TmpInst.setOpcode(ARM::t2LDR_POST);
8034 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8035 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8036 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8037 TmpInst.addOperand(MCOperand::CreateImm(4));
8038 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8039 TmpInst.addOperand(Inst.getOperand(3));
8043 case ARM::t2STMDB_UPD: {
8044 // If this is a store of a single register, then we should use
8045 // a pre-indexed STR instruction instead, per the ARM ARM.
8046 if (Inst.getNumOperands() != 5)
8049 TmpInst.setOpcode(ARM::t2STR_PRE);
8050 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8051 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8052 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8053 TmpInst.addOperand(MCOperand::CreateImm(-4));
8054 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8055 TmpInst.addOperand(Inst.getOperand(3));
8059 case ARM::LDMIA_UPD:
8060 // If this is a load of a single register via a 'pop', then we should use
8061 // a post-indexed LDR instruction instead, per the ARM ARM.
8062 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
8063 Inst.getNumOperands() == 5) {
8065 TmpInst.setOpcode(ARM::LDR_POST_IMM);
8066 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8067 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8068 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8069 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
8070 TmpInst.addOperand(MCOperand::CreateImm(4));
8071 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8072 TmpInst.addOperand(Inst.getOperand(3));
8077 case ARM::STMDB_UPD:
8078 // If this is a store of a single register via a 'push', then we should use
8079 // a pre-indexed STR instruction instead, per the ARM ARM.
8080 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
8081 Inst.getNumOperands() == 5) {
8083 TmpInst.setOpcode(ARM::STR_PRE_IMM);
8084 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8085 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8086 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
8087 TmpInst.addOperand(MCOperand::CreateImm(-4));
8088 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8089 TmpInst.addOperand(Inst.getOperand(3));
8093 case ARM::t2ADDri12:
8094 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
8095 // mnemonic was used (not "addw"), encoding T3 is preferred.
8096 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
8097 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8099 Inst.setOpcode(ARM::t2ADDri);
8100 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8102 case ARM::t2SUBri12:
8103 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
8104 // mnemonic was used (not "subw"), encoding T3 is preferred.
8105 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
8106 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8108 Inst.setOpcode(ARM::t2SUBri);
8109 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8112 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
8113 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8114 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8115 // to encoding T1 if <Rd> is omitted."
8116 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
8117 Inst.setOpcode(ARM::tADDi3);
8122 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
8123 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8124 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8125 // to encoding T1 if <Rd> is omitted."
8126 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
8127 Inst.setOpcode(ARM::tSUBi3);
8132 case ARM::t2SUBri: {
8133 // If the destination and first source operand are the same, and
8134 // the flags are compatible with the current IT status, use encoding T2
8135 // instead of T3. For compatibility with the system 'as'. Make sure the
8136 // wide encoding wasn't explicit.
8137 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
8138 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
8139 (unsigned)Inst.getOperand(2).getImm() > 255 ||
8140 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
8141 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
8142 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8143 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
8146 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
8147 ARM::tADDi8 : ARM::tSUBi8);
8148 TmpInst.addOperand(Inst.getOperand(0));
8149 TmpInst.addOperand(Inst.getOperand(5));
8150 TmpInst.addOperand(Inst.getOperand(0));
8151 TmpInst.addOperand(Inst.getOperand(2));
8152 TmpInst.addOperand(Inst.getOperand(3));
8153 TmpInst.addOperand(Inst.getOperand(4));
8157 case ARM::t2ADDrr: {
8158 // If the destination and first source operand are the same, and
8159 // there's no setting of the flags, use encoding T2 instead of T3.
8160 // Note that this is only for ADD, not SUB. This mirrors the system
8161 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
8162 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
8163 Inst.getOperand(5).getReg() != 0 ||
8164 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8165 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
8168 TmpInst.setOpcode(ARM::tADDhirr);
8169 TmpInst.addOperand(Inst.getOperand(0));
8170 TmpInst.addOperand(Inst.getOperand(0));
8171 TmpInst.addOperand(Inst.getOperand(2));
8172 TmpInst.addOperand(Inst.getOperand(3));
8173 TmpInst.addOperand(Inst.getOperand(4));
8177 case ARM::tADDrSP: {
8178 // If the non-SP source operand and the destination operand are not the
8179 // same, we need to use the 32-bit encoding if it's available.
8180 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
8181 Inst.setOpcode(ARM::t2ADDrr);
8182 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8188 // A Thumb conditional branch outside of an IT block is a tBcc.
8189 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
8190 Inst.setOpcode(ARM::tBcc);
8195 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
8196 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
8197 Inst.setOpcode(ARM::t2Bcc);
8202 // If the conditional is AL or we're in an IT block, we really want t2B.
8203 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
8204 Inst.setOpcode(ARM::t2B);
8209 // If the conditional is AL, we really want tB.
8210 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
8211 Inst.setOpcode(ARM::tB);
8216 // If the register list contains any high registers, or if the writeback
8217 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
8218 // instead if we're in Thumb2. Otherwise, this should have generated
8219 // an error in validateInstruction().
8220 unsigned Rn = Inst.getOperand(0).getReg();
8221 bool hasWritebackToken =
8222 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8223 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
8224 bool listContainsBase;
8225 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
8226 (!listContainsBase && !hasWritebackToken) ||
8227 (listContainsBase && hasWritebackToken)) {
8228 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8229 assert (isThumbTwo());
8230 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
8231 // If we're switching to the updating version, we need to insert
8232 // the writeback tied operand.
8233 if (hasWritebackToken)
8234 Inst.insert(Inst.begin(),
8235 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
8240 case ARM::tSTMIA_UPD: {
8241 // If the register list contains any high registers, we need to use
8242 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8243 // should have generated an error in validateInstruction().
8244 unsigned Rn = Inst.getOperand(0).getReg();
8245 bool listContainsBase;
8246 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
8247 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8248 assert (isThumbTwo());
8249 Inst.setOpcode(ARM::t2STMIA_UPD);
8255 bool listContainsBase;
8256 // If the register list contains any high registers, we need to use
8257 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8258 // should have generated an error in validateInstruction().
8259 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
8261 assert (isThumbTwo());
8262 Inst.setOpcode(ARM::t2LDMIA_UPD);
8263 // Add the base register and writeback operands.
8264 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8265 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8269 bool listContainsBase;
8270 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
8272 assert (isThumbTwo());
8273 Inst.setOpcode(ARM::t2STMDB_UPD);
8274 // Add the base register and writeback operands.
8275 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8276 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8280 // If we can use the 16-bit encoding and the user didn't explicitly
8281 // request the 32-bit variant, transform it here.
8282 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8283 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
8284 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
8285 Inst.getOperand(4).getReg() == ARM::CPSR) ||
8286 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
8287 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8288 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
8289 // The operands aren't in the same order for tMOVi8...
8291 TmpInst.setOpcode(ARM::tMOVi8);
8292 TmpInst.addOperand(Inst.getOperand(0));
8293 TmpInst.addOperand(Inst.getOperand(4));
8294 TmpInst.addOperand(Inst.getOperand(1));
8295 TmpInst.addOperand(Inst.getOperand(2));
8296 TmpInst.addOperand(Inst.getOperand(3));
8303 // If we can use the 16-bit encoding and the user didn't explicitly
8304 // request the 32-bit variant, transform it here.
8305 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8306 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8307 Inst.getOperand(2).getImm() == ARMCC::AL &&
8308 Inst.getOperand(4).getReg() == ARM::CPSR &&
8309 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8310 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
8311 // The operands aren't the same for tMOV[S]r... (no cc_out)
8313 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
8314 TmpInst.addOperand(Inst.getOperand(0));
8315 TmpInst.addOperand(Inst.getOperand(1));
8316 TmpInst.addOperand(Inst.getOperand(2));
8317 TmpInst.addOperand(Inst.getOperand(3));
8327 // If we can use the 16-bit encoding and the user didn't explicitly
8328 // request the 32-bit variant, transform it here.
8329 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8330 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8331 Inst.getOperand(2).getImm() == 0 &&
8332 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8333 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
8335 switch (Inst.getOpcode()) {
8336 default: llvm_unreachable("Illegal opcode!");
8337 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
8338 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
8339 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
8340 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
8342 // The operands aren't the same for thumb1 (no rotate operand).
8344 TmpInst.setOpcode(NewOpc);
8345 TmpInst.addOperand(Inst.getOperand(0));
8346 TmpInst.addOperand(Inst.getOperand(1));
8347 TmpInst.addOperand(Inst.getOperand(3));
8348 TmpInst.addOperand(Inst.getOperand(4));
8355 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
8356 // rrx shifts and asr/lsr of #32 is encoded as 0
8357 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
8359 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
8360 // Shifting by zero is accepted as a vanilla 'MOVr'
8362 TmpInst.setOpcode(ARM::MOVr);
8363 TmpInst.addOperand(Inst.getOperand(0));
8364 TmpInst.addOperand(Inst.getOperand(1));
8365 TmpInst.addOperand(Inst.getOperand(3));
8366 TmpInst.addOperand(Inst.getOperand(4));
8367 TmpInst.addOperand(Inst.getOperand(5));
8380 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
8381 if (SOpc == ARM_AM::rrx) return false;
8382 switch (Inst.getOpcode()) {
8383 default: llvm_unreachable("unexpected opcode!");
8384 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
8385 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
8386 case ARM::EORrsi: newOpc = ARM::EORrr; break;
8387 case ARM::BICrsi: newOpc = ARM::BICrr; break;
8388 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
8389 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
8391 // If the shift is by zero, use the non-shifted instruction definition.
8392 // The exception is for right shifts, where 0 == 32
8393 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
8394 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
8396 TmpInst.setOpcode(newOpc);
8397 TmpInst.addOperand(Inst.getOperand(0));
8398 TmpInst.addOperand(Inst.getOperand(1));
8399 TmpInst.addOperand(Inst.getOperand(2));
8400 TmpInst.addOperand(Inst.getOperand(4));
8401 TmpInst.addOperand(Inst.getOperand(5));
8402 TmpInst.addOperand(Inst.getOperand(6));
8410 // The mask bits for all but the first condition are represented as
8411 // the low bit of the condition code value implies 't'. We currently
8412 // always have 1 implies 't', so XOR toggle the bits if the low bit
8413 // of the condition code is zero.
8414 MCOperand &MO = Inst.getOperand(1);
8415 unsigned Mask = MO.getImm();
8416 unsigned OrigMask = Mask;
8417 unsigned TZ = countTrailingZeros(Mask);
8418 if ((Inst.getOperand(0).getImm() & 1) == 0) {
8419 assert(Mask && TZ <= 3 && "illegal IT mask value!");
8420 Mask ^= (0xE << TZ) & 0xF;
8424 // Set up the IT block state according to the IT instruction we just
8426 assert(!inITBlock() && "nested IT blocks?!");
8427 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
8428 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
8429 ITState.CurPosition = 0;
8430 ITState.FirstCond = true;
8440 // Assemblers should use the narrow encodings of these instructions when permissible.
8441 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8442 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8443 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
8444 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
8445 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8446 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8447 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8450 switch (Inst.getOpcode()) {
8451 default: llvm_unreachable("unexpected opcode");
8452 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
8453 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
8454 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
8455 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
8456 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
8457 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
8460 TmpInst.setOpcode(NewOpc);
8461 TmpInst.addOperand(Inst.getOperand(0));
8462 TmpInst.addOperand(Inst.getOperand(5));
8463 TmpInst.addOperand(Inst.getOperand(1));
8464 TmpInst.addOperand(Inst.getOperand(2));
8465 TmpInst.addOperand(Inst.getOperand(3));
8466 TmpInst.addOperand(Inst.getOperand(4));
8477 // Assemblers should use the narrow encodings of these instructions when permissible.
8478 // These instructions are special in that they are commutable, so shorter encodings
8479 // are available more often.
8480 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8481 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8482 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
8483 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
8484 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
8485 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8486 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8487 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8490 switch (Inst.getOpcode()) {
8491 default: llvm_unreachable("unexpected opcode");
8492 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
8493 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
8494 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
8495 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
8498 TmpInst.setOpcode(NewOpc);
8499 TmpInst.addOperand(Inst.getOperand(0));
8500 TmpInst.addOperand(Inst.getOperand(5));
8501 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8502 TmpInst.addOperand(Inst.getOperand(1));
8503 TmpInst.addOperand(Inst.getOperand(2));
8505 TmpInst.addOperand(Inst.getOperand(2));
8506 TmpInst.addOperand(Inst.getOperand(1));
8508 TmpInst.addOperand(Inst.getOperand(3));
8509 TmpInst.addOperand(Inst.getOperand(4));
8519 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8520 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8521 // suffix depending on whether they're in an IT block or not.
8522 unsigned Opc = Inst.getOpcode();
8523 const MCInstrDesc &MCID = MII.get(Opc);
8524 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8525 assert(MCID.hasOptionalDef() &&
8526 "optionally flag setting instruction missing optional def operand");
8527 assert(MCID.NumOperands == Inst.getNumOperands() &&
8528 "operand count mismatch!");
8529 // Find the optional-def operand (cc_out).
8532 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8535 // If we're parsing Thumb1, reject it completely.
8536 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8537 return Match_MnemonicFail;
8538 // If we're parsing Thumb2, which form is legal depends on whether we're
8540 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8542 return Match_RequiresITBlock;
8543 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8545 return Match_RequiresNotITBlock;
8547 // Some high-register supporting Thumb1 encodings only allow both registers
8548 // to be from r0-r7 when in Thumb2.
8549 else if (Opc == ARM::tADDhirr && isThumbOne() && !hasV6MOps() &&
8550 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8551 isARMLowRegister(Inst.getOperand(2).getReg()))
8552 return Match_RequiresThumb2;
8553 // Others only require ARMv6 or later.
8554 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
8555 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8556 isARMLowRegister(Inst.getOperand(1).getReg()))
8557 return Match_RequiresV6;
8558 return Match_Success;
8562 template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
8563 return true; // In an assembly source, no need to second-guess
8567 static const char *getSubtargetFeatureName(uint64_t Val);
8568 bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8569 OperandVector &Operands,
8570 MCStreamer &Out, uint64_t &ErrorInfo,
8571 bool MatchingInlineAsm) {
8573 unsigned MatchResult;
8575 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
8577 switch (MatchResult) {
8580 // Context sensitive operand constraints aren't handled by the matcher,
8581 // so check them here.
8582 if (validateInstruction(Inst, Operands)) {
8583 // Still progress the IT block, otherwise one wrong condition causes
8584 // nasty cascading errors.
8585 forwardITPosition();
8589 { // processInstruction() updates inITBlock state, we need to save it away
8590 bool wasInITBlock = inITBlock();
8592 // Some instructions need post-processing to, for example, tweak which
8593 // encoding is selected. Loop on it while changes happen so the
8594 // individual transformations can chain off each other. E.g.,
8595 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
8596 while (processInstruction(Inst, Operands, Out))
8599 // Only after the instruction is fully processed, we can validate it
8600 if (wasInITBlock && hasV8Ops() && isThumb() &&
8601 !isV8EligibleForIT(&Inst)) {
8602 Warning(IDLoc, "deprecated instruction in IT block");
8606 // Only move forward at the very end so that everything in validate
8607 // and process gets a consistent answer about whether we're in an IT
8609 forwardITPosition();
8611 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8612 // doesn't actually encode.
8613 if (Inst.getOpcode() == ARM::ITasm)
8617 Out.EmitInstruction(Inst, STI);
8619 case Match_MissingFeature: {
8620 assert(ErrorInfo && "Unknown missing feature!");
8621 // Special case the error message for the very common case where only
8622 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8623 std::string Msg = "instruction requires:";
8625 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8626 if (ErrorInfo & Mask) {
8628 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8632 return Error(IDLoc, Msg);
8634 case Match_InvalidOperand: {
8635 SMLoc ErrorLoc = IDLoc;
8636 if (ErrorInfo != ~0ULL) {
8637 if (ErrorInfo >= Operands.size())
8638 return Error(IDLoc, "too few operands for instruction");
8640 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
8641 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8644 return Error(ErrorLoc, "invalid operand for instruction");
8646 case Match_MnemonicFail:
8647 return Error(IDLoc, "invalid instruction",
8648 ((ARMOperand &)*Operands[0]).getLocRange());
8649 case Match_RequiresNotITBlock:
8650 return Error(IDLoc, "flag setting instruction only valid outside IT block");
8651 case Match_RequiresITBlock:
8652 return Error(IDLoc, "instruction only valid inside IT block");
8653 case Match_RequiresV6:
8654 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8655 case Match_RequiresThumb2:
8656 return Error(IDLoc, "instruction variant requires Thumb2");
8657 case Match_ImmRange0_15: {
8658 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
8659 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8660 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8662 case Match_ImmRange0_239: {
8663 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
8664 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8665 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8667 case Match_AlignedMemoryRequiresNone:
8668 case Match_DupAlignedMemoryRequiresNone:
8669 case Match_AlignedMemoryRequires16:
8670 case Match_DupAlignedMemoryRequires16:
8671 case Match_AlignedMemoryRequires32:
8672 case Match_DupAlignedMemoryRequires32:
8673 case Match_AlignedMemoryRequires64:
8674 case Match_DupAlignedMemoryRequires64:
8675 case Match_AlignedMemoryRequires64or128:
8676 case Match_DupAlignedMemoryRequires64or128:
8677 case Match_AlignedMemoryRequires64or128or256:
8679 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
8680 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8681 switch (MatchResult) {
8683 llvm_unreachable("Missing Match_Aligned type");
8684 case Match_AlignedMemoryRequiresNone:
8685 case Match_DupAlignedMemoryRequiresNone:
8686 return Error(ErrorLoc, "alignment must be omitted");
8687 case Match_AlignedMemoryRequires16:
8688 case Match_DupAlignedMemoryRequires16:
8689 return Error(ErrorLoc, "alignment must be 16 or omitted");
8690 case Match_AlignedMemoryRequires32:
8691 case Match_DupAlignedMemoryRequires32:
8692 return Error(ErrorLoc, "alignment must be 32 or omitted");
8693 case Match_AlignedMemoryRequires64:
8694 case Match_DupAlignedMemoryRequires64:
8695 return Error(ErrorLoc, "alignment must be 64 or omitted");
8696 case Match_AlignedMemoryRequires64or128:
8697 case Match_DupAlignedMemoryRequires64or128:
8698 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8699 case Match_AlignedMemoryRequires64or128or256:
8700 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8705 llvm_unreachable("Implement any new match types added!");
8708 /// parseDirective parses the arm specific directives
8709 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
8710 const MCObjectFileInfo::Environment Format =
8711 getContext().getObjectFileInfo()->getObjectFileType();
8712 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
8713 bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
8715 StringRef IDVal = DirectiveID.getIdentifier();
8716 if (IDVal == ".word")
8717 return parseLiteralValues(4, DirectiveID.getLoc());
8718 else if (IDVal == ".short" || IDVal == ".hword")
8719 return parseLiteralValues(2, DirectiveID.getLoc());
8720 else if (IDVal == ".thumb")
8721 return parseDirectiveThumb(DirectiveID.getLoc());
8722 else if (IDVal == ".arm")
8723 return parseDirectiveARM(DirectiveID.getLoc());
8724 else if (IDVal == ".thumb_func")
8725 return parseDirectiveThumbFunc(DirectiveID.getLoc());
8726 else if (IDVal == ".code")
8727 return parseDirectiveCode(DirectiveID.getLoc());
8728 else if (IDVal == ".syntax")
8729 return parseDirectiveSyntax(DirectiveID.getLoc());
8730 else if (IDVal == ".unreq")
8731 return parseDirectiveUnreq(DirectiveID.getLoc());
8732 else if (IDVal == ".fnend")
8733 return parseDirectiveFnEnd(DirectiveID.getLoc());
8734 else if (IDVal == ".cantunwind")
8735 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8736 else if (IDVal == ".personality")
8737 return parseDirectivePersonality(DirectiveID.getLoc());
8738 else if (IDVal == ".handlerdata")
8739 return parseDirectiveHandlerData(DirectiveID.getLoc());
8740 else if (IDVal == ".setfp")
8741 return parseDirectiveSetFP(DirectiveID.getLoc());
8742 else if (IDVal == ".pad")
8743 return parseDirectivePad(DirectiveID.getLoc());
8744 else if (IDVal == ".save")
8745 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8746 else if (IDVal == ".vsave")
8747 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
8748 else if (IDVal == ".ltorg" || IDVal == ".pool")
8749 return parseDirectiveLtorg(DirectiveID.getLoc());
8750 else if (IDVal == ".even")
8751 return parseDirectiveEven(DirectiveID.getLoc());
8752 else if (IDVal == ".personalityindex")
8753 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
8754 else if (IDVal == ".unwind_raw")
8755 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
8756 else if (IDVal == ".movsp")
8757 return parseDirectiveMovSP(DirectiveID.getLoc());
8758 else if (IDVal == ".arch_extension")
8759 return parseDirectiveArchExtension(DirectiveID.getLoc());
8760 else if (IDVal == ".align")
8761 return parseDirectiveAlign(DirectiveID.getLoc());
8762 else if (IDVal == ".thumb_set")
8763 return parseDirectiveThumbSet(DirectiveID.getLoc());
8765 if (!IsMachO && !IsCOFF) {
8766 if (IDVal == ".arch")
8767 return parseDirectiveArch(DirectiveID.getLoc());
8768 else if (IDVal == ".cpu")
8769 return parseDirectiveCPU(DirectiveID.getLoc());
8770 else if (IDVal == ".eabi_attribute")
8771 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8772 else if (IDVal == ".fpu")
8773 return parseDirectiveFPU(DirectiveID.getLoc());
8774 else if (IDVal == ".fnstart")
8775 return parseDirectiveFnStart(DirectiveID.getLoc());
8776 else if (IDVal == ".inst")
8777 return parseDirectiveInst(DirectiveID.getLoc());
8778 else if (IDVal == ".inst.n")
8779 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8780 else if (IDVal == ".inst.w")
8781 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8782 else if (IDVal == ".object_arch")
8783 return parseDirectiveObjectArch(DirectiveID.getLoc());
8784 else if (IDVal == ".tlsdescseq")
8785 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8791 /// parseLiteralValues
8792 /// ::= .hword expression [, expression]*
8793 /// ::= .short expression [, expression]*
8794 /// ::= .word expression [, expression]*
8795 bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
8796 MCAsmParser &Parser = getParser();
8797 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8799 const MCExpr *Value;
8800 if (getParser().parseExpression(Value)) {
8801 Parser.eatToEndOfStatement();
8805 getParser().getStreamer().EmitValue(Value, Size);
8807 if (getLexer().is(AsmToken::EndOfStatement))
8810 // FIXME: Improve diagnostic.
8811 if (getLexer().isNot(AsmToken::Comma)) {
8812 Error(L, "unexpected token in directive");
8823 /// parseDirectiveThumb
8825 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
8826 MCAsmParser &Parser = getParser();
8827 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8828 Error(L, "unexpected token in directive");
8834 Error(L, "target does not support Thumb mode");
8841 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8845 /// parseDirectiveARM
8847 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
8848 MCAsmParser &Parser = getParser();
8849 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8850 Error(L, "unexpected token in directive");
8856 Error(L, "target does not support ARM mode");
8863 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8867 void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8868 if (NextSymbolIsThumb) {
8869 getParser().getStreamer().EmitThumbFunc(Symbol);
8870 NextSymbolIsThumb = false;
8874 /// parseDirectiveThumbFunc
8875 /// ::= .thumbfunc symbol_name
8876 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
8877 MCAsmParser &Parser = getParser();
8878 const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
8879 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
8881 // Darwin asm has (optionally) function name after .thumb_func direction
8884 const AsmToken &Tok = Parser.getTok();
8885 if (Tok.isNot(AsmToken::EndOfStatement)) {
8886 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8887 Error(L, "unexpected token in .thumb_func directive");
8892 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8893 getParser().getStreamer().EmitThumbFunc(Func);
8894 Parser.Lex(); // Consume the identifier token.
8899 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8900 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8901 Parser.eatToEndOfStatement();
8905 NextSymbolIsThumb = true;
8909 /// parseDirectiveSyntax
8910 /// ::= .syntax unified | divided
8911 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
8912 MCAsmParser &Parser = getParser();
8913 const AsmToken &Tok = Parser.getTok();
8914 if (Tok.isNot(AsmToken::Identifier)) {
8915 Error(L, "unexpected token in .syntax directive");
8919 StringRef Mode = Tok.getString();
8920 if (Mode == "unified" || Mode == "UNIFIED") {
8922 } else if (Mode == "divided" || Mode == "DIVIDED") {
8923 Error(L, "'.syntax divided' arm asssembly not supported");
8926 Error(L, "unrecognized syntax mode in .syntax directive");
8930 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8931 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8936 // TODO tell the MC streamer the mode
8937 // getParser().getStreamer().Emit???();
8941 /// parseDirectiveCode
8942 /// ::= .code 16 | 32
8943 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
8944 MCAsmParser &Parser = getParser();
8945 const AsmToken &Tok = Parser.getTok();
8946 if (Tok.isNot(AsmToken::Integer)) {
8947 Error(L, "unexpected token in .code directive");
8950 int64_t Val = Parser.getTok().getIntVal();
8951 if (Val != 16 && Val != 32) {
8952 Error(L, "invalid operand to .code directive");
8957 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8958 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8965 Error(L, "target does not support Thumb mode");
8971 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8974 Error(L, "target does not support ARM mode");
8980 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8986 /// parseDirectiveReq
8987 /// ::= name .req registername
8988 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8989 MCAsmParser &Parser = getParser();
8990 Parser.Lex(); // Eat the '.req' token.
8992 SMLoc SRegLoc, ERegLoc;
8993 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
8994 Parser.eatToEndOfStatement();
8995 Error(SRegLoc, "register name expected");
8999 // Shouldn't be anything else.
9000 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
9001 Parser.eatToEndOfStatement();
9002 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
9006 Parser.Lex(); // Consume the EndOfStatement
9008 if (!RegisterReqs.insert(std::make_pair(Name, Reg)).second) {
9009 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
9016 /// parseDirectiveUneq
9017 /// ::= .unreq registername
9018 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
9019 MCAsmParser &Parser = getParser();
9020 if (Parser.getTok().isNot(AsmToken::Identifier)) {
9021 Parser.eatToEndOfStatement();
9022 Error(L, "unexpected input in .unreq directive.");
9025 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
9026 Parser.Lex(); // Eat the identifier.
9030 /// parseDirectiveArch
9032 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
9033 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
9035 unsigned ID = StringSwitch<unsigned>(Arch)
9036 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9037 .Case(NAME, ARM::ID)
9038 #define ARM_ARCH_ALIAS(NAME, ID) \
9039 .Case(NAME, ARM::ID)
9040 #include "MCTargetDesc/ARMArchName.def"
9041 .Default(ARM::INVALID_ARCH);
9043 if (ID == ARM::INVALID_ARCH) {
9044 Error(L, "Unknown arch name");
9048 getTargetStreamer().emitArch(ID);
9052 /// parseDirectiveEabiAttr
9053 /// ::= .eabi_attribute int, int [, "str"]
9054 /// ::= .eabi_attribute Tag_name, int [, "str"]
9055 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
9056 MCAsmParser &Parser = getParser();
9059 TagLoc = Parser.getTok().getLoc();
9060 if (Parser.getTok().is(AsmToken::Identifier)) {
9061 StringRef Name = Parser.getTok().getIdentifier();
9062 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
9064 Error(TagLoc, "attribute name not recognised: " + Name);
9065 Parser.eatToEndOfStatement();
9070 const MCExpr *AttrExpr;
9072 TagLoc = Parser.getTok().getLoc();
9073 if (Parser.parseExpression(AttrExpr)) {
9074 Parser.eatToEndOfStatement();
9078 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
9080 Error(TagLoc, "expected numeric constant");
9081 Parser.eatToEndOfStatement();
9085 Tag = CE->getValue();
9088 if (Parser.getTok().isNot(AsmToken::Comma)) {
9089 Error(Parser.getTok().getLoc(), "comma expected");
9090 Parser.eatToEndOfStatement();
9093 Parser.Lex(); // skip comma
9095 StringRef StringValue = "";
9096 bool IsStringValue = false;
9098 int64_t IntegerValue = 0;
9099 bool IsIntegerValue = false;
9101 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
9102 IsStringValue = true;
9103 else if (Tag == ARMBuildAttrs::compatibility) {
9104 IsStringValue = true;
9105 IsIntegerValue = true;
9106 } else if (Tag < 32 || Tag % 2 == 0)
9107 IsIntegerValue = true;
9108 else if (Tag % 2 == 1)
9109 IsStringValue = true;
9111 llvm_unreachable("invalid tag type");
9113 if (IsIntegerValue) {
9114 const MCExpr *ValueExpr;
9115 SMLoc ValueExprLoc = Parser.getTok().getLoc();
9116 if (Parser.parseExpression(ValueExpr)) {
9117 Parser.eatToEndOfStatement();
9121 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
9123 Error(ValueExprLoc, "expected numeric constant");
9124 Parser.eatToEndOfStatement();
9128 IntegerValue = CE->getValue();
9131 if (Tag == ARMBuildAttrs::compatibility) {
9132 if (Parser.getTok().isNot(AsmToken::Comma))
9133 IsStringValue = false;
9138 if (IsStringValue) {
9139 if (Parser.getTok().isNot(AsmToken::String)) {
9140 Error(Parser.getTok().getLoc(), "bad string constant");
9141 Parser.eatToEndOfStatement();
9145 StringValue = Parser.getTok().getStringContents();
9149 if (IsIntegerValue && IsStringValue) {
9150 assert(Tag == ARMBuildAttrs::compatibility);
9151 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
9152 } else if (IsIntegerValue)
9153 getTargetStreamer().emitAttribute(Tag, IntegerValue);
9154 else if (IsStringValue)
9155 getTargetStreamer().emitTextAttribute(Tag, StringValue);
9159 /// parseDirectiveCPU
9161 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
9162 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
9163 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
9165 if (!STI.isCPUStringValid(CPU)) {
9166 Error(L, "Unknown CPU name");
9170 // FIXME: This switches the CPU features globally, therefore it might
9171 // happen that code you would not expect to assemble will. For details
9172 // see: http://llvm.org/bugs/show_bug.cgi?id=20757
9173 STI.InitMCProcessorInfo(CPU, "");
9174 STI.InitCPUSchedModel(CPU);
9175 unsigned FB = ComputeAvailableFeatures(STI.getFeatureBits());
9176 setAvailableFeatures(FB);
9181 // FIXME: This is duplicated in getARMFPUFeatures() in
9182 // tools/clang/lib/Driver/Tools.cpp
9183 static const struct {
9185 const uint64_t Enabled;
9186 const uint64_t Disabled;
9188 {ARM::VFP, ARM::FeatureVFP2, ARM::FeatureNEON},
9189 {ARM::VFPV2, ARM::FeatureVFP2, ARM::FeatureNEON},
9190 {ARM::VFPV3, ARM::FeatureVFP3, ARM::FeatureNEON},
9191 {ARM::VFPV3_D16, ARM::FeatureVFP3 | ARM::FeatureD16, ARM::FeatureNEON},
9192 {ARM::VFPV4, ARM::FeatureVFP4, ARM::FeatureNEON},
9193 {ARM::VFPV4_D16, ARM::FeatureVFP4 | ARM::FeatureD16, ARM::FeatureNEON},
9194 {ARM::FPV5_D16, ARM::FeatureFPARMv8 | ARM::FeatureD16,
9195 ARM::FeatureNEON | ARM::FeatureCrypto},
9196 {ARM::FP_ARMV8, ARM::FeatureFPARMv8,
9197 ARM::FeatureNEON | ARM::FeatureCrypto},
9198 {ARM::NEON, ARM::FeatureNEON, 0},
9199 {ARM::NEON_VFPV4, ARM::FeatureVFP4 | ARM::FeatureNEON, 0},
9200 {ARM::NEON_FP_ARMV8, ARM::FeatureFPARMv8 | ARM::FeatureNEON,
9201 ARM::FeatureCrypto},
9202 {ARM::CRYPTO_NEON_FP_ARMV8,
9203 ARM::FeatureFPARMv8 | ARM::FeatureNEON | ARM::FeatureCrypto, 0},
9204 {ARM::SOFTVFP, 0, 0},
9207 /// parseDirectiveFPU
9209 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
9210 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
9212 unsigned ID = StringSwitch<unsigned>(FPU)
9213 #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
9214 #include "ARMFPUName.def"
9215 .Default(ARM::INVALID_FPU);
9217 if (ID == ARM::INVALID_FPU) {
9218 Error(L, "Unknown FPU name");
9222 for (const auto &Fpu : Fpus) {
9226 // Need to toggle features that should be on but are off and that
9227 // should off but are on.
9228 uint64_t Toggle = (Fpu.Enabled & ~STI.getFeatureBits()) |
9229 (Fpu.Disabled & STI.getFeatureBits());
9230 setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle)));
9234 getTargetStreamer().emitFPU(ID);
9238 /// parseDirectiveFnStart
9240 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
9241 if (UC.hasFnStart()) {
9242 Error(L, ".fnstart starts before the end of previous one");
9243 UC.emitFnStartLocNotes();
9247 // Reset the unwind directives parser state
9250 getTargetStreamer().emitFnStart();
9252 UC.recordFnStart(L);
9256 /// parseDirectiveFnEnd
9258 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
9259 // Check the ordering of unwind directives
9260 if (!UC.hasFnStart()) {
9261 Error(L, ".fnstart must precede .fnend directive");
9265 // Reset the unwind directives parser state
9266 getTargetStreamer().emitFnEnd();
9272 /// parseDirectiveCantUnwind
9274 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
9275 UC.recordCantUnwind(L);
9277 // Check the ordering of unwind directives
9278 if (!UC.hasFnStart()) {
9279 Error(L, ".fnstart must precede .cantunwind directive");
9282 if (UC.hasHandlerData()) {
9283 Error(L, ".cantunwind can't be used with .handlerdata directive");
9284 UC.emitHandlerDataLocNotes();
9287 if (UC.hasPersonality()) {
9288 Error(L, ".cantunwind can't be used with .personality directive");
9289 UC.emitPersonalityLocNotes();
9293 getTargetStreamer().emitCantUnwind();
9297 /// parseDirectivePersonality
9298 /// ::= .personality name
9299 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
9300 MCAsmParser &Parser = getParser();
9301 bool HasExistingPersonality = UC.hasPersonality();
9303 UC.recordPersonality(L);
9305 // Check the ordering of unwind directives
9306 if (!UC.hasFnStart()) {
9307 Error(L, ".fnstart must precede .personality directive");
9310 if (UC.cantUnwind()) {
9311 Error(L, ".personality can't be used with .cantunwind directive");
9312 UC.emitCantUnwindLocNotes();
9315 if (UC.hasHandlerData()) {
9316 Error(L, ".personality must precede .handlerdata directive");
9317 UC.emitHandlerDataLocNotes();
9320 if (HasExistingPersonality) {
9321 Parser.eatToEndOfStatement();
9322 Error(L, "multiple personality directives");
9323 UC.emitPersonalityLocNotes();
9327 // Parse the name of the personality routine
9328 if (Parser.getTok().isNot(AsmToken::Identifier)) {
9329 Parser.eatToEndOfStatement();
9330 Error(L, "unexpected input in .personality directive.");
9333 StringRef Name(Parser.getTok().getIdentifier());
9336 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
9337 getTargetStreamer().emitPersonality(PR);
9341 /// parseDirectiveHandlerData
9342 /// ::= .handlerdata
9343 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
9344 UC.recordHandlerData(L);
9346 // Check the ordering of unwind directives
9347 if (!UC.hasFnStart()) {
9348 Error(L, ".fnstart must precede .personality directive");
9351 if (UC.cantUnwind()) {
9352 Error(L, ".handlerdata can't be used with .cantunwind directive");
9353 UC.emitCantUnwindLocNotes();
9357 getTargetStreamer().emitHandlerData();
9361 /// parseDirectiveSetFP
9362 /// ::= .setfp fpreg, spreg [, offset]
9363 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
9364 MCAsmParser &Parser = getParser();
9365 // Check the ordering of unwind directives
9366 if (!UC.hasFnStart()) {
9367 Error(L, ".fnstart must precede .setfp directive");
9370 if (UC.hasHandlerData()) {
9371 Error(L, ".setfp must precede .handlerdata directive");
9376 SMLoc FPRegLoc = Parser.getTok().getLoc();
9377 int FPReg = tryParseRegister();
9379 Error(FPRegLoc, "frame pointer register expected");
9384 if (Parser.getTok().isNot(AsmToken::Comma)) {
9385 Error(Parser.getTok().getLoc(), "comma expected");
9388 Parser.Lex(); // skip comma
9391 SMLoc SPRegLoc = Parser.getTok().getLoc();
9392 int SPReg = tryParseRegister();
9394 Error(SPRegLoc, "stack pointer register expected");
9398 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
9399 Error(SPRegLoc, "register should be either $sp or the latest fp register");
9403 // Update the frame pointer register
9404 UC.saveFPReg(FPReg);
9408 if (Parser.getTok().is(AsmToken::Comma)) {
9409 Parser.Lex(); // skip comma
9411 if (Parser.getTok().isNot(AsmToken::Hash) &&
9412 Parser.getTok().isNot(AsmToken::Dollar)) {
9413 Error(Parser.getTok().getLoc(), "'#' expected");
9416 Parser.Lex(); // skip hash token.
9418 const MCExpr *OffsetExpr;
9419 SMLoc ExLoc = Parser.getTok().getLoc();
9421 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9422 Error(ExLoc, "malformed setfp offset");
9425 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9427 Error(ExLoc, "setfp offset must be an immediate");
9431 Offset = CE->getValue();
9434 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
9435 static_cast<unsigned>(SPReg), Offset);
9441 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
9442 MCAsmParser &Parser = getParser();
9443 // Check the ordering of unwind directives
9444 if (!UC.hasFnStart()) {
9445 Error(L, ".fnstart must precede .pad directive");
9448 if (UC.hasHandlerData()) {
9449 Error(L, ".pad must precede .handlerdata directive");
9454 if (Parser.getTok().isNot(AsmToken::Hash) &&
9455 Parser.getTok().isNot(AsmToken::Dollar)) {
9456 Error(Parser.getTok().getLoc(), "'#' expected");
9459 Parser.Lex(); // skip hash token.
9461 const MCExpr *OffsetExpr;
9462 SMLoc ExLoc = Parser.getTok().getLoc();
9464 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9465 Error(ExLoc, "malformed pad offset");
9468 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9470 Error(ExLoc, "pad offset must be an immediate");
9474 getTargetStreamer().emitPad(CE->getValue());
9478 /// parseDirectiveRegSave
9479 /// ::= .save { registers }
9480 /// ::= .vsave { registers }
9481 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
9482 // Check the ordering of unwind directives
9483 if (!UC.hasFnStart()) {
9484 Error(L, ".fnstart must precede .save or .vsave directives");
9487 if (UC.hasHandlerData()) {
9488 Error(L, ".save or .vsave must precede .handlerdata directive");
9492 // RAII object to make sure parsed operands are deleted.
9493 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
9495 // Parse the register list
9496 if (parseRegisterList(Operands))
9498 ARMOperand &Op = (ARMOperand &)*Operands[0];
9499 if (!IsVector && !Op.isRegList()) {
9500 Error(L, ".save expects GPR registers");
9503 if (IsVector && !Op.isDPRRegList()) {
9504 Error(L, ".vsave expects DPR registers");
9508 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
9512 /// parseDirectiveInst
9513 /// ::= .inst opcode [, ...]
9514 /// ::= .inst.n opcode [, ...]
9515 /// ::= .inst.w opcode [, ...]
9516 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
9517 MCAsmParser &Parser = getParser();
9529 Parser.eatToEndOfStatement();
9530 Error(Loc, "cannot determine Thumb instruction size, "
9531 "use inst.n/inst.w instead");
9536 Parser.eatToEndOfStatement();
9537 Error(Loc, "width suffixes are invalid in ARM mode");
9543 if (getLexer().is(AsmToken::EndOfStatement)) {
9544 Parser.eatToEndOfStatement();
9545 Error(Loc, "expected expression following directive");
9552 if (getParser().parseExpression(Expr)) {
9553 Error(Loc, "expected expression");
9557 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
9559 Error(Loc, "expected constant expression");
9565 if (Value->getValue() > 0xffff) {
9566 Error(Loc, "inst.n operand is too big, use inst.w instead");
9571 if (Value->getValue() > 0xffffffff) {
9573 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9578 llvm_unreachable("only supported widths are 2 and 4");
9581 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9583 if (getLexer().is(AsmToken::EndOfStatement))
9586 if (getLexer().isNot(AsmToken::Comma)) {
9587 Error(Loc, "unexpected token in directive");
9598 /// parseDirectiveLtorg
9599 /// ::= .ltorg | .pool
9600 bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
9601 getTargetStreamer().emitCurrentConstantPool();
9605 bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9606 const MCSection *Section = getStreamer().getCurrentSection().first;
9608 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9609 TokError("unexpected token in directive");
9614 getStreamer().InitSections(false);
9615 Section = getStreamer().getCurrentSection().first;
9618 assert(Section && "must have section to emit alignment");
9619 if (Section->UseCodeAlign())
9620 getStreamer().EmitCodeAlignment(2);
9622 getStreamer().EmitValueToAlignment(2);
9627 /// parseDirectivePersonalityIndex
9628 /// ::= .personalityindex index
9629 bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
9630 MCAsmParser &Parser = getParser();
9631 bool HasExistingPersonality = UC.hasPersonality();
9633 UC.recordPersonalityIndex(L);
9635 if (!UC.hasFnStart()) {
9636 Parser.eatToEndOfStatement();
9637 Error(L, ".fnstart must precede .personalityindex directive");
9640 if (UC.cantUnwind()) {
9641 Parser.eatToEndOfStatement();
9642 Error(L, ".personalityindex cannot be used with .cantunwind");
9643 UC.emitCantUnwindLocNotes();
9646 if (UC.hasHandlerData()) {
9647 Parser.eatToEndOfStatement();
9648 Error(L, ".personalityindex must precede .handlerdata directive");
9649 UC.emitHandlerDataLocNotes();
9652 if (HasExistingPersonality) {
9653 Parser.eatToEndOfStatement();
9654 Error(L, "multiple personality directives");
9655 UC.emitPersonalityLocNotes();
9659 const MCExpr *IndexExpression;
9660 SMLoc IndexLoc = Parser.getTok().getLoc();
9661 if (Parser.parseExpression(IndexExpression)) {
9662 Parser.eatToEndOfStatement();
9666 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9668 Parser.eatToEndOfStatement();
9669 Error(IndexLoc, "index must be a constant number");
9672 if (CE->getValue() < 0 ||
9673 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9674 Parser.eatToEndOfStatement();
9675 Error(IndexLoc, "personality routine index should be in range [0-3]");
9679 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9683 /// parseDirectiveUnwindRaw
9684 /// ::= .unwind_raw offset, opcode [, opcode...]
9685 bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
9686 MCAsmParser &Parser = getParser();
9687 if (!UC.hasFnStart()) {
9688 Parser.eatToEndOfStatement();
9689 Error(L, ".fnstart must precede .unwind_raw directives");
9693 int64_t StackOffset;
9695 const MCExpr *OffsetExpr;
9696 SMLoc OffsetLoc = getLexer().getLoc();
9697 if (getLexer().is(AsmToken::EndOfStatement) ||
9698 getParser().parseExpression(OffsetExpr)) {
9699 Error(OffsetLoc, "expected expression");
9700 Parser.eatToEndOfStatement();
9704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9706 Error(OffsetLoc, "offset must be a constant");
9707 Parser.eatToEndOfStatement();
9711 StackOffset = CE->getValue();
9713 if (getLexer().isNot(AsmToken::Comma)) {
9714 Error(getLexer().getLoc(), "expected comma");
9715 Parser.eatToEndOfStatement();
9720 SmallVector<uint8_t, 16> Opcodes;
9724 SMLoc OpcodeLoc = getLexer().getLoc();
9725 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9726 Error(OpcodeLoc, "expected opcode expression");
9727 Parser.eatToEndOfStatement();
9731 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9733 Error(OpcodeLoc, "opcode value must be a constant");
9734 Parser.eatToEndOfStatement();
9738 const int64_t Opcode = OC->getValue();
9739 if (Opcode & ~0xff) {
9740 Error(OpcodeLoc, "invalid opcode");
9741 Parser.eatToEndOfStatement();
9745 Opcodes.push_back(uint8_t(Opcode));
9747 if (getLexer().is(AsmToken::EndOfStatement))
9750 if (getLexer().isNot(AsmToken::Comma)) {
9751 Error(getLexer().getLoc(), "unexpected token in directive");
9752 Parser.eatToEndOfStatement();
9759 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9765 /// parseDirectiveTLSDescSeq
9766 /// ::= .tlsdescseq tls-variable
9767 bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
9768 MCAsmParser &Parser = getParser();
9770 if (getLexer().isNot(AsmToken::Identifier)) {
9771 TokError("expected variable after '.tlsdescseq' directive");
9772 Parser.eatToEndOfStatement();
9776 const MCSymbolRefExpr *SRE =
9777 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9778 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9781 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9782 Error(Parser.getTok().getLoc(), "unexpected token");
9783 Parser.eatToEndOfStatement();
9787 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9791 /// parseDirectiveMovSP
9792 /// ::= .movsp reg [, #offset]
9793 bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
9794 MCAsmParser &Parser = getParser();
9795 if (!UC.hasFnStart()) {
9796 Parser.eatToEndOfStatement();
9797 Error(L, ".fnstart must precede .movsp directives");
9800 if (UC.getFPReg() != ARM::SP) {
9801 Parser.eatToEndOfStatement();
9802 Error(L, "unexpected .movsp directive");
9806 SMLoc SPRegLoc = Parser.getTok().getLoc();
9807 int SPReg = tryParseRegister();
9809 Parser.eatToEndOfStatement();
9810 Error(SPRegLoc, "register expected");
9814 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9815 Parser.eatToEndOfStatement();
9816 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9821 if (Parser.getTok().is(AsmToken::Comma)) {
9824 if (Parser.getTok().isNot(AsmToken::Hash)) {
9825 Error(Parser.getTok().getLoc(), "expected #constant");
9826 Parser.eatToEndOfStatement();
9831 const MCExpr *OffsetExpr;
9832 SMLoc OffsetLoc = Parser.getTok().getLoc();
9833 if (Parser.parseExpression(OffsetExpr)) {
9834 Parser.eatToEndOfStatement();
9835 Error(OffsetLoc, "malformed offset expression");
9839 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9841 Parser.eatToEndOfStatement();
9842 Error(OffsetLoc, "offset must be an immediate constant");
9846 Offset = CE->getValue();
9849 getTargetStreamer().emitMovSP(SPReg, Offset);
9850 UC.saveFPReg(SPReg);
9855 /// parseDirectiveObjectArch
9856 /// ::= .object_arch name
9857 bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
9858 MCAsmParser &Parser = getParser();
9859 if (getLexer().isNot(AsmToken::Identifier)) {
9860 Error(getLexer().getLoc(), "unexpected token");
9861 Parser.eatToEndOfStatement();
9865 StringRef Arch = Parser.getTok().getString();
9866 SMLoc ArchLoc = Parser.getTok().getLoc();
9869 unsigned ID = StringSwitch<unsigned>(Arch)
9870 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9871 .Case(NAME, ARM::ID)
9872 #define ARM_ARCH_ALIAS(NAME, ID) \
9873 .Case(NAME, ARM::ID)
9874 #include "MCTargetDesc/ARMArchName.def"
9875 #undef ARM_ARCH_NAME
9876 #undef ARM_ARCH_ALIAS
9877 .Default(ARM::INVALID_ARCH);
9879 if (ID == ARM::INVALID_ARCH) {
9880 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9881 Parser.eatToEndOfStatement();
9885 getTargetStreamer().emitObjectArch(ID);
9887 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9888 Error(getLexer().getLoc(), "unexpected token");
9889 Parser.eatToEndOfStatement();
9895 /// parseDirectiveAlign
9897 bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9898 // NOTE: if this is not the end of the statement, fall back to the target
9899 // agnostic handling for this directive which will correctly handle this.
9900 if (getLexer().isNot(AsmToken::EndOfStatement))
9903 // '.align' is target specifically handled to mean 2**2 byte alignment.
9904 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9905 getStreamer().EmitCodeAlignment(4, 0);
9907 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9912 /// parseDirectiveThumbSet
9913 /// ::= .thumb_set name, value
9914 bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
9915 MCAsmParser &Parser = getParser();
9918 if (Parser.parseIdentifier(Name)) {
9919 TokError("expected identifier after '.thumb_set'");
9920 Parser.eatToEndOfStatement();
9924 if (getLexer().isNot(AsmToken::Comma)) {
9925 TokError("expected comma after name '" + Name + "'");
9926 Parser.eatToEndOfStatement();
9931 const MCExpr *Value;
9932 if (Parser.parseExpression(Value)) {
9933 TokError("missing expression");
9934 Parser.eatToEndOfStatement();
9938 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9939 TokError("unexpected token");
9940 Parser.eatToEndOfStatement();
9945 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
9946 getTargetStreamer().emitThumbSet(Alias, Value);
9950 /// Force static initialization.
9951 extern "C" void LLVMInitializeARMAsmParser() {
9952 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9953 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9954 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9955 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
9958 #define GET_REGISTER_MATCHER
9959 #define GET_SUBTARGET_FEATURE_NAME
9960 #define GET_MATCHER_IMPLEMENTATION
9961 #include "ARMGenAsmMatcher.inc"
9963 static const struct {
9965 const unsigned ArchCheck;
9966 const uint64_t Features;
9968 { "crc", Feature_HasV8, ARM::FeatureCRC },
9969 { "crypto", Feature_HasV8,
9970 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9971 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
9972 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
9973 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
9974 // FIXME: iWMMXT not supported
9975 { "iwmmxt", Feature_None, 0 },
9976 // FIXME: iWMMXT2 not supported
9977 { "iwmmxt2", Feature_None, 0 },
9978 // FIXME: Maverick not supported
9979 { "maverick", Feature_None, 0 },
9980 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
9981 // FIXME: ARMv6-m OS Extensions feature not checked
9982 { "os", Feature_None, 0 },
9983 // FIXME: Also available in ARMv6-K
9984 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
9985 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9986 // FIXME: Only available in A-class, isel not predicated
9987 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
9988 // FIXME: xscale not supported
9989 { "xscale", Feature_None, 0 },
9992 /// parseDirectiveArchExtension
9993 /// ::= .arch_extension [no]feature
9994 bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
9995 MCAsmParser &Parser = getParser();
9997 if (getLexer().isNot(AsmToken::Identifier)) {
9998 Error(getLexer().getLoc(), "unexpected token");
9999 Parser.eatToEndOfStatement();
10003 StringRef Name = Parser.getTok().getString();
10004 SMLoc ExtLoc = Parser.getTok().getLoc();
10007 bool EnableFeature = true;
10008 if (Name.startswith_lower("no")) {
10009 EnableFeature = false;
10010 Name = Name.substr(2);
10013 for (const auto &Extension : Extensions) {
10014 if (Extension.Name != Name)
10017 if (!Extension.Features)
10018 report_fatal_error("unsupported architectural extension: " + Name);
10020 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) {
10021 Error(ExtLoc, "architectural extension '" + Name + "' is not "
10022 "allowed for the current base architecture");
10026 uint64_t ToggleFeatures = EnableFeature
10027 ? (~STI.getFeatureBits() & Extension.Features)
10028 : ( STI.getFeatureBits() & Extension.Features);
10029 uint64_t Features =
10030 ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
10031 setAvailableFeatures(Features);
10035 Error(ExtLoc, "unknown architectural extension: " + Name);
10036 Parser.eatToEndOfStatement();
10040 // Define this matcher function after the auto-generated include so we
10041 // have the match class enum definitions.
10042 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
10044 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
10045 // If the kind is a token for a literal immediate, check if our asm
10046 // operand matches. This is for InstAliases which have a fixed-value
10047 // immediate in the syntax.
10052 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
10053 if (CE->getValue() == 0)
10054 return Match_Success;
10059 const MCExpr *SOExpr = Op.getImm();
10061 if (!SOExpr->EvaluateAsAbsolute(Value))
10062 return Match_Success;
10063 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
10064 "expression value must be representable in 32 bits");
10069 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
10070 return Match_Success;
10073 return Match_InvalidOperand;