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;
133 const MCInstrInfo &MII;
134 const MCRegisterInfo *MRI;
137 ARMTargetStreamer &getTargetStreamer() {
138 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
139 return static_cast<ARMTargetStreamer &>(TS);
142 // Map of register aliases registers via the .req directive.
143 StringMap<unsigned> RegisterReqs;
145 bool NextSymbolIsThumb;
148 ARMCC::CondCodes Cond; // Condition for IT block.
149 unsigned Mask:4; // Condition mask for instructions.
150 // Starting at first 1 (from lsb).
151 // '1' condition as indicated in IT.
152 // '0' inverse of condition (else).
153 // Count of instructions in IT block is
154 // 4 - trailingzeroes(mask)
156 bool FirstCond; // Explicit flag for when we're parsing the
157 // First instruction in the IT block. It's
158 // implied in the mask, so needs special
161 unsigned CurPosition; // Current position in parsing of IT
162 // block. In range [0,3]. Initialized
163 // according to count of instructions in block.
164 // ~0U if no active IT block.
166 bool inITBlock() { return ITState.CurPosition != ~0U;}
167 void forwardITPosition() {
168 if (!inITBlock()) return;
169 // Move to the next instruction in the IT block, if there is one. If not,
170 // mark the block as done.
171 unsigned TZ = countTrailingZeros(ITState.Mask);
172 if (++ITState.CurPosition == 5 - TZ)
173 ITState.CurPosition = ~0U; // Done with the IT block after this.
177 MCAsmParser &getParser() const { return Parser; }
178 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
180 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
181 return Parser.Note(L, Msg, Ranges);
183 bool Warning(SMLoc L, const Twine &Msg,
184 ArrayRef<SMRange> Ranges = None) {
185 return Parser.Warning(L, Msg, Ranges);
187 bool Error(SMLoc L, const Twine &Msg,
188 ArrayRef<SMRange> Ranges = None) {
189 return Parser.Error(L, Msg, Ranges);
192 int tryParseRegister();
193 bool tryParseRegisterWithWriteBack(OperandVector &);
194 int tryParseShiftRegister(OperandVector &);
195 bool parseRegisterList(OperandVector &);
196 bool parseMemory(OperandVector &);
197 bool parseOperand(OperandVector &, StringRef Mnemonic);
198 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
199 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
200 unsigned &ShiftAmount);
201 bool parseLiteralValues(unsigned Size, SMLoc L);
202 bool parseDirectiveThumb(SMLoc L);
203 bool parseDirectiveARM(SMLoc L);
204 bool parseDirectiveThumbFunc(SMLoc L);
205 bool parseDirectiveCode(SMLoc L);
206 bool parseDirectiveSyntax(SMLoc L);
207 bool parseDirectiveReq(StringRef Name, SMLoc L);
208 bool parseDirectiveUnreq(SMLoc L);
209 bool parseDirectiveArch(SMLoc L);
210 bool parseDirectiveEabiAttr(SMLoc L);
211 bool parseDirectiveCPU(SMLoc L);
212 bool parseDirectiveFPU(SMLoc L);
213 bool parseDirectiveFnStart(SMLoc L);
214 bool parseDirectiveFnEnd(SMLoc L);
215 bool parseDirectiveCantUnwind(SMLoc L);
216 bool parseDirectivePersonality(SMLoc L);
217 bool parseDirectiveHandlerData(SMLoc L);
218 bool parseDirectiveSetFP(SMLoc L);
219 bool parseDirectivePad(SMLoc L);
220 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
221 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
222 bool parseDirectiveLtorg(SMLoc L);
223 bool parseDirectiveEven(SMLoc L);
224 bool parseDirectivePersonalityIndex(SMLoc L);
225 bool parseDirectiveUnwindRaw(SMLoc L);
226 bool parseDirectiveTLSDescSeq(SMLoc L);
227 bool parseDirectiveMovSP(SMLoc L);
228 bool parseDirectiveObjectArch(SMLoc L);
229 bool parseDirectiveArchExtension(SMLoc L);
230 bool parseDirectiveAlign(SMLoc L);
231 bool parseDirectiveThumbSet(SMLoc L);
233 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
234 bool &CarrySetting, unsigned &ProcessorIMod,
236 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
237 bool &CanAcceptCarrySet,
238 bool &CanAcceptPredicationCode);
240 bool isThumb() const {
241 // FIXME: Can tablegen auto-generate this?
242 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
244 bool isThumbOne() const {
245 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
247 bool isThumbTwo() const {
248 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
250 bool hasThumb() const {
251 return STI.getFeatureBits() & ARM::HasV4TOps;
253 bool hasV6Ops() const {
254 return STI.getFeatureBits() & ARM::HasV6Ops;
256 bool hasV6MOps() const {
257 return STI.getFeatureBits() & ARM::HasV6MOps;
259 bool hasV7Ops() const {
260 return STI.getFeatureBits() & ARM::HasV7Ops;
262 bool hasV8Ops() const {
263 return STI.getFeatureBits() & ARM::HasV8Ops;
265 bool hasARM() const {
266 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
268 bool hasThumb2DSP() const {
269 return STI.getFeatureBits() & ARM::FeatureDSPThumb2;
273 uint64_t FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
274 setAvailableFeatures(FB);
276 bool isMClass() const {
277 return STI.getFeatureBits() & ARM::FeatureMClass;
280 /// @name Auto-generated Match Functions
283 #define GET_ASSEMBLER_HEADER
284 #include "ARMGenAsmMatcher.inc"
288 OperandMatchResultTy parseITCondCode(OperandVector &);
289 OperandMatchResultTy parseCoprocNumOperand(OperandVector &);
290 OperandMatchResultTy parseCoprocRegOperand(OperandVector &);
291 OperandMatchResultTy parseCoprocOptionOperand(OperandVector &);
292 OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &);
293 OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &);
294 OperandMatchResultTy parseProcIFlagsOperand(OperandVector &);
295 OperandMatchResultTy parseMSRMaskOperand(OperandVector &);
296 OperandMatchResultTy parseBankedRegOperand(OperandVector &);
297 OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low,
299 OperandMatchResultTy parsePKHLSLImm(OperandVector &O) {
300 return parsePKHImm(O, "lsl", 0, 31);
302 OperandMatchResultTy parsePKHASRImm(OperandVector &O) {
303 return parsePKHImm(O, "asr", 1, 32);
305 OperandMatchResultTy parseSetEndImm(OperandVector &);
306 OperandMatchResultTy parseShifterImm(OperandVector &);
307 OperandMatchResultTy parseRotImm(OperandVector &);
308 OperandMatchResultTy parseBitfield(OperandVector &);
309 OperandMatchResultTy parsePostIdxReg(OperandVector &);
310 OperandMatchResultTy parseAM3Offset(OperandVector &);
311 OperandMatchResultTy parseFPImm(OperandVector &);
312 OperandMatchResultTy parseVectorList(OperandVector &);
313 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
316 // Asm Match Converter Methods
317 void cvtThumbMultiply(MCInst &Inst, const OperandVector &);
318 void cvtThumbBranches(MCInst &Inst, const OperandVector &);
320 bool validateInstruction(MCInst &Inst, const OperandVector &Ops);
321 bool processInstruction(MCInst &Inst, const OperandVector &Ops);
322 bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands);
323 bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands);
326 enum ARMMatchResultTy {
327 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
328 Match_RequiresNotITBlock,
330 Match_RequiresThumb2,
331 #define GET_OPERAND_DIAGNOSTIC_TYPES
332 #include "ARMGenAsmMatcher.inc"
336 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
337 const MCInstrInfo &MII,
338 const MCTargetOptions &Options)
339 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), UC(_Parser) {
340 MCAsmParserExtension::Initialize(_Parser);
342 // Cache the MCRegisterInfo.
343 MRI = getContext().getRegisterInfo();
345 // Initialize the set of available features.
346 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
348 // Not in an ITBlock to start with.
349 ITState.CurPosition = ~0U;
351 NextSymbolIsThumb = false;
354 // Implementation of the MCTargetAsmParser interface:
355 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
356 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
357 SMLoc NameLoc, OperandVector &Operands) override;
358 bool ParseDirective(AsmToken DirectiveID) override;
360 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
361 unsigned Kind) override;
362 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
364 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
365 OperandVector &Operands, MCStreamer &Out,
367 bool MatchingInlineAsm) override;
368 void onLabelParsed(MCSymbol *Symbol) override;
370 } // end anonymous namespace
374 /// ARMOperand - Instances of this class represent a parsed ARM machine
376 class ARMOperand : public MCParsedAsmOperand {
386 k_InstSyncBarrierOpt,
398 k_VectorListAllLanes,
404 k_BitfieldDescriptor,
408 SMLoc StartLoc, EndLoc, AlignmentLoc;
409 SmallVector<unsigned, 8> Registers;
412 ARMCC::CondCodes Val;
419 struct CoprocOptionOp {
432 ARM_ISB::InstSyncBOpt Val;
436 ARM_PROC::IFlags Val;
456 // A vector register list is a sequential list of 1 to 4 registers.
457 struct VectorListOp {
464 struct VectorIndexOp {
472 /// Combined record for all forms of ARM address expressions.
475 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
477 const MCConstantExpr *OffsetImm; // Offset immediate value
478 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
479 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
480 unsigned ShiftImm; // shift for OffsetReg.
481 unsigned Alignment; // 0 = no alignment specified
482 // n = alignment in bytes (2, 4, 8, 16, or 32)
483 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
486 struct PostIdxRegOp {
489 ARM_AM::ShiftOpc ShiftTy;
493 struct ShifterImmOp {
498 struct RegShiftedRegOp {
499 ARM_AM::ShiftOpc ShiftTy;
505 struct RegShiftedImmOp {
506 ARM_AM::ShiftOpc ShiftTy;
523 struct CoprocOptionOp CoprocOption;
524 struct MBOptOp MBOpt;
525 struct ISBOptOp ISBOpt;
526 struct ITMaskOp ITMask;
527 struct IFlagsOp IFlags;
528 struct MMaskOp MMask;
529 struct BankedRegOp BankedReg;
532 struct VectorListOp VectorList;
533 struct VectorIndexOp VectorIndex;
535 struct MemoryOp Memory;
536 struct PostIdxRegOp PostIdxReg;
537 struct ShifterImmOp ShifterImm;
538 struct RegShiftedRegOp RegShiftedReg;
539 struct RegShiftedImmOp RegShiftedImm;
540 struct RotImmOp RotImm;
541 struct BitfieldOp Bitfield;
545 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
546 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
548 StartLoc = o.StartLoc;
565 case k_DPRRegisterList:
566 case k_SPRRegisterList:
567 Registers = o.Registers;
570 case k_VectorListAllLanes:
571 case k_VectorListIndexed:
572 VectorList = o.VectorList;
579 CoprocOption = o.CoprocOption;
584 case k_MemBarrierOpt:
587 case k_InstSyncBarrierOpt:
592 case k_PostIndexRegister:
593 PostIdxReg = o.PostIdxReg;
599 BankedReg = o.BankedReg;
604 case k_ShifterImmediate:
605 ShifterImm = o.ShifterImm;
607 case k_ShiftedRegister:
608 RegShiftedReg = o.RegShiftedReg;
610 case k_ShiftedImmediate:
611 RegShiftedImm = o.RegShiftedImm;
613 case k_RotateImmediate:
616 case k_BitfieldDescriptor:
617 Bitfield = o.Bitfield;
620 VectorIndex = o.VectorIndex;
625 /// getStartLoc - Get the location of the first token of this operand.
626 SMLoc getStartLoc() const override { return StartLoc; }
627 /// getEndLoc - Get the location of the last token of this operand.
628 SMLoc getEndLoc() const override { return EndLoc; }
629 /// getLocRange - Get the range between the first and last token of this
631 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
633 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
634 SMLoc getAlignmentLoc() const {
635 assert(Kind == k_Memory && "Invalid access!");
639 ARMCC::CondCodes getCondCode() const {
640 assert(Kind == k_CondCode && "Invalid access!");
644 unsigned getCoproc() const {
645 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
649 StringRef getToken() const {
650 assert(Kind == k_Token && "Invalid access!");
651 return StringRef(Tok.Data, Tok.Length);
654 unsigned getReg() const override {
655 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
659 const SmallVectorImpl<unsigned> &getRegList() const {
660 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
661 Kind == k_SPRRegisterList) && "Invalid access!");
665 const MCExpr *getImm() const {
666 assert(isImm() && "Invalid access!");
670 unsigned getVectorIndex() const {
671 assert(Kind == k_VectorIndex && "Invalid access!");
672 return VectorIndex.Val;
675 ARM_MB::MemBOpt getMemBarrierOpt() const {
676 assert(Kind == k_MemBarrierOpt && "Invalid access!");
680 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
681 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
685 ARM_PROC::IFlags getProcIFlags() const {
686 assert(Kind == k_ProcIFlags && "Invalid access!");
690 unsigned getMSRMask() const {
691 assert(Kind == k_MSRMask && "Invalid access!");
695 unsigned getBankedReg() const {
696 assert(Kind == k_BankedReg && "Invalid access!");
697 return BankedReg.Val;
700 bool isCoprocNum() const { return Kind == k_CoprocNum; }
701 bool isCoprocReg() const { return Kind == k_CoprocReg; }
702 bool isCoprocOption() const { return Kind == k_CoprocOption; }
703 bool isCondCode() const { return Kind == k_CondCode; }
704 bool isCCOut() const { return Kind == k_CCOut; }
705 bool isITMask() const { return Kind == k_ITCondMask; }
706 bool isITCondCode() const { return Kind == k_CondCode; }
707 bool isImm() const override { return Kind == k_Immediate; }
708 // checks whether this operand is an unsigned offset which fits is a field
709 // of specified width and scaled by a specific number of bits
710 template<unsigned width, unsigned scale>
711 bool isUnsignedOffset() const {
712 if (!isImm()) return false;
713 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
714 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
715 int64_t Val = CE->getValue();
716 int64_t Align = 1LL << scale;
717 int64_t Max = Align * ((1LL << width) - 1);
718 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
722 // checks whether this operand is an signed offset which fits is a field
723 // of specified width and scaled by a specific number of bits
724 template<unsigned width, unsigned scale>
725 bool isSignedOffset() const {
726 if (!isImm()) return false;
727 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
728 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
729 int64_t Val = CE->getValue();
730 int64_t Align = 1LL << scale;
731 int64_t Max = Align * ((1LL << (width-1)) - 1);
732 int64_t Min = -Align * (1LL << (width-1));
733 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
738 // checks whether this operand is a memory operand computed as an offset
739 // applied to PC. the offset may have 8 bits of magnitude and is represented
740 // with two bits of shift. textually it may be either [pc, #imm], #imm or
741 // relocable expression...
742 bool isThumbMemPC() const {
745 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
747 if (!CE) return false;
748 Val = CE->getValue();
751 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
752 if(Memory.BaseRegNum != ARM::PC) return false;
753 Val = Memory.OffsetImm->getValue();
756 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
758 bool isFPImm() const {
759 if (!isImm()) return false;
760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
761 if (!CE) return false;
762 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
765 bool isFBits16() const {
766 if (!isImm()) return false;
767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
768 if (!CE) return false;
769 int64_t Value = CE->getValue();
770 return Value >= 0 && Value <= 16;
772 bool isFBits32() const {
773 if (!isImm()) return false;
774 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
775 if (!CE) return false;
776 int64_t Value = CE->getValue();
777 return Value >= 1 && Value <= 32;
779 bool isImm8s4() const {
780 if (!isImm()) return false;
781 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
782 if (!CE) return false;
783 int64_t Value = CE->getValue();
784 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
786 bool isImm0_1020s4() const {
787 if (!isImm()) return false;
788 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
789 if (!CE) return false;
790 int64_t Value = CE->getValue();
791 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
793 bool isImm0_508s4() const {
794 if (!isImm()) return false;
795 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
796 if (!CE) return false;
797 int64_t Value = CE->getValue();
798 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
800 bool isImm0_508s4Neg() const {
801 if (!isImm()) return false;
802 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
803 if (!CE) return false;
804 int64_t Value = -CE->getValue();
805 // explicitly exclude zero. we want that to use the normal 0_508 version.
806 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
808 bool isImm0_239() const {
809 if (!isImm()) return false;
810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return Value >= 0 && Value < 240;
815 bool isImm0_255() const {
816 if (!isImm()) return false;
817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
818 if (!CE) return false;
819 int64_t Value = CE->getValue();
820 return Value >= 0 && Value < 256;
822 bool isImm0_4095() const {
823 if (!isImm()) return false;
824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
825 if (!CE) return false;
826 int64_t Value = CE->getValue();
827 return Value >= 0 && Value < 4096;
829 bool isImm0_4095Neg() const {
830 if (!isImm()) return false;
831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
832 if (!CE) return false;
833 int64_t Value = -CE->getValue();
834 return Value > 0 && Value < 4096;
836 bool isImm0_1() const {
837 if (!isImm()) return false;
838 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
839 if (!CE) return false;
840 int64_t Value = CE->getValue();
841 return Value >= 0 && Value < 2;
843 bool isImm0_3() const {
844 if (!isImm()) return false;
845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
846 if (!CE) return false;
847 int64_t Value = CE->getValue();
848 return Value >= 0 && Value < 4;
850 bool isImm0_7() const {
851 if (!isImm()) return false;
852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
853 if (!CE) return false;
854 int64_t Value = CE->getValue();
855 return Value >= 0 && Value < 8;
857 bool isImm0_15() const {
858 if (!isImm()) return false;
859 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
860 if (!CE) return false;
861 int64_t Value = CE->getValue();
862 return Value >= 0 && Value < 16;
864 bool isImm0_31() const {
865 if (!isImm()) return false;
866 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
867 if (!CE) return false;
868 int64_t Value = CE->getValue();
869 return Value >= 0 && Value < 32;
871 bool isImm0_63() const {
872 if (!isImm()) return false;
873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
874 if (!CE) return false;
875 int64_t Value = CE->getValue();
876 return Value >= 0 && Value < 64;
878 bool isImm8() const {
879 if (!isImm()) return false;
880 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
881 if (!CE) return false;
882 int64_t Value = CE->getValue();
885 bool isImm16() const {
886 if (!isImm()) return false;
887 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
888 if (!CE) return false;
889 int64_t Value = CE->getValue();
892 bool isImm32() const {
893 if (!isImm()) return false;
894 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
895 if (!CE) return false;
896 int64_t Value = CE->getValue();
899 bool isShrImm8() const {
900 if (!isImm()) return false;
901 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
902 if (!CE) return false;
903 int64_t Value = CE->getValue();
904 return Value > 0 && Value <= 8;
906 bool isShrImm16() const {
907 if (!isImm()) return false;
908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
909 if (!CE) return false;
910 int64_t Value = CE->getValue();
911 return Value > 0 && Value <= 16;
913 bool isShrImm32() const {
914 if (!isImm()) return false;
915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
916 if (!CE) return false;
917 int64_t Value = CE->getValue();
918 return Value > 0 && Value <= 32;
920 bool isShrImm64() const {
921 if (!isImm()) return false;
922 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
923 if (!CE) return false;
924 int64_t Value = CE->getValue();
925 return Value > 0 && Value <= 64;
927 bool isImm1_7() const {
928 if (!isImm()) return false;
929 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
930 if (!CE) return false;
931 int64_t Value = CE->getValue();
932 return Value > 0 && Value < 8;
934 bool isImm1_15() const {
935 if (!isImm()) return false;
936 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
937 if (!CE) return false;
938 int64_t Value = CE->getValue();
939 return Value > 0 && Value < 16;
941 bool isImm1_31() const {
942 if (!isImm()) return false;
943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
944 if (!CE) return false;
945 int64_t Value = CE->getValue();
946 return Value > 0 && Value < 32;
948 bool isImm1_16() const {
949 if (!isImm()) return false;
950 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
951 if (!CE) return false;
952 int64_t Value = CE->getValue();
953 return Value > 0 && Value < 17;
955 bool isImm1_32() const {
956 if (!isImm()) return false;
957 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
958 if (!CE) return false;
959 int64_t Value = CE->getValue();
960 return Value > 0 && Value < 33;
962 bool isImm0_32() const {
963 if (!isImm()) return false;
964 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
965 if (!CE) return false;
966 int64_t Value = CE->getValue();
967 return Value >= 0 && Value < 33;
969 bool isImm0_65535() const {
970 if (!isImm()) return false;
971 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
972 if (!CE) return false;
973 int64_t Value = CE->getValue();
974 return Value >= 0 && Value < 65536;
976 bool isImm256_65535Expr() const {
977 if (!isImm()) return false;
978 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
979 // If it's not a constant expression, it'll generate a fixup and be
981 if (!CE) return true;
982 int64_t Value = CE->getValue();
983 return Value >= 256 && Value < 65536;
985 bool isImm0_65535Expr() const {
986 if (!isImm()) return false;
987 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
988 // If it's not a constant expression, it'll generate a fixup and be
990 if (!CE) return true;
991 int64_t Value = CE->getValue();
992 return Value >= 0 && Value < 65536;
994 bool isImm24bit() const {
995 if (!isImm()) return false;
996 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
997 if (!CE) return false;
998 int64_t Value = CE->getValue();
999 return Value >= 0 && Value <= 0xffffff;
1001 bool isImmThumbSR() const {
1002 if (!isImm()) return false;
1003 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1004 if (!CE) return false;
1005 int64_t Value = CE->getValue();
1006 return Value > 0 && Value < 33;
1008 bool isPKHLSLImm() const {
1009 if (!isImm()) return false;
1010 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1011 if (!CE) return false;
1012 int64_t Value = CE->getValue();
1013 return Value >= 0 && Value < 32;
1015 bool isPKHASRImm() const {
1016 if (!isImm()) return false;
1017 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1018 if (!CE) return false;
1019 int64_t Value = CE->getValue();
1020 return Value > 0 && Value <= 32;
1022 bool isAdrLabel() const {
1023 // If we have an immediate that's not a constant, treat it as a label
1024 // reference needing a fixup. If it is a constant, but it can't fit
1025 // into shift immediate encoding, we reject it.
1026 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1027 else return (isARMSOImm() || isARMSOImmNeg());
1029 bool isARMSOImm() const {
1030 if (!isImm()) return false;
1031 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1032 if (!CE) return false;
1033 int64_t Value = CE->getValue();
1034 return ARM_AM::getSOImmVal(Value) != -1;
1036 bool isARMSOImmNot() const {
1037 if (!isImm()) return false;
1038 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1039 if (!CE) return false;
1040 int64_t Value = CE->getValue();
1041 return ARM_AM::getSOImmVal(~Value) != -1;
1043 bool isARMSOImmNeg() const {
1044 if (!isImm()) return false;
1045 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1046 if (!CE) return false;
1047 int64_t Value = CE->getValue();
1048 // Only use this when not representable as a plain so_imm.
1049 return ARM_AM::getSOImmVal(Value) == -1 &&
1050 ARM_AM::getSOImmVal(-Value) != -1;
1052 bool isT2SOImm() const {
1053 if (!isImm()) return false;
1054 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1055 if (!CE) return false;
1056 int64_t Value = CE->getValue();
1057 return ARM_AM::getT2SOImmVal(Value) != -1;
1059 bool isT2SOImmNot() const {
1060 if (!isImm()) return false;
1061 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1062 if (!CE) return false;
1063 int64_t Value = CE->getValue();
1064 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1065 ARM_AM::getT2SOImmVal(~Value) != -1;
1067 bool isT2SOImmNeg() const {
1068 if (!isImm()) return false;
1069 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1070 if (!CE) return false;
1071 int64_t Value = CE->getValue();
1072 // Only use this when not representable as a plain so_imm.
1073 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1074 ARM_AM::getT2SOImmVal(-Value) != -1;
1076 bool isSetEndImm() const {
1077 if (!isImm()) return false;
1078 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1079 if (!CE) return false;
1080 int64_t Value = CE->getValue();
1081 return Value == 1 || Value == 0;
1083 bool isReg() const override { return Kind == k_Register; }
1084 bool isRegList() const { return Kind == k_RegisterList; }
1085 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1086 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
1087 bool isToken() const override { return Kind == k_Token; }
1088 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
1089 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
1090 bool isMem() const override { return Kind == k_Memory; }
1091 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1092 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1093 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1094 bool isRotImm() const { return Kind == k_RotateImmediate; }
1095 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1096 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
1097 bool isPostIdxReg() const {
1098 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
1100 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
1103 // No offset of any kind.
1104 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
1105 (alignOK || Memory.Alignment == Alignment);
1107 bool isMemPCRelImm12() const {
1108 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1110 // Base register must be PC.
1111 if (Memory.BaseRegNum != ARM::PC)
1113 // Immediate offset in range [-4095, 4095].
1114 if (!Memory.OffsetImm) return true;
1115 int64_t Val = Memory.OffsetImm->getValue();
1116 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1118 bool isAlignedMemory() const {
1119 return isMemNoOffset(true);
1121 bool isAlignedMemoryNone() const {
1122 return isMemNoOffset(false, 0);
1124 bool isDupAlignedMemoryNone() const {
1125 return isMemNoOffset(false, 0);
1127 bool isAlignedMemory16() const {
1128 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1130 return isMemNoOffset(false, 0);
1132 bool isDupAlignedMemory16() const {
1133 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1135 return isMemNoOffset(false, 0);
1137 bool isAlignedMemory32() const {
1138 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1140 return isMemNoOffset(false, 0);
1142 bool isDupAlignedMemory32() const {
1143 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1145 return isMemNoOffset(false, 0);
1147 bool isAlignedMemory64() const {
1148 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1150 return isMemNoOffset(false, 0);
1152 bool isDupAlignedMemory64() const {
1153 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1155 return isMemNoOffset(false, 0);
1157 bool isAlignedMemory64or128() const {
1158 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1160 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1162 return isMemNoOffset(false, 0);
1164 bool isDupAlignedMemory64or128() const {
1165 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1167 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1169 return isMemNoOffset(false, 0);
1171 bool isAlignedMemory64or128or256() const {
1172 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1174 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1176 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1178 return isMemNoOffset(false, 0);
1180 bool isAddrMode2() const {
1181 if (!isMem() || Memory.Alignment != 0) return false;
1182 // Check for register offset.
1183 if (Memory.OffsetRegNum) return true;
1184 // Immediate offset in range [-4095, 4095].
1185 if (!Memory.OffsetImm) return true;
1186 int64_t Val = Memory.OffsetImm->getValue();
1187 return Val > -4096 && Val < 4096;
1189 bool isAM2OffsetImm() const {
1190 if (!isImm()) return false;
1191 // Immediate offset in range [-4095, 4095].
1192 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1193 if (!CE) return false;
1194 int64_t Val = CE->getValue();
1195 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1197 bool isAddrMode3() const {
1198 // If we have an immediate that's not a constant, treat it as a label
1199 // reference needing a fixup. If it is a constant, it's something else
1200 // and we reject it.
1201 if (isImm() && !isa<MCConstantExpr>(getImm()))
1203 if (!isMem() || Memory.Alignment != 0) return false;
1204 // No shifts are legal for AM3.
1205 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1206 // Check for register offset.
1207 if (Memory.OffsetRegNum) return true;
1208 // Immediate offset in range [-255, 255].
1209 if (!Memory.OffsetImm) return true;
1210 int64_t Val = Memory.OffsetImm->getValue();
1211 // The #-0 offset is encoded as INT32_MIN, and we have to check
1213 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1215 bool isAM3Offset() const {
1216 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1218 if (Kind == k_PostIndexRegister)
1219 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1220 // Immediate offset in range [-255, 255].
1221 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1222 if (!CE) return false;
1223 int64_t Val = CE->getValue();
1224 // Special case, #-0 is INT32_MIN.
1225 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1227 bool isAddrMode5() const {
1228 // If we have an immediate that's not a constant, treat it as a label
1229 // reference needing a fixup. If it is a constant, it's something else
1230 // and we reject it.
1231 if (isImm() && !isa<MCConstantExpr>(getImm()))
1233 if (!isMem() || Memory.Alignment != 0) return false;
1234 // Check for register offset.
1235 if (Memory.OffsetRegNum) return false;
1236 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1237 if (!Memory.OffsetImm) return true;
1238 int64_t Val = Memory.OffsetImm->getValue();
1239 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1242 bool isMemTBB() const {
1243 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1244 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1248 bool isMemTBH() const {
1249 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1250 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1251 Memory.Alignment != 0 )
1255 bool isMemRegOffset() const {
1256 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1260 bool isT2MemRegOffset() const {
1261 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1262 Memory.Alignment != 0)
1264 // Only lsl #{0, 1, 2, 3} allowed.
1265 if (Memory.ShiftType == ARM_AM::no_shift)
1267 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1271 bool isMemThumbRR() const {
1272 // Thumb reg+reg addressing is simple. Just two registers, a base and
1273 // an offset. No shifts, negations or any other complicating factors.
1274 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1275 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1277 return isARMLowRegister(Memory.BaseRegNum) &&
1278 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1280 bool isMemThumbRIs4() const {
1281 if (!isMem() || Memory.OffsetRegNum != 0 ||
1282 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1284 // Immediate offset, multiple of 4 in range [0, 124].
1285 if (!Memory.OffsetImm) return true;
1286 int64_t Val = Memory.OffsetImm->getValue();
1287 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1289 bool isMemThumbRIs2() const {
1290 if (!isMem() || Memory.OffsetRegNum != 0 ||
1291 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1293 // Immediate offset, multiple of 4 in range [0, 62].
1294 if (!Memory.OffsetImm) return true;
1295 int64_t Val = Memory.OffsetImm->getValue();
1296 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1298 bool isMemThumbRIs1() const {
1299 if (!isMem() || Memory.OffsetRegNum != 0 ||
1300 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1302 // Immediate offset in range [0, 31].
1303 if (!Memory.OffsetImm) return true;
1304 int64_t Val = Memory.OffsetImm->getValue();
1305 return Val >= 0 && Val <= 31;
1307 bool isMemThumbSPI() const {
1308 if (!isMem() || Memory.OffsetRegNum != 0 ||
1309 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1311 // Immediate offset, multiple of 4 in range [0, 1020].
1312 if (!Memory.OffsetImm) return true;
1313 int64_t Val = Memory.OffsetImm->getValue();
1314 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1316 bool isMemImm8s4Offset() const {
1317 // If we have an immediate that's not a constant, treat it as a label
1318 // reference needing a fixup. If it is a constant, it's something else
1319 // and we reject it.
1320 if (isImm() && !isa<MCConstantExpr>(getImm()))
1322 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1324 // Immediate offset a multiple of 4 in range [-1020, 1020].
1325 if (!Memory.OffsetImm) return true;
1326 int64_t Val = Memory.OffsetImm->getValue();
1327 // Special case, #-0 is INT32_MIN.
1328 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1330 bool isMemImm0_1020s4Offset() const {
1331 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1333 // Immediate offset a multiple of 4 in range [0, 1020].
1334 if (!Memory.OffsetImm) return true;
1335 int64_t Val = Memory.OffsetImm->getValue();
1336 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1338 bool isMemImm8Offset() const {
1339 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1341 // Base reg of PC isn't allowed for these encodings.
1342 if (Memory.BaseRegNum == ARM::PC) return false;
1343 // Immediate offset in range [-255, 255].
1344 if (!Memory.OffsetImm) return true;
1345 int64_t Val = Memory.OffsetImm->getValue();
1346 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1348 bool isMemPosImm8Offset() const {
1349 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1351 // Immediate offset in range [0, 255].
1352 if (!Memory.OffsetImm) return true;
1353 int64_t Val = Memory.OffsetImm->getValue();
1354 return Val >= 0 && Val < 256;
1356 bool isMemNegImm8Offset() const {
1357 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1359 // Base reg of PC isn't allowed for these encodings.
1360 if (Memory.BaseRegNum == ARM::PC) return false;
1361 // Immediate offset in range [-255, -1].
1362 if (!Memory.OffsetImm) return false;
1363 int64_t Val = Memory.OffsetImm->getValue();
1364 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1366 bool isMemUImm12Offset() const {
1367 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1369 // Immediate offset in range [0, 4095].
1370 if (!Memory.OffsetImm) return true;
1371 int64_t Val = Memory.OffsetImm->getValue();
1372 return (Val >= 0 && Val < 4096);
1374 bool isMemImm12Offset() const {
1375 // If we have an immediate that's not a constant, treat it as a label
1376 // reference needing a fixup. If it is a constant, it's something else
1377 // and we reject it.
1378 if (isImm() && !isa<MCConstantExpr>(getImm()))
1381 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1383 // Immediate offset in range [-4095, 4095].
1384 if (!Memory.OffsetImm) return true;
1385 int64_t Val = Memory.OffsetImm->getValue();
1386 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1388 bool isPostIdxImm8() const {
1389 if (!isImm()) return false;
1390 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1391 if (!CE) return false;
1392 int64_t Val = CE->getValue();
1393 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1395 bool isPostIdxImm8s4() const {
1396 if (!isImm()) return false;
1397 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1398 if (!CE) return false;
1399 int64_t Val = CE->getValue();
1400 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1404 bool isMSRMask() const { return Kind == k_MSRMask; }
1405 bool isBankedReg() const { return Kind == k_BankedReg; }
1406 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1409 bool isSingleSpacedVectorList() const {
1410 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1412 bool isDoubleSpacedVectorList() const {
1413 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1415 bool isVecListOneD() const {
1416 if (!isSingleSpacedVectorList()) return false;
1417 return VectorList.Count == 1;
1420 bool isVecListDPair() const {
1421 if (!isSingleSpacedVectorList()) return false;
1422 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1423 .contains(VectorList.RegNum));
1426 bool isVecListThreeD() const {
1427 if (!isSingleSpacedVectorList()) return false;
1428 return VectorList.Count == 3;
1431 bool isVecListFourD() const {
1432 if (!isSingleSpacedVectorList()) return false;
1433 return VectorList.Count == 4;
1436 bool isVecListDPairSpaced() const {
1437 if (Kind != k_VectorList) return false;
1438 if (isSingleSpacedVectorList()) return false;
1439 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1440 .contains(VectorList.RegNum));
1443 bool isVecListThreeQ() const {
1444 if (!isDoubleSpacedVectorList()) return false;
1445 return VectorList.Count == 3;
1448 bool isVecListFourQ() const {
1449 if (!isDoubleSpacedVectorList()) return false;
1450 return VectorList.Count == 4;
1453 bool isSingleSpacedVectorAllLanes() const {
1454 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1456 bool isDoubleSpacedVectorAllLanes() const {
1457 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1459 bool isVecListOneDAllLanes() const {
1460 if (!isSingleSpacedVectorAllLanes()) return false;
1461 return VectorList.Count == 1;
1464 bool isVecListDPairAllLanes() const {
1465 if (!isSingleSpacedVectorAllLanes()) return false;
1466 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1467 .contains(VectorList.RegNum));
1470 bool isVecListDPairSpacedAllLanes() const {
1471 if (!isDoubleSpacedVectorAllLanes()) return false;
1472 return VectorList.Count == 2;
1475 bool isVecListThreeDAllLanes() const {
1476 if (!isSingleSpacedVectorAllLanes()) return false;
1477 return VectorList.Count == 3;
1480 bool isVecListThreeQAllLanes() const {
1481 if (!isDoubleSpacedVectorAllLanes()) return false;
1482 return VectorList.Count == 3;
1485 bool isVecListFourDAllLanes() const {
1486 if (!isSingleSpacedVectorAllLanes()) return false;
1487 return VectorList.Count == 4;
1490 bool isVecListFourQAllLanes() const {
1491 if (!isDoubleSpacedVectorAllLanes()) return false;
1492 return VectorList.Count == 4;
1495 bool isSingleSpacedVectorIndexed() const {
1496 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1498 bool isDoubleSpacedVectorIndexed() const {
1499 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1501 bool isVecListOneDByteIndexed() const {
1502 if (!isSingleSpacedVectorIndexed()) return false;
1503 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1506 bool isVecListOneDHWordIndexed() const {
1507 if (!isSingleSpacedVectorIndexed()) return false;
1508 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1511 bool isVecListOneDWordIndexed() const {
1512 if (!isSingleSpacedVectorIndexed()) return false;
1513 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1516 bool isVecListTwoDByteIndexed() const {
1517 if (!isSingleSpacedVectorIndexed()) return false;
1518 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1521 bool isVecListTwoDHWordIndexed() const {
1522 if (!isSingleSpacedVectorIndexed()) return false;
1523 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1526 bool isVecListTwoQWordIndexed() const {
1527 if (!isDoubleSpacedVectorIndexed()) return false;
1528 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1531 bool isVecListTwoQHWordIndexed() const {
1532 if (!isDoubleSpacedVectorIndexed()) return false;
1533 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1536 bool isVecListTwoDWordIndexed() const {
1537 if (!isSingleSpacedVectorIndexed()) return false;
1538 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1541 bool isVecListThreeDByteIndexed() const {
1542 if (!isSingleSpacedVectorIndexed()) return false;
1543 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1546 bool isVecListThreeDHWordIndexed() const {
1547 if (!isSingleSpacedVectorIndexed()) return false;
1548 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1551 bool isVecListThreeQWordIndexed() const {
1552 if (!isDoubleSpacedVectorIndexed()) return false;
1553 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1556 bool isVecListThreeQHWordIndexed() const {
1557 if (!isDoubleSpacedVectorIndexed()) return false;
1558 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1561 bool isVecListThreeDWordIndexed() const {
1562 if (!isSingleSpacedVectorIndexed()) return false;
1563 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1566 bool isVecListFourDByteIndexed() const {
1567 if (!isSingleSpacedVectorIndexed()) return false;
1568 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1571 bool isVecListFourDHWordIndexed() const {
1572 if (!isSingleSpacedVectorIndexed()) return false;
1573 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1576 bool isVecListFourQWordIndexed() const {
1577 if (!isDoubleSpacedVectorIndexed()) return false;
1578 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1581 bool isVecListFourQHWordIndexed() const {
1582 if (!isDoubleSpacedVectorIndexed()) return false;
1583 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1586 bool isVecListFourDWordIndexed() const {
1587 if (!isSingleSpacedVectorIndexed()) return false;
1588 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1591 bool isVectorIndex8() const {
1592 if (Kind != k_VectorIndex) return false;
1593 return VectorIndex.Val < 8;
1595 bool isVectorIndex16() const {
1596 if (Kind != k_VectorIndex) return false;
1597 return VectorIndex.Val < 4;
1599 bool isVectorIndex32() const {
1600 if (Kind != k_VectorIndex) return false;
1601 return VectorIndex.Val < 2;
1604 bool isNEONi8splat() const {
1605 if (!isImm()) return false;
1606 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1607 // Must be a constant.
1608 if (!CE) return false;
1609 int64_t Value = CE->getValue();
1610 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1612 return Value >= 0 && Value < 256;
1615 bool isNEONi16splat() const {
1616 if (isNEONByteReplicate(2))
1617 return false; // Leave that for bytes replication and forbid by default.
1620 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1621 // Must be a constant.
1622 if (!CE) return false;
1623 int64_t Value = CE->getValue();
1624 // i16 value in the range [0,255] or [0x0100, 0xff00]
1625 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1628 bool isNEONi32splat() const {
1629 if (isNEONByteReplicate(4))
1630 return false; // Leave that for bytes replication and forbid by default.
1633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1634 // Must be a constant.
1635 if (!CE) return false;
1636 int64_t Value = CE->getValue();
1637 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1638 return (Value >= 0 && Value < 256) ||
1639 (Value >= 0x0100 && Value <= 0xff00) ||
1640 (Value >= 0x010000 && Value <= 0xff0000) ||
1641 (Value >= 0x01000000 && Value <= 0xff000000);
1644 bool isNEONByteReplicate(unsigned NumBytes) const {
1647 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1648 // Must be a constant.
1651 int64_t Value = CE->getValue();
1653 return false; // Don't bother with zero.
1655 unsigned char B = Value & 0xff;
1656 for (unsigned i = 1; i < NumBytes; ++i) {
1658 if ((Value & 0xff) != B)
1663 bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); }
1664 bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); }
1665 bool isNEONi32vmov() const {
1666 if (isNEONByteReplicate(4))
1667 return false; // Let it to be classified as byte-replicate case.
1670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1671 // Must be a constant.
1674 int64_t Value = CE->getValue();
1675 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1676 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1677 return (Value >= 0 && Value < 256) ||
1678 (Value >= 0x0100 && Value <= 0xff00) ||
1679 (Value >= 0x010000 && Value <= 0xff0000) ||
1680 (Value >= 0x01000000 && Value <= 0xff000000) ||
1681 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1682 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1684 bool isNEONi32vmovNeg() const {
1685 if (!isImm()) return false;
1686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1687 // Must be a constant.
1688 if (!CE) return false;
1689 int64_t Value = ~CE->getValue();
1690 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1691 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1692 return (Value >= 0 && Value < 256) ||
1693 (Value >= 0x0100 && Value <= 0xff00) ||
1694 (Value >= 0x010000 && Value <= 0xff0000) ||
1695 (Value >= 0x01000000 && Value <= 0xff000000) ||
1696 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1697 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1700 bool isNEONi64splat() const {
1701 if (!isImm()) return false;
1702 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1703 // Must be a constant.
1704 if (!CE) return false;
1705 uint64_t Value = CE->getValue();
1706 // i64 value with each byte being either 0 or 0xff.
1707 for (unsigned i = 0; i < 8; ++i)
1708 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1712 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1713 // Add as immediates when possible. Null MCExpr = 0.
1715 Inst.addOperand(MCOperand::CreateImm(0));
1716 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1717 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1719 Inst.addOperand(MCOperand::CreateExpr(Expr));
1722 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1723 assert(N == 2 && "Invalid number of operands!");
1724 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1725 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1726 Inst.addOperand(MCOperand::CreateReg(RegNum));
1729 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1730 assert(N == 1 && "Invalid number of operands!");
1731 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1734 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1735 assert(N == 1 && "Invalid number of operands!");
1736 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1739 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1740 assert(N == 1 && "Invalid number of operands!");
1741 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1744 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1745 assert(N == 1 && "Invalid number of operands!");
1746 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1749 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1750 assert(N == 1 && "Invalid number of operands!");
1751 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1754 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1755 assert(N == 1 && "Invalid number of operands!");
1756 Inst.addOperand(MCOperand::CreateReg(getReg()));
1759 void addRegOperands(MCInst &Inst, unsigned N) const {
1760 assert(N == 1 && "Invalid number of operands!");
1761 Inst.addOperand(MCOperand::CreateReg(getReg()));
1764 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1765 assert(N == 3 && "Invalid number of operands!");
1766 assert(isRegShiftedReg() &&
1767 "addRegShiftedRegOperands() on non-RegShiftedReg!");
1768 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1769 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1770 Inst.addOperand(MCOperand::CreateImm(
1771 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1774 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1775 assert(N == 2 && "Invalid number of operands!");
1776 assert(isRegShiftedImm() &&
1777 "addRegShiftedImmOperands() on non-RegShiftedImm!");
1778 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1779 // Shift of #32 is encoded as 0 where permitted
1780 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1781 Inst.addOperand(MCOperand::CreateImm(
1782 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1785 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1786 assert(N == 1 && "Invalid number of operands!");
1787 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1791 void addRegListOperands(MCInst &Inst, unsigned N) const {
1792 assert(N == 1 && "Invalid number of operands!");
1793 const SmallVectorImpl<unsigned> &RegList = getRegList();
1794 for (SmallVectorImpl<unsigned>::const_iterator
1795 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1796 Inst.addOperand(MCOperand::CreateReg(*I));
1799 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1800 addRegListOperands(Inst, N);
1803 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1804 addRegListOperands(Inst, N);
1807 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1808 assert(N == 1 && "Invalid number of operands!");
1809 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1810 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1813 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1814 assert(N == 1 && "Invalid number of operands!");
1815 // Munge the lsb/width into a bitfield mask.
1816 unsigned lsb = Bitfield.LSB;
1817 unsigned width = Bitfield.Width;
1818 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1819 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1820 (32 - (lsb + width)));
1821 Inst.addOperand(MCOperand::CreateImm(Mask));
1824 void addImmOperands(MCInst &Inst, unsigned N) const {
1825 assert(N == 1 && "Invalid number of operands!");
1826 addExpr(Inst, getImm());
1829 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1830 assert(N == 1 && "Invalid number of operands!");
1831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1832 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1835 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1836 assert(N == 1 && "Invalid number of operands!");
1837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1838 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1841 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1842 assert(N == 1 && "Invalid number of operands!");
1843 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1844 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1845 Inst.addOperand(MCOperand::CreateImm(Val));
1848 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1849 assert(N == 1 && "Invalid number of operands!");
1850 // FIXME: We really want to scale the value here, but the LDRD/STRD
1851 // instruction don't encode operands that way yet.
1852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1853 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1856 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1857 assert(N == 1 && "Invalid number of operands!");
1858 // The immediate is scaled by four in the encoding and is stored
1859 // in the MCInst as such. Lop off the low two bits here.
1860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1861 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1864 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1865 assert(N == 1 && "Invalid number of operands!");
1866 // The immediate is scaled by four in the encoding and is stored
1867 // in the MCInst as such. Lop off the low two bits here.
1868 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1869 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1872 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1873 assert(N == 1 && "Invalid number of operands!");
1874 // The immediate is scaled by four in the encoding and is stored
1875 // in the MCInst as such. Lop off the low two bits here.
1876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1877 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1880 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1881 assert(N == 1 && "Invalid number of operands!");
1882 // The constant encodes as the immediate-1, and we store in the instruction
1883 // the bits as encoded, so subtract off one here.
1884 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1885 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1888 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1889 assert(N == 1 && "Invalid number of operands!");
1890 // The constant encodes as the immediate-1, and we store in the instruction
1891 // the bits as encoded, so subtract off one here.
1892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1893 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1896 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1897 assert(N == 1 && "Invalid number of operands!");
1898 // The constant encodes as the immediate, except for 32, which encodes as
1900 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1901 unsigned Imm = CE->getValue();
1902 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1905 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1906 assert(N == 1 && "Invalid number of operands!");
1907 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1908 // the instruction as well.
1909 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1910 int Val = CE->getValue();
1911 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1914 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1915 assert(N == 1 && "Invalid number of operands!");
1916 // The operand is actually a t2_so_imm, but we have its bitwise
1917 // negation in the assembly source, so twiddle it here.
1918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1919 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1922 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1923 assert(N == 1 && "Invalid number of operands!");
1924 // The operand is actually a t2_so_imm, but we have its
1925 // negation in the assembly source, so twiddle it here.
1926 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1927 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1930 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1931 assert(N == 1 && "Invalid number of operands!");
1932 // The operand is actually an imm0_4095, but we have its
1933 // negation in the assembly source, so twiddle it here.
1934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1935 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1938 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1939 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1940 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1944 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1945 assert(SR && "Unknown value type!");
1946 Inst.addOperand(MCOperand::CreateExpr(SR));
1949 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1950 assert(N == 1 && "Invalid number of operands!");
1952 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1954 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1958 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1959 assert(SR && "Unknown value type!");
1960 Inst.addOperand(MCOperand::CreateExpr(SR));
1964 assert(isMem() && "Unknown value type!");
1965 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1966 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1969 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1970 assert(N == 1 && "Invalid number of operands!");
1971 // The operand is actually a so_imm, but we have its bitwise
1972 // negation in the assembly source, so twiddle it here.
1973 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1974 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1977 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1978 assert(N == 1 && "Invalid number of operands!");
1979 // The operand is actually a so_imm, but we have its
1980 // negation in the assembly source, so twiddle it here.
1981 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1982 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1985 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1986 assert(N == 1 && "Invalid number of operands!");
1987 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1990 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1991 assert(N == 1 && "Invalid number of operands!");
1992 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1995 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1996 assert(N == 1 && "Invalid number of operands!");
1997 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2000 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
2001 assert(N == 1 && "Invalid number of operands!");
2002 int32_t Imm = Memory.OffsetImm->getValue();
2003 Inst.addOperand(MCOperand::CreateImm(Imm));
2006 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
2007 assert(N == 1 && "Invalid number of operands!");
2008 assert(isImm() && "Not an immediate!");
2010 // If we have an immediate that's not a constant, treat it as a label
2011 // reference needing a fixup.
2012 if (!isa<MCConstantExpr>(getImm())) {
2013 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2017 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2018 int Val = CE->getValue();
2019 Inst.addOperand(MCOperand::CreateImm(Val));
2022 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
2023 assert(N == 2 && "Invalid number of operands!");
2024 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2025 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
2028 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2029 addAlignedMemoryOperands(Inst, N);
2032 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2033 addAlignedMemoryOperands(Inst, N);
2036 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2037 addAlignedMemoryOperands(Inst, N);
2040 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2041 addAlignedMemoryOperands(Inst, N);
2044 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2045 addAlignedMemoryOperands(Inst, N);
2048 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2049 addAlignedMemoryOperands(Inst, N);
2052 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2053 addAlignedMemoryOperands(Inst, N);
2056 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2057 addAlignedMemoryOperands(Inst, N);
2060 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2061 addAlignedMemoryOperands(Inst, N);
2064 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2065 addAlignedMemoryOperands(Inst, N);
2068 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2069 addAlignedMemoryOperands(Inst, N);
2072 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2073 assert(N == 3 && "Invalid number of operands!");
2074 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2075 if (!Memory.OffsetRegNum) {
2076 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2077 // Special case for #-0
2078 if (Val == INT32_MIN) Val = 0;
2079 if (Val < 0) Val = -Val;
2080 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2082 // For register offset, we encode the shift type and negation flag
2084 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2085 Memory.ShiftImm, Memory.ShiftType);
2087 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2088 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2089 Inst.addOperand(MCOperand::CreateImm(Val));
2092 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
2093 assert(N == 2 && "Invalid number of operands!");
2094 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2095 assert(CE && "non-constant AM2OffsetImm operand!");
2096 int32_t Val = CE->getValue();
2097 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2098 // Special case for #-0
2099 if (Val == INT32_MIN) Val = 0;
2100 if (Val < 0) Val = -Val;
2101 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2102 Inst.addOperand(MCOperand::CreateReg(0));
2103 Inst.addOperand(MCOperand::CreateImm(Val));
2106 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
2107 assert(N == 3 && "Invalid number of operands!");
2108 // If we have an immediate that's not a constant, treat it as a label
2109 // reference needing a fixup. If it is a constant, it's something else
2110 // and we reject it.
2112 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2113 Inst.addOperand(MCOperand::CreateReg(0));
2114 Inst.addOperand(MCOperand::CreateImm(0));
2118 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2119 if (!Memory.OffsetRegNum) {
2120 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2121 // Special case for #-0
2122 if (Val == INT32_MIN) Val = 0;
2123 if (Val < 0) Val = -Val;
2124 Val = ARM_AM::getAM3Opc(AddSub, Val);
2126 // For register offset, we encode the shift type and negation flag
2128 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
2130 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2131 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2132 Inst.addOperand(MCOperand::CreateImm(Val));
2135 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2136 assert(N == 2 && "Invalid number of operands!");
2137 if (Kind == k_PostIndexRegister) {
2139 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2140 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2141 Inst.addOperand(MCOperand::CreateImm(Val));
2146 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2147 int32_t Val = CE->getValue();
2148 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2149 // Special case for #-0
2150 if (Val == INT32_MIN) Val = 0;
2151 if (Val < 0) Val = -Val;
2152 Val = ARM_AM::getAM3Opc(AddSub, Val);
2153 Inst.addOperand(MCOperand::CreateReg(0));
2154 Inst.addOperand(MCOperand::CreateImm(Val));
2157 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2158 assert(N == 2 && "Invalid number of operands!");
2159 // If we have an immediate that's not a constant, treat it as a label
2160 // reference needing a fixup. If it is a constant, it's something else
2161 // and we reject it.
2163 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2164 Inst.addOperand(MCOperand::CreateImm(0));
2168 // The lower two bits are always zero and as such are not encoded.
2169 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2170 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2171 // Special case for #-0
2172 if (Val == INT32_MIN) Val = 0;
2173 if (Val < 0) Val = -Val;
2174 Val = ARM_AM::getAM5Opc(AddSub, Val);
2175 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2176 Inst.addOperand(MCOperand::CreateImm(Val));
2179 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2180 assert(N == 2 && "Invalid number of operands!");
2181 // If we have an immediate that's not a constant, treat it as a label
2182 // reference needing a fixup. If it is a constant, it's something else
2183 // and we reject it.
2185 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2186 Inst.addOperand(MCOperand::CreateImm(0));
2190 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2191 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2192 Inst.addOperand(MCOperand::CreateImm(Val));
2195 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2196 assert(N == 2 && "Invalid number of operands!");
2197 // The lower two bits are always zero and as such are not encoded.
2198 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2199 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2200 Inst.addOperand(MCOperand::CreateImm(Val));
2203 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2204 assert(N == 2 && "Invalid number of operands!");
2205 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2206 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2207 Inst.addOperand(MCOperand::CreateImm(Val));
2210 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2211 addMemImm8OffsetOperands(Inst, N);
2214 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2215 addMemImm8OffsetOperands(Inst, N);
2218 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2219 assert(N == 2 && "Invalid number of operands!");
2220 // If this is an immediate, it's a label reference.
2222 addExpr(Inst, getImm());
2223 Inst.addOperand(MCOperand::CreateImm(0));
2227 // Otherwise, it's a normal memory reg+offset.
2228 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2229 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2230 Inst.addOperand(MCOperand::CreateImm(Val));
2233 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2234 assert(N == 2 && "Invalid number of operands!");
2235 // If this is an immediate, it's a label reference.
2237 addExpr(Inst, getImm());
2238 Inst.addOperand(MCOperand::CreateImm(0));
2242 // Otherwise, it's a normal memory reg+offset.
2243 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2244 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2245 Inst.addOperand(MCOperand::CreateImm(Val));
2248 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2249 assert(N == 2 && "Invalid number of operands!");
2250 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2251 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2254 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2255 assert(N == 2 && "Invalid number of operands!");
2256 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2257 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2260 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2261 assert(N == 3 && "Invalid number of operands!");
2263 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2264 Memory.ShiftImm, Memory.ShiftType);
2265 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2266 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2267 Inst.addOperand(MCOperand::CreateImm(Val));
2270 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2271 assert(N == 3 && "Invalid number of operands!");
2272 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2273 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2274 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2277 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2278 assert(N == 2 && "Invalid number of operands!");
2279 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2280 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2283 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2284 assert(N == 2 && "Invalid number of operands!");
2285 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2286 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2287 Inst.addOperand(MCOperand::CreateImm(Val));
2290 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2291 assert(N == 2 && "Invalid number of operands!");
2292 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2293 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2294 Inst.addOperand(MCOperand::CreateImm(Val));
2297 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2298 assert(N == 2 && "Invalid number of operands!");
2299 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2300 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2301 Inst.addOperand(MCOperand::CreateImm(Val));
2304 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2305 assert(N == 2 && "Invalid number of operands!");
2306 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2307 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2308 Inst.addOperand(MCOperand::CreateImm(Val));
2311 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2312 assert(N == 1 && "Invalid number of operands!");
2313 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2314 assert(CE && "non-constant post-idx-imm8 operand!");
2315 int Imm = CE->getValue();
2316 bool isAdd = Imm >= 0;
2317 if (Imm == INT32_MIN) Imm = 0;
2318 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2319 Inst.addOperand(MCOperand::CreateImm(Imm));
2322 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2323 assert(N == 1 && "Invalid number of operands!");
2324 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2325 assert(CE && "non-constant post-idx-imm8s4 operand!");
2326 int Imm = CE->getValue();
2327 bool isAdd = Imm >= 0;
2328 if (Imm == INT32_MIN) Imm = 0;
2329 // Immediate is scaled by 4.
2330 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2331 Inst.addOperand(MCOperand::CreateImm(Imm));
2334 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2335 assert(N == 2 && "Invalid number of operands!");
2336 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2337 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2340 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2341 assert(N == 2 && "Invalid number of operands!");
2342 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2343 // The sign, shift type, and shift amount are encoded in a single operand
2344 // using the AM2 encoding helpers.
2345 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2346 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2347 PostIdxReg.ShiftTy);
2348 Inst.addOperand(MCOperand::CreateImm(Imm));
2351 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2352 assert(N == 1 && "Invalid number of operands!");
2353 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2356 void addBankedRegOperands(MCInst &Inst, unsigned N) const {
2357 assert(N == 1 && "Invalid number of operands!");
2358 Inst.addOperand(MCOperand::CreateImm(unsigned(getBankedReg())));
2361 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2362 assert(N == 1 && "Invalid number of operands!");
2363 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2366 void addVecListOperands(MCInst &Inst, unsigned N) const {
2367 assert(N == 1 && "Invalid number of operands!");
2368 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2371 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2372 assert(N == 2 && "Invalid number of operands!");
2373 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2374 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2377 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2378 assert(N == 1 && "Invalid number of operands!");
2379 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2382 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2383 assert(N == 1 && "Invalid number of operands!");
2384 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2387 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2388 assert(N == 1 && "Invalid number of operands!");
2389 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2392 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2393 assert(N == 1 && "Invalid number of operands!");
2394 // The immediate encodes the type of constant as well as the value.
2395 // Mask in that this is an i8 splat.
2396 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2397 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2400 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2401 assert(N == 1 && "Invalid number of operands!");
2402 // The immediate encodes the type of constant as well as the value.
2403 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2404 unsigned Value = CE->getValue();
2406 Value = (Value >> 8) | 0xa00;
2409 Inst.addOperand(MCOperand::CreateImm(Value));
2412 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2413 assert(N == 1 && "Invalid number of operands!");
2414 // The immediate encodes the type of constant as well as the value.
2415 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2416 unsigned Value = CE->getValue();
2417 if (Value >= 256 && Value <= 0xff00)
2418 Value = (Value >> 8) | 0x200;
2419 else if (Value > 0xffff && Value <= 0xff0000)
2420 Value = (Value >> 16) | 0x400;
2421 else if (Value > 0xffffff)
2422 Value = (Value >> 24) | 0x600;
2423 Inst.addOperand(MCOperand::CreateImm(Value));
2426 void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const {
2427 assert(N == 1 && "Invalid number of operands!");
2428 // The immediate encodes the type of constant as well as the value.
2429 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2430 unsigned Value = CE->getValue();
2431 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2432 Inst.getOpcode() == ARM::VMOVv16i8) &&
2433 "All vmvn instructions that wants to replicate non-zero byte "
2434 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2435 unsigned B = ((~Value) & 0xff);
2436 B |= 0xe00; // cmode = 0b1110
2437 Inst.addOperand(MCOperand::CreateImm(B));
2439 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2440 assert(N == 1 && "Invalid number of operands!");
2441 // The immediate encodes the type of constant as well as the value.
2442 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2443 unsigned Value = CE->getValue();
2444 if (Value >= 256 && Value <= 0xffff)
2445 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2446 else if (Value > 0xffff && Value <= 0xffffff)
2447 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2448 else if (Value > 0xffffff)
2449 Value = (Value >> 24) | 0x600;
2450 Inst.addOperand(MCOperand::CreateImm(Value));
2453 void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const {
2454 assert(N == 1 && "Invalid number of operands!");
2455 // The immediate encodes the type of constant as well as the value.
2456 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2457 unsigned Value = CE->getValue();
2458 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2459 Inst.getOpcode() == ARM::VMOVv16i8) &&
2460 "All instructions that wants to replicate non-zero byte "
2461 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2462 unsigned B = Value & 0xff;
2463 B |= 0xe00; // cmode = 0b1110
2464 Inst.addOperand(MCOperand::CreateImm(B));
2466 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2467 assert(N == 1 && "Invalid number of operands!");
2468 // The immediate encodes the type of constant as well as the value.
2469 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2470 unsigned Value = ~CE->getValue();
2471 if (Value >= 256 && Value <= 0xffff)
2472 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2473 else if (Value > 0xffff && Value <= 0xffffff)
2474 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2475 else if (Value > 0xffffff)
2476 Value = (Value >> 24) | 0x600;
2477 Inst.addOperand(MCOperand::CreateImm(Value));
2480 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2481 assert(N == 1 && "Invalid number of operands!");
2482 // The immediate encodes the type of constant as well as the value.
2483 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2484 uint64_t Value = CE->getValue();
2486 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2487 Imm |= (Value & 1) << i;
2489 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2492 void print(raw_ostream &OS) const override;
2494 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) {
2495 auto Op = make_unique<ARMOperand>(k_ITCondMask);
2496 Op->ITMask.Mask = Mask;
2502 static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC,
2504 auto Op = make_unique<ARMOperand>(k_CondCode);
2511 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) {
2512 auto Op = make_unique<ARMOperand>(k_CoprocNum);
2513 Op->Cop.Val = CopVal;
2519 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) {
2520 auto Op = make_unique<ARMOperand>(k_CoprocReg);
2521 Op->Cop.Val = CopVal;
2527 static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S,
2529 auto Op = make_unique<ARMOperand>(k_CoprocOption);
2536 static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) {
2537 auto Op = make_unique<ARMOperand>(k_CCOut);
2538 Op->Reg.RegNum = RegNum;
2544 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) {
2545 auto Op = make_unique<ARMOperand>(k_Token);
2546 Op->Tok.Data = Str.data();
2547 Op->Tok.Length = Str.size();
2553 static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S,
2555 auto Op = make_unique<ARMOperand>(k_Register);
2556 Op->Reg.RegNum = RegNum;
2562 static std::unique_ptr<ARMOperand>
2563 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2564 unsigned ShiftReg, unsigned ShiftImm, SMLoc S,
2566 auto Op = make_unique<ARMOperand>(k_ShiftedRegister);
2567 Op->RegShiftedReg.ShiftTy = ShTy;
2568 Op->RegShiftedReg.SrcReg = SrcReg;
2569 Op->RegShiftedReg.ShiftReg = ShiftReg;
2570 Op->RegShiftedReg.ShiftImm = ShiftImm;
2576 static std::unique_ptr<ARMOperand>
2577 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2578 unsigned ShiftImm, SMLoc S, SMLoc E) {
2579 auto Op = make_unique<ARMOperand>(k_ShiftedImmediate);
2580 Op->RegShiftedImm.ShiftTy = ShTy;
2581 Op->RegShiftedImm.SrcReg = SrcReg;
2582 Op->RegShiftedImm.ShiftImm = ShiftImm;
2588 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm,
2590 auto Op = make_unique<ARMOperand>(k_ShifterImmediate);
2591 Op->ShifterImm.isASR = isASR;
2592 Op->ShifterImm.Imm = Imm;
2598 static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S,
2600 auto Op = make_unique<ARMOperand>(k_RotateImmediate);
2601 Op->RotImm.Imm = Imm;
2607 static std::unique_ptr<ARMOperand>
2608 CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) {
2609 auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor);
2610 Op->Bitfield.LSB = LSB;
2611 Op->Bitfield.Width = Width;
2617 static std::unique_ptr<ARMOperand>
2618 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs,
2619 SMLoc StartLoc, SMLoc EndLoc) {
2620 assert (Regs.size() > 0 && "RegList contains no registers?");
2621 KindTy Kind = k_RegisterList;
2623 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2624 Kind = k_DPRRegisterList;
2625 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2626 contains(Regs.front().second))
2627 Kind = k_SPRRegisterList;
2629 // Sort based on the register encoding values.
2630 array_pod_sort(Regs.begin(), Regs.end());
2632 auto Op = make_unique<ARMOperand>(Kind);
2633 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2634 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2635 Op->Registers.push_back(I->second);
2636 Op->StartLoc = StartLoc;
2637 Op->EndLoc = EndLoc;
2641 static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum,
2643 bool isDoubleSpaced,
2645 auto Op = make_unique<ARMOperand>(k_VectorList);
2646 Op->VectorList.RegNum = RegNum;
2647 Op->VectorList.Count = Count;
2648 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2654 static std::unique_ptr<ARMOperand>
2655 CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced,
2657 auto Op = make_unique<ARMOperand>(k_VectorListAllLanes);
2658 Op->VectorList.RegNum = RegNum;
2659 Op->VectorList.Count = Count;
2660 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2666 static std::unique_ptr<ARMOperand>
2667 CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index,
2668 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2669 auto Op = make_unique<ARMOperand>(k_VectorListIndexed);
2670 Op->VectorList.RegNum = RegNum;
2671 Op->VectorList.Count = Count;
2672 Op->VectorList.LaneIndex = Index;
2673 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2679 static std::unique_ptr<ARMOperand>
2680 CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) {
2681 auto Op = make_unique<ARMOperand>(k_VectorIndex);
2682 Op->VectorIndex.Val = Idx;
2688 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S,
2690 auto Op = make_unique<ARMOperand>(k_Immediate);
2697 static std::unique_ptr<ARMOperand>
2698 CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm,
2699 unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType,
2700 unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S,
2701 SMLoc E, SMLoc AlignmentLoc = SMLoc()) {
2702 auto Op = make_unique<ARMOperand>(k_Memory);
2703 Op->Memory.BaseRegNum = BaseRegNum;
2704 Op->Memory.OffsetImm = OffsetImm;
2705 Op->Memory.OffsetRegNum = OffsetRegNum;
2706 Op->Memory.ShiftType = ShiftType;
2707 Op->Memory.ShiftImm = ShiftImm;
2708 Op->Memory.Alignment = Alignment;
2709 Op->Memory.isNegative = isNegative;
2712 Op->AlignmentLoc = AlignmentLoc;
2716 static std::unique_ptr<ARMOperand>
2717 CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy,
2718 unsigned ShiftImm, SMLoc S, SMLoc E) {
2719 auto Op = make_unique<ARMOperand>(k_PostIndexRegister);
2720 Op->PostIdxReg.RegNum = RegNum;
2721 Op->PostIdxReg.isAdd = isAdd;
2722 Op->PostIdxReg.ShiftTy = ShiftTy;
2723 Op->PostIdxReg.ShiftImm = ShiftImm;
2729 static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt,
2731 auto Op = make_unique<ARMOperand>(k_MemBarrierOpt);
2732 Op->MBOpt.Val = Opt;
2738 static std::unique_ptr<ARMOperand>
2739 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) {
2740 auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt);
2741 Op->ISBOpt.Val = Opt;
2747 static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags,
2749 auto Op = make_unique<ARMOperand>(k_ProcIFlags);
2750 Op->IFlags.Val = IFlags;
2756 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) {
2757 auto Op = make_unique<ARMOperand>(k_MSRMask);
2758 Op->MMask.Val = MMask;
2764 static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) {
2765 auto Op = make_unique<ARMOperand>(k_BankedReg);
2766 Op->BankedReg.Val = Reg;
2773 } // end anonymous namespace.
2775 void ARMOperand::print(raw_ostream &OS) const {
2778 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2781 OS << "<ccout " << getReg() << ">";
2783 case k_ITCondMask: {
2784 static const char *const MaskStr[] = {
2785 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2786 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2788 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2789 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2793 OS << "<coprocessor number: " << getCoproc() << ">";
2796 OS << "<coprocessor register: " << getCoproc() << ">";
2798 case k_CoprocOption:
2799 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2802 OS << "<mask: " << getMSRMask() << ">";
2805 OS << "<banked reg: " << getBankedReg() << ">";
2808 getImm()->print(OS);
2810 case k_MemBarrierOpt:
2811 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2813 case k_InstSyncBarrierOpt:
2814 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2818 << " base:" << Memory.BaseRegNum;
2821 case k_PostIndexRegister:
2822 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2823 << PostIdxReg.RegNum;
2824 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2825 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2826 << PostIdxReg.ShiftImm;
2829 case k_ProcIFlags: {
2830 OS << "<ARM_PROC::";
2831 unsigned IFlags = getProcIFlags();
2832 for (int i=2; i >= 0; --i)
2833 if (IFlags & (1 << i))
2834 OS << ARM_PROC::IFlagsToString(1 << i);
2839 OS << "<register " << getReg() << ">";
2841 case k_ShifterImmediate:
2842 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2843 << " #" << ShifterImm.Imm << ">";
2845 case k_ShiftedRegister:
2846 OS << "<so_reg_reg "
2847 << RegShiftedReg.SrcReg << " "
2848 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2849 << " " << RegShiftedReg.ShiftReg << ">";
2851 case k_ShiftedImmediate:
2852 OS << "<so_reg_imm "
2853 << RegShiftedImm.SrcReg << " "
2854 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2855 << " #" << RegShiftedImm.ShiftImm << ">";
2857 case k_RotateImmediate:
2858 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2860 case k_BitfieldDescriptor:
2861 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2862 << ", width: " << Bitfield.Width << ">";
2864 case k_RegisterList:
2865 case k_DPRRegisterList:
2866 case k_SPRRegisterList: {
2867 OS << "<register_list ";
2869 const SmallVectorImpl<unsigned> &RegList = getRegList();
2870 for (SmallVectorImpl<unsigned>::const_iterator
2871 I = RegList.begin(), E = RegList.end(); I != E; ) {
2873 if (++I < E) OS << ", ";
2880 OS << "<vector_list " << VectorList.Count << " * "
2881 << VectorList.RegNum << ">";
2883 case k_VectorListAllLanes:
2884 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2885 << VectorList.RegNum << ">";
2887 case k_VectorListIndexed:
2888 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2889 << VectorList.Count << " * " << VectorList.RegNum << ">";
2892 OS << "'" << getToken() << "'";
2895 OS << "<vectorindex " << getVectorIndex() << ">";
2900 /// @name Auto-generated Match Functions
2903 static unsigned MatchRegisterName(StringRef Name);
2907 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2908 SMLoc &StartLoc, SMLoc &EndLoc) {
2909 StartLoc = Parser.getTok().getLoc();
2910 EndLoc = Parser.getTok().getEndLoc();
2911 RegNo = tryParseRegister();
2913 return (RegNo == (unsigned)-1);
2916 /// Try to parse a register name. The token must be an Identifier when called,
2917 /// and if it is a register name the token is eaten and the register number is
2918 /// returned. Otherwise return -1.
2920 int ARMAsmParser::tryParseRegister() {
2921 const AsmToken &Tok = Parser.getTok();
2922 if (Tok.isNot(AsmToken::Identifier)) return -1;
2924 std::string lowerCase = Tok.getString().lower();
2925 unsigned RegNum = MatchRegisterName(lowerCase);
2927 RegNum = StringSwitch<unsigned>(lowerCase)
2928 .Case("r13", ARM::SP)
2929 .Case("r14", ARM::LR)
2930 .Case("r15", ARM::PC)
2931 .Case("ip", ARM::R12)
2932 // Additional register name aliases for 'gas' compatibility.
2933 .Case("a1", ARM::R0)
2934 .Case("a2", ARM::R1)
2935 .Case("a3", ARM::R2)
2936 .Case("a4", ARM::R3)
2937 .Case("v1", ARM::R4)
2938 .Case("v2", ARM::R5)
2939 .Case("v3", ARM::R6)
2940 .Case("v4", ARM::R7)
2941 .Case("v5", ARM::R8)
2942 .Case("v6", ARM::R9)
2943 .Case("v7", ARM::R10)
2944 .Case("v8", ARM::R11)
2945 .Case("sb", ARM::R9)
2946 .Case("sl", ARM::R10)
2947 .Case("fp", ARM::R11)
2951 // Check for aliases registered via .req. Canonicalize to lower case.
2952 // That's more consistent since register names are case insensitive, and
2953 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2954 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2955 // If no match, return failure.
2956 if (Entry == RegisterReqs.end())
2958 Parser.Lex(); // Eat identifier token.
2959 return Entry->getValue();
2962 Parser.Lex(); // Eat identifier token.
2967 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2968 // If a recoverable error occurs, return 1. If an irrecoverable error
2969 // occurs, return -1. An irrecoverable error is one where tokens have been
2970 // consumed in the process of trying to parse the shifter (i.e., when it is
2971 // indeed a shifter operand, but malformed).
2972 int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
2973 SMLoc S = Parser.getTok().getLoc();
2974 const AsmToken &Tok = Parser.getTok();
2975 if (Tok.isNot(AsmToken::Identifier))
2978 std::string lowerCase = Tok.getString().lower();
2979 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2980 .Case("asl", ARM_AM::lsl)
2981 .Case("lsl", ARM_AM::lsl)
2982 .Case("lsr", ARM_AM::lsr)
2983 .Case("asr", ARM_AM::asr)
2984 .Case("ror", ARM_AM::ror)
2985 .Case("rrx", ARM_AM::rrx)
2986 .Default(ARM_AM::no_shift);
2988 if (ShiftTy == ARM_AM::no_shift)
2991 Parser.Lex(); // Eat the operator.
2993 // The source register for the shift has already been added to the
2994 // operand list, so we need to pop it off and combine it into the shifted
2995 // register operand instead.
2996 std::unique_ptr<ARMOperand> PrevOp(
2997 (ARMOperand *)Operands.pop_back_val().release());
2998 if (!PrevOp->isReg())
2999 return Error(PrevOp->getStartLoc(), "shift must be of a register");
3000 int SrcReg = PrevOp->getReg();
3005 if (ShiftTy == ARM_AM::rrx) {
3006 // RRX Doesn't have an explicit shift amount. The encoder expects
3007 // the shift register to be the same as the source register. Seems odd,
3011 // Figure out if this is shifted by a constant or a register (for non-RRX).
3012 if (Parser.getTok().is(AsmToken::Hash) ||
3013 Parser.getTok().is(AsmToken::Dollar)) {
3014 Parser.Lex(); // Eat hash.
3015 SMLoc ImmLoc = Parser.getTok().getLoc();
3016 const MCExpr *ShiftExpr = nullptr;
3017 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
3018 Error(ImmLoc, "invalid immediate shift value");
3021 // The expression must be evaluatable as an immediate.
3022 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
3024 Error(ImmLoc, "invalid immediate shift value");
3027 // Range check the immediate.
3028 // lsl, ror: 0 <= imm <= 31
3029 // lsr, asr: 0 <= imm <= 32
3030 Imm = CE->getValue();
3032 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
3033 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
3034 Error(ImmLoc, "immediate shift value out of range");
3037 // shift by zero is a nop. Always send it through as lsl.
3038 // ('as' compatibility)
3040 ShiftTy = ARM_AM::lsl;
3041 } else if (Parser.getTok().is(AsmToken::Identifier)) {
3042 SMLoc L = Parser.getTok().getLoc();
3043 EndLoc = Parser.getTok().getEndLoc();
3044 ShiftReg = tryParseRegister();
3045 if (ShiftReg == -1) {
3046 Error(L, "expected immediate or register in shift operand");
3050 Error(Parser.getTok().getLoc(),
3051 "expected immediate or register in shift operand");
3056 if (ShiftReg && ShiftTy != ARM_AM::rrx)
3057 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
3061 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
3068 /// Try to parse a register name. The token must be an Identifier when called.
3069 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
3070 /// if there is a "writeback". 'true' if it's not a register.
3072 /// TODO this is likely to change to allow different register types and or to
3073 /// parse for a specific register type.
3074 bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
3075 const AsmToken &RegTok = Parser.getTok();
3076 int RegNo = tryParseRegister();
3080 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3081 RegTok.getEndLoc()));
3083 const AsmToken &ExclaimTok = Parser.getTok();
3084 if (ExclaimTok.is(AsmToken::Exclaim)) {
3085 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
3086 ExclaimTok.getLoc()));
3087 Parser.Lex(); // Eat exclaim token
3091 // Also check for an index operand. This is only legal for vector registers,
3092 // but that'll get caught OK in operand matching, so we don't need to
3093 // explicitly filter everything else out here.
3094 if (Parser.getTok().is(AsmToken::LBrac)) {
3095 SMLoc SIdx = Parser.getTok().getLoc();
3096 Parser.Lex(); // Eat left bracket token.
3098 const MCExpr *ImmVal;
3099 if (getParser().parseExpression(ImmVal))
3101 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
3103 return TokError("immediate value expected for vector index");
3105 if (Parser.getTok().isNot(AsmToken::RBrac))
3106 return Error(Parser.getTok().getLoc(), "']' expected");
3108 SMLoc E = Parser.getTok().getEndLoc();
3109 Parser.Lex(); // Eat right bracket token.
3111 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
3119 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
3120 /// instruction with a symbolic operand name.
3121 /// We accept "crN" syntax for GAS compatibility.
3122 /// <operand-name> ::= <prefix><number>
3123 /// If CoprocOp is 'c', then:
3124 /// <prefix> ::= c | cr
3125 /// If CoprocOp is 'p', then :
3127 /// <number> ::= integer in range [0, 15]
3128 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
3129 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3131 if (Name.size() < 2 || Name[0] != CoprocOp)
3133 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front();
3135 switch (Name.size()) {
3156 // CP10 and CP11 are VFP/NEON and so vector instructions should be used.
3157 // However, old cores (v5/v6) did use them in that way.
3158 case '0': return 10;
3159 case '1': return 11;
3160 case '2': return 12;
3161 case '3': return 13;
3162 case '4': return 14;
3163 case '5': return 15;
3168 /// parseITCondCode - Try to parse a condition code for an IT instruction.
3169 ARMAsmParser::OperandMatchResultTy
3170 ARMAsmParser::parseITCondCode(OperandVector &Operands) {
3171 SMLoc S = Parser.getTok().getLoc();
3172 const AsmToken &Tok = Parser.getTok();
3173 if (!Tok.is(AsmToken::Identifier))
3174 return MatchOperand_NoMatch;
3175 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
3176 .Case("eq", ARMCC::EQ)
3177 .Case("ne", ARMCC::NE)
3178 .Case("hs", ARMCC::HS)
3179 .Case("cs", ARMCC::HS)
3180 .Case("lo", ARMCC::LO)
3181 .Case("cc", ARMCC::LO)
3182 .Case("mi", ARMCC::MI)
3183 .Case("pl", ARMCC::PL)
3184 .Case("vs", ARMCC::VS)
3185 .Case("vc", ARMCC::VC)
3186 .Case("hi", ARMCC::HI)
3187 .Case("ls", ARMCC::LS)
3188 .Case("ge", ARMCC::GE)
3189 .Case("lt", ARMCC::LT)
3190 .Case("gt", ARMCC::GT)
3191 .Case("le", ARMCC::LE)
3192 .Case("al", ARMCC::AL)
3195 return MatchOperand_NoMatch;
3196 Parser.Lex(); // Eat the token.
3198 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3200 return MatchOperand_Success;
3203 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
3204 /// token must be an Identifier when called, and if it is a coprocessor
3205 /// number, the token is eaten and the operand is added to the operand list.
3206 ARMAsmParser::OperandMatchResultTy
3207 ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
3208 SMLoc S = Parser.getTok().getLoc();
3209 const AsmToken &Tok = Parser.getTok();
3210 if (Tok.isNot(AsmToken::Identifier))
3211 return MatchOperand_NoMatch;
3213 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
3215 return MatchOperand_NoMatch;
3216 // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions
3217 if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11))
3218 return MatchOperand_NoMatch;
3220 Parser.Lex(); // Eat identifier token.
3221 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
3222 return MatchOperand_Success;
3225 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
3226 /// token must be an Identifier when called, and if it is a coprocessor
3227 /// number, the token is eaten and the operand is added to the operand list.
3228 ARMAsmParser::OperandMatchResultTy
3229 ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
3230 SMLoc S = Parser.getTok().getLoc();
3231 const AsmToken &Tok = Parser.getTok();
3232 if (Tok.isNot(AsmToken::Identifier))
3233 return MatchOperand_NoMatch;
3235 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3237 return MatchOperand_NoMatch;
3239 Parser.Lex(); // Eat identifier token.
3240 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
3241 return MatchOperand_Success;
3244 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3245 /// coproc_option : '{' imm0_255 '}'
3246 ARMAsmParser::OperandMatchResultTy
3247 ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
3248 SMLoc S = Parser.getTok().getLoc();
3250 // If this isn't a '{', this isn't a coprocessor immediate operand.
3251 if (Parser.getTok().isNot(AsmToken::LCurly))
3252 return MatchOperand_NoMatch;
3253 Parser.Lex(); // Eat the '{'
3256 SMLoc Loc = Parser.getTok().getLoc();
3257 if (getParser().parseExpression(Expr)) {
3258 Error(Loc, "illegal expression");
3259 return MatchOperand_ParseFail;
3261 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3262 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3263 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3264 return MatchOperand_ParseFail;
3266 int Val = CE->getValue();
3268 // Check for and consume the closing '}'
3269 if (Parser.getTok().isNot(AsmToken::RCurly))
3270 return MatchOperand_ParseFail;
3271 SMLoc E = Parser.getTok().getEndLoc();
3272 Parser.Lex(); // Eat the '}'
3274 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3275 return MatchOperand_Success;
3278 // For register list parsing, we need to map from raw GPR register numbering
3279 // to the enumeration values. The enumeration values aren't sorted by
3280 // register number due to our using "sp", "lr" and "pc" as canonical names.
3281 static unsigned getNextRegister(unsigned Reg) {
3282 // If this is a GPR, we need to do it manually, otherwise we can rely
3283 // on the sort ordering of the enumeration since the other reg-classes
3285 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3288 default: llvm_unreachable("Invalid GPR number!");
3289 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3290 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3291 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3292 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3293 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3294 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3295 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3296 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3300 // Return the low-subreg of a given Q register.
3301 static unsigned getDRegFromQReg(unsigned QReg) {
3303 default: llvm_unreachable("expected a Q register!");
3304 case ARM::Q0: return ARM::D0;
3305 case ARM::Q1: return ARM::D2;
3306 case ARM::Q2: return ARM::D4;
3307 case ARM::Q3: return ARM::D6;
3308 case ARM::Q4: return ARM::D8;
3309 case ARM::Q5: return ARM::D10;
3310 case ARM::Q6: return ARM::D12;
3311 case ARM::Q7: return ARM::D14;
3312 case ARM::Q8: return ARM::D16;
3313 case ARM::Q9: return ARM::D18;
3314 case ARM::Q10: return ARM::D20;
3315 case ARM::Q11: return ARM::D22;
3316 case ARM::Q12: return ARM::D24;
3317 case ARM::Q13: return ARM::D26;
3318 case ARM::Q14: return ARM::D28;
3319 case ARM::Q15: return ARM::D30;
3323 /// Parse a register list.
3324 bool ARMAsmParser::parseRegisterList(OperandVector &Operands) {
3325 assert(Parser.getTok().is(AsmToken::LCurly) &&
3326 "Token is not a Left Curly Brace");
3327 SMLoc S = Parser.getTok().getLoc();
3328 Parser.Lex(); // Eat '{' token.
3329 SMLoc RegLoc = Parser.getTok().getLoc();
3331 // Check the first register in the list to see what register class
3332 // this is a list of.
3333 int Reg = tryParseRegister();
3335 return Error(RegLoc, "register expected");
3337 // The reglist instructions have at most 16 registers, so reserve
3338 // space for that many.
3340 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3342 // Allow Q regs and just interpret them as the two D sub-registers.
3343 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3344 Reg = getDRegFromQReg(Reg);
3345 EReg = MRI->getEncodingValue(Reg);
3346 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3349 const MCRegisterClass *RC;
3350 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3351 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3352 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3353 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3354 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3355 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3357 return Error(RegLoc, "invalid register in register list");
3359 // Store the register.
3360 EReg = MRI->getEncodingValue(Reg);
3361 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3363 // This starts immediately after the first register token in the list,
3364 // so we can see either a comma or a minus (range separator) as a legal
3366 while (Parser.getTok().is(AsmToken::Comma) ||
3367 Parser.getTok().is(AsmToken::Minus)) {
3368 if (Parser.getTok().is(AsmToken::Minus)) {
3369 Parser.Lex(); // Eat the minus.
3370 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3371 int EndReg = tryParseRegister();
3373 return Error(AfterMinusLoc, "register expected");
3374 // Allow Q regs and just interpret them as the two D sub-registers.
3375 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3376 EndReg = getDRegFromQReg(EndReg) + 1;
3377 // If the register is the same as the start reg, there's nothing
3381 // The register must be in the same register class as the first.
3382 if (!RC->contains(EndReg))
3383 return Error(AfterMinusLoc, "invalid register in register list");
3384 // Ranges must go from low to high.
3385 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3386 return Error(AfterMinusLoc, "bad range in register list");
3388 // Add all the registers in the range to the register list.
3389 while (Reg != EndReg) {
3390 Reg = getNextRegister(Reg);
3391 EReg = MRI->getEncodingValue(Reg);
3392 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3396 Parser.Lex(); // Eat the comma.
3397 RegLoc = Parser.getTok().getLoc();
3399 const AsmToken RegTok = Parser.getTok();
3400 Reg = tryParseRegister();
3402 return Error(RegLoc, "register expected");
3403 // Allow Q regs and just interpret them as the two D sub-registers.
3404 bool isQReg = false;
3405 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3406 Reg = getDRegFromQReg(Reg);
3409 // The register must be in the same register class as the first.
3410 if (!RC->contains(Reg))
3411 return Error(RegLoc, "invalid register in register list");
3412 // List must be monotonically increasing.
3413 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3414 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3415 Warning(RegLoc, "register list not in ascending order");
3417 return Error(RegLoc, "register list not in ascending order");
3419 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3420 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3421 ") in register list");
3424 // VFP register lists must also be contiguous.
3425 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3427 return Error(RegLoc, "non-contiguous register range");
3428 EReg = MRI->getEncodingValue(Reg);
3429 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3431 EReg = MRI->getEncodingValue(++Reg);
3432 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3436 if (Parser.getTok().isNot(AsmToken::RCurly))
3437 return Error(Parser.getTok().getLoc(), "'}' expected");
3438 SMLoc E = Parser.getTok().getEndLoc();
3439 Parser.Lex(); // Eat '}' token.
3441 // Push the register list operand.
3442 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3444 // The ARM system instruction variants for LDM/STM have a '^' token here.
3445 if (Parser.getTok().is(AsmToken::Caret)) {
3446 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3447 Parser.Lex(); // Eat '^' token.
3453 // Helper function to parse the lane index for vector lists.
3454 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3455 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3456 Index = 0; // Always return a defined index value.
3457 if (Parser.getTok().is(AsmToken::LBrac)) {
3458 Parser.Lex(); // Eat the '['.
3459 if (Parser.getTok().is(AsmToken::RBrac)) {
3460 // "Dn[]" is the 'all lanes' syntax.
3461 LaneKind = AllLanes;
3462 EndLoc = Parser.getTok().getEndLoc();
3463 Parser.Lex(); // Eat the ']'.
3464 return MatchOperand_Success;
3467 // There's an optional '#' token here. Normally there wouldn't be, but
3468 // inline assemble puts one in, and it's friendly to accept that.
3469 if (Parser.getTok().is(AsmToken::Hash))
3470 Parser.Lex(); // Eat '#' or '$'.
3472 const MCExpr *LaneIndex;
3473 SMLoc Loc = Parser.getTok().getLoc();
3474 if (getParser().parseExpression(LaneIndex)) {
3475 Error(Loc, "illegal expression");
3476 return MatchOperand_ParseFail;
3478 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3480 Error(Loc, "lane index must be empty or an integer");
3481 return MatchOperand_ParseFail;
3483 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3484 Error(Parser.getTok().getLoc(), "']' expected");
3485 return MatchOperand_ParseFail;
3487 EndLoc = Parser.getTok().getEndLoc();
3488 Parser.Lex(); // Eat the ']'.
3489 int64_t Val = CE->getValue();
3491 // FIXME: Make this range check context sensitive for .8, .16, .32.
3492 if (Val < 0 || Val > 7) {
3493 Error(Parser.getTok().getLoc(), "lane index out of range");
3494 return MatchOperand_ParseFail;
3497 LaneKind = IndexedLane;
3498 return MatchOperand_Success;
3501 return MatchOperand_Success;
3504 // parse a vector register list
3505 ARMAsmParser::OperandMatchResultTy
3506 ARMAsmParser::parseVectorList(OperandVector &Operands) {
3507 VectorLaneTy LaneKind;
3509 SMLoc S = Parser.getTok().getLoc();
3510 // As an extension (to match gas), support a plain D register or Q register
3511 // (without encosing curly braces) as a single or double entry list,
3513 if (Parser.getTok().is(AsmToken::Identifier)) {
3514 SMLoc E = Parser.getTok().getEndLoc();
3515 int Reg = tryParseRegister();
3517 return MatchOperand_NoMatch;
3518 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3519 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3520 if (Res != MatchOperand_Success)
3524 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3527 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3531 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3536 return MatchOperand_Success;
3538 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3539 Reg = getDRegFromQReg(Reg);
3540 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3541 if (Res != MatchOperand_Success)
3545 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3546 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3547 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3550 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3551 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3552 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3556 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3561 return MatchOperand_Success;
3563 Error(S, "vector register expected");
3564 return MatchOperand_ParseFail;
3567 if (Parser.getTok().isNot(AsmToken::LCurly))
3568 return MatchOperand_NoMatch;
3570 Parser.Lex(); // Eat '{' token.
3571 SMLoc RegLoc = Parser.getTok().getLoc();
3573 int Reg = tryParseRegister();
3575 Error(RegLoc, "register expected");
3576 return MatchOperand_ParseFail;
3580 unsigned FirstReg = Reg;
3581 // The list is of D registers, but we also allow Q regs and just interpret
3582 // them as the two D sub-registers.
3583 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3584 FirstReg = Reg = getDRegFromQReg(Reg);
3585 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3586 // it's ambiguous with four-register single spaced.
3592 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3593 return MatchOperand_ParseFail;
3595 while (Parser.getTok().is(AsmToken::Comma) ||
3596 Parser.getTok().is(AsmToken::Minus)) {
3597 if (Parser.getTok().is(AsmToken::Minus)) {
3599 Spacing = 1; // Register range implies a single spaced list.
3600 else if (Spacing == 2) {
3601 Error(Parser.getTok().getLoc(),
3602 "sequential registers in double spaced list");
3603 return MatchOperand_ParseFail;
3605 Parser.Lex(); // Eat the minus.
3606 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3607 int EndReg = tryParseRegister();
3609 Error(AfterMinusLoc, "register expected");
3610 return MatchOperand_ParseFail;
3612 // Allow Q regs and just interpret them as the two D sub-registers.
3613 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3614 EndReg = getDRegFromQReg(EndReg) + 1;
3615 // If the register is the same as the start reg, there's nothing
3619 // The register must be in the same register class as the first.
3620 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3621 Error(AfterMinusLoc, "invalid register in register list");
3622 return MatchOperand_ParseFail;
3624 // Ranges must go from low to high.
3626 Error(AfterMinusLoc, "bad range in register list");
3627 return MatchOperand_ParseFail;
3629 // Parse the lane specifier if present.
3630 VectorLaneTy NextLaneKind;
3631 unsigned NextLaneIndex;
3632 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3633 MatchOperand_Success)
3634 return MatchOperand_ParseFail;
3635 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3636 Error(AfterMinusLoc, "mismatched lane index in register list");
3637 return MatchOperand_ParseFail;
3640 // Add all the registers in the range to the register list.
3641 Count += EndReg - Reg;
3645 Parser.Lex(); // Eat the comma.
3646 RegLoc = Parser.getTok().getLoc();
3648 Reg = tryParseRegister();
3650 Error(RegLoc, "register expected");
3651 return MatchOperand_ParseFail;
3653 // vector register lists must be contiguous.
3654 // It's OK to use the enumeration values directly here rather, as the
3655 // VFP register classes have the enum sorted properly.
3657 // The list is of D registers, but we also allow Q regs and just interpret
3658 // them as the two D sub-registers.
3659 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3661 Spacing = 1; // Register range implies a single spaced list.
3662 else if (Spacing == 2) {
3664 "invalid register in double-spaced list (must be 'D' register')");
3665 return MatchOperand_ParseFail;
3667 Reg = getDRegFromQReg(Reg);
3668 if (Reg != OldReg + 1) {
3669 Error(RegLoc, "non-contiguous register range");
3670 return MatchOperand_ParseFail;
3674 // Parse the lane specifier if present.
3675 VectorLaneTy NextLaneKind;
3676 unsigned NextLaneIndex;
3677 SMLoc LaneLoc = Parser.getTok().getLoc();
3678 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3679 MatchOperand_Success)
3680 return MatchOperand_ParseFail;
3681 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3682 Error(LaneLoc, "mismatched lane index in register list");
3683 return MatchOperand_ParseFail;
3687 // Normal D register.
3688 // Figure out the register spacing (single or double) of the list if
3689 // we don't know it already.
3691 Spacing = 1 + (Reg == OldReg + 2);
3693 // Just check that it's contiguous and keep going.
3694 if (Reg != OldReg + Spacing) {
3695 Error(RegLoc, "non-contiguous register range");
3696 return MatchOperand_ParseFail;
3699 // Parse the lane specifier if present.
3700 VectorLaneTy NextLaneKind;
3701 unsigned NextLaneIndex;
3702 SMLoc EndLoc = Parser.getTok().getLoc();
3703 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3704 return MatchOperand_ParseFail;
3705 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3706 Error(EndLoc, "mismatched lane index in register list");
3707 return MatchOperand_ParseFail;
3711 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3712 Error(Parser.getTok().getLoc(), "'}' expected");
3713 return MatchOperand_ParseFail;
3715 E = Parser.getTok().getEndLoc();
3716 Parser.Lex(); // Eat '}' token.
3720 // Two-register operands have been converted to the
3721 // composite register classes.
3723 const MCRegisterClass *RC = (Spacing == 1) ?
3724 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3725 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3726 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3729 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3730 (Spacing == 2), S, E));
3733 // Two-register operands have been converted to the
3734 // composite register classes.
3736 const MCRegisterClass *RC = (Spacing == 1) ?
3737 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3738 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3739 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3741 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3746 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3752 return MatchOperand_Success;
3755 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3756 ARMAsmParser::OperandMatchResultTy
3757 ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
3758 SMLoc S = Parser.getTok().getLoc();
3759 const AsmToken &Tok = Parser.getTok();
3762 if (Tok.is(AsmToken::Identifier)) {
3763 StringRef OptStr = Tok.getString();
3765 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3766 .Case("sy", ARM_MB::SY)
3767 .Case("st", ARM_MB::ST)
3768 .Case("ld", ARM_MB::LD)
3769 .Case("sh", ARM_MB::ISH)
3770 .Case("ish", ARM_MB::ISH)
3771 .Case("shst", ARM_MB::ISHST)
3772 .Case("ishst", ARM_MB::ISHST)
3773 .Case("ishld", ARM_MB::ISHLD)
3774 .Case("nsh", ARM_MB::NSH)
3775 .Case("un", ARM_MB::NSH)
3776 .Case("nshst", ARM_MB::NSHST)
3777 .Case("nshld", ARM_MB::NSHLD)
3778 .Case("unst", ARM_MB::NSHST)
3779 .Case("osh", ARM_MB::OSH)
3780 .Case("oshst", ARM_MB::OSHST)
3781 .Case("oshld", ARM_MB::OSHLD)
3784 // ishld, oshld, nshld and ld are only available from ARMv8.
3785 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3786 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3790 return MatchOperand_NoMatch;
3792 Parser.Lex(); // Eat identifier token.
3793 } else if (Tok.is(AsmToken::Hash) ||
3794 Tok.is(AsmToken::Dollar) ||
3795 Tok.is(AsmToken::Integer)) {
3796 if (Parser.getTok().isNot(AsmToken::Integer))
3797 Parser.Lex(); // Eat '#' or '$'.
3798 SMLoc Loc = Parser.getTok().getLoc();
3800 const MCExpr *MemBarrierID;
3801 if (getParser().parseExpression(MemBarrierID)) {
3802 Error(Loc, "illegal expression");
3803 return MatchOperand_ParseFail;
3806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3808 Error(Loc, "constant expression expected");
3809 return MatchOperand_ParseFail;
3812 int Val = CE->getValue();
3814 Error(Loc, "immediate value out of range");
3815 return MatchOperand_ParseFail;
3818 Opt = ARM_MB::RESERVED_0 + Val;
3820 return MatchOperand_ParseFail;
3822 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3823 return MatchOperand_Success;
3826 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3827 ARMAsmParser::OperandMatchResultTy
3828 ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
3829 SMLoc S = Parser.getTok().getLoc();
3830 const AsmToken &Tok = Parser.getTok();
3833 if (Tok.is(AsmToken::Identifier)) {
3834 StringRef OptStr = Tok.getString();
3836 if (OptStr.equals_lower("sy"))
3839 return MatchOperand_NoMatch;
3841 Parser.Lex(); // Eat identifier token.
3842 } else if (Tok.is(AsmToken::Hash) ||
3843 Tok.is(AsmToken::Dollar) ||
3844 Tok.is(AsmToken::Integer)) {
3845 if (Parser.getTok().isNot(AsmToken::Integer))
3846 Parser.Lex(); // Eat '#' or '$'.
3847 SMLoc Loc = Parser.getTok().getLoc();
3849 const MCExpr *ISBarrierID;
3850 if (getParser().parseExpression(ISBarrierID)) {
3851 Error(Loc, "illegal expression");
3852 return MatchOperand_ParseFail;
3855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3857 Error(Loc, "constant expression expected");
3858 return MatchOperand_ParseFail;
3861 int Val = CE->getValue();
3863 Error(Loc, "immediate value out of range");
3864 return MatchOperand_ParseFail;
3867 Opt = ARM_ISB::RESERVED_0 + Val;
3869 return MatchOperand_ParseFail;
3871 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3872 (ARM_ISB::InstSyncBOpt)Opt, S));
3873 return MatchOperand_Success;
3877 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3878 ARMAsmParser::OperandMatchResultTy
3879 ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
3880 SMLoc S = Parser.getTok().getLoc();
3881 const AsmToken &Tok = Parser.getTok();
3882 if (!Tok.is(AsmToken::Identifier))
3883 return MatchOperand_NoMatch;
3884 StringRef IFlagsStr = Tok.getString();
3886 // An iflags string of "none" is interpreted to mean that none of the AIF
3887 // bits are set. Not a terribly useful instruction, but a valid encoding.
3888 unsigned IFlags = 0;
3889 if (IFlagsStr != "none") {
3890 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3891 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3892 .Case("a", ARM_PROC::A)
3893 .Case("i", ARM_PROC::I)
3894 .Case("f", ARM_PROC::F)
3897 // If some specific iflag is already set, it means that some letter is
3898 // present more than once, this is not acceptable.
3899 if (Flag == ~0U || (IFlags & Flag))
3900 return MatchOperand_NoMatch;
3906 Parser.Lex(); // Eat identifier token.
3907 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3908 return MatchOperand_Success;
3911 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3912 ARMAsmParser::OperandMatchResultTy
3913 ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
3914 SMLoc S = Parser.getTok().getLoc();
3915 const AsmToken &Tok = Parser.getTok();
3916 if (!Tok.is(AsmToken::Identifier))
3917 return MatchOperand_NoMatch;
3918 StringRef Mask = Tok.getString();
3921 // See ARMv6-M 10.1.1
3922 std::string Name = Mask.lower();
3923 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3924 // Note: in the documentation:
3925 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3926 // for MSR APSR_nzcvq.
3927 // but we do make it an alias here. This is so to get the "mask encoding"
3928 // bits correct on MSR APSR writes.
3930 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3931 // should really only be allowed when writing a special register. Note
3932 // they get dropped in the MRS instruction reading a special register as
3933 // the SYSm field is only 8 bits.
3934 .Case("apsr", 0x800)
3935 .Case("apsr_nzcvq", 0x800)
3936 .Case("apsr_g", 0x400)
3937 .Case("apsr_nzcvqg", 0xc00)
3938 .Case("iapsr", 0x801)
3939 .Case("iapsr_nzcvq", 0x801)
3940 .Case("iapsr_g", 0x401)
3941 .Case("iapsr_nzcvqg", 0xc01)
3942 .Case("eapsr", 0x802)
3943 .Case("eapsr_nzcvq", 0x802)
3944 .Case("eapsr_g", 0x402)
3945 .Case("eapsr_nzcvqg", 0xc02)
3946 .Case("xpsr", 0x803)
3947 .Case("xpsr_nzcvq", 0x803)
3948 .Case("xpsr_g", 0x403)
3949 .Case("xpsr_nzcvqg", 0xc03)
3950 .Case("ipsr", 0x805)
3951 .Case("epsr", 0x806)
3952 .Case("iepsr", 0x807)
3955 .Case("primask", 0x810)
3956 .Case("basepri", 0x811)
3957 .Case("basepri_max", 0x812)
3958 .Case("faultmask", 0x813)
3959 .Case("control", 0x814)
3962 if (FlagsVal == ~0U)
3963 return MatchOperand_NoMatch;
3965 if (!hasThumb2DSP() && (FlagsVal & 0x400))
3966 // The _g and _nzcvqg versions are only valid if the DSP extension is
3968 return MatchOperand_NoMatch;
3970 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3971 // basepri, basepri_max and faultmask only valid for V7m.
3972 return MatchOperand_NoMatch;
3974 Parser.Lex(); // Eat identifier token.
3975 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3976 return MatchOperand_Success;
3979 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3980 size_t Start = 0, Next = Mask.find('_');
3981 StringRef Flags = "";
3982 std::string SpecReg = Mask.slice(Start, Next).lower();
3983 if (Next != StringRef::npos)
3984 Flags = Mask.slice(Next+1, Mask.size());
3986 // FlagsVal contains the complete mask:
3988 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3989 unsigned FlagsVal = 0;
3991 if (SpecReg == "apsr") {
3992 FlagsVal = StringSwitch<unsigned>(Flags)
3993 .Case("nzcvq", 0x8) // same as CPSR_f
3994 .Case("g", 0x4) // same as CPSR_s
3995 .Case("nzcvqg", 0xc) // same as CPSR_fs
3998 if (FlagsVal == ~0U) {
4000 return MatchOperand_NoMatch;
4002 FlagsVal = 8; // No flag
4004 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
4005 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
4006 if (Flags == "all" || Flags == "")
4008 for (int i = 0, e = Flags.size(); i != e; ++i) {
4009 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
4016 // If some specific flag is already set, it means that some letter is
4017 // present more than once, this is not acceptable.
4018 if (FlagsVal == ~0U || (FlagsVal & Flag))
4019 return MatchOperand_NoMatch;
4022 } else // No match for special register.
4023 return MatchOperand_NoMatch;
4025 // Special register without flags is NOT equivalent to "fc" flags.
4026 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
4027 // two lines would enable gas compatibility at the expense of breaking
4033 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4034 if (SpecReg == "spsr")
4037 Parser.Lex(); // Eat identifier token.
4038 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4039 return MatchOperand_Success;
4042 /// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for
4043 /// use in the MRS/MSR instructions added to support virtualization.
4044 ARMAsmParser::OperandMatchResultTy
4045 ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) {
4046 SMLoc S = Parser.getTok().getLoc();
4047 const AsmToken &Tok = Parser.getTok();
4048 if (!Tok.is(AsmToken::Identifier))
4049 return MatchOperand_NoMatch;
4050 StringRef RegName = Tok.getString();
4052 // The values here come from B9.2.3 of the ARM ARM, where bits 4-0 are SysM
4054 unsigned Encoding = StringSwitch<unsigned>(RegName.lower())
4055 .Case("r8_usr", 0x00)
4056 .Case("r9_usr", 0x01)
4057 .Case("r10_usr", 0x02)
4058 .Case("r11_usr", 0x03)
4059 .Case("r12_usr", 0x04)
4060 .Case("sp_usr", 0x05)
4061 .Case("lr_usr", 0x06)
4062 .Case("r8_fiq", 0x08)
4063 .Case("r9_fiq", 0x09)
4064 .Case("r10_fiq", 0x0a)
4065 .Case("r11_fiq", 0x0b)
4066 .Case("r12_fiq", 0x0c)
4067 .Case("sp_fiq", 0x0d)
4068 .Case("lr_fiq", 0x0e)
4069 .Case("lr_irq", 0x10)
4070 .Case("sp_irq", 0x11)
4071 .Case("lr_svc", 0x12)
4072 .Case("sp_svc", 0x13)
4073 .Case("lr_abt", 0x14)
4074 .Case("sp_abt", 0x15)
4075 .Case("lr_und", 0x16)
4076 .Case("sp_und", 0x17)
4077 .Case("lr_mon", 0x1c)
4078 .Case("sp_mon", 0x1d)
4079 .Case("elr_hyp", 0x1e)
4080 .Case("sp_hyp", 0x1f)
4081 .Case("spsr_fiq", 0x2e)
4082 .Case("spsr_irq", 0x30)
4083 .Case("spsr_svc", 0x32)
4084 .Case("spsr_abt", 0x34)
4085 .Case("spsr_und", 0x36)
4086 .Case("spsr_mon", 0x3c)
4087 .Case("spsr_hyp", 0x3e)
4090 if (Encoding == ~0U)
4091 return MatchOperand_NoMatch;
4093 Parser.Lex(); // Eat identifier token.
4094 Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S));
4095 return MatchOperand_Success;
4098 ARMAsmParser::OperandMatchResultTy
4099 ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low,
4101 const AsmToken &Tok = Parser.getTok();
4102 if (Tok.isNot(AsmToken::Identifier)) {
4103 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4104 return MatchOperand_ParseFail;
4106 StringRef ShiftName = Tok.getString();
4107 std::string LowerOp = Op.lower();
4108 std::string UpperOp = Op.upper();
4109 if (ShiftName != LowerOp && ShiftName != UpperOp) {
4110 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4111 return MatchOperand_ParseFail;
4113 Parser.Lex(); // Eat shift type token.
4115 // There must be a '#' and a shift amount.
4116 if (Parser.getTok().isNot(AsmToken::Hash) &&
4117 Parser.getTok().isNot(AsmToken::Dollar)) {
4118 Error(Parser.getTok().getLoc(), "'#' expected");
4119 return MatchOperand_ParseFail;
4121 Parser.Lex(); // Eat hash token.
4123 const MCExpr *ShiftAmount;
4124 SMLoc Loc = Parser.getTok().getLoc();
4126 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
4127 Error(Loc, "illegal expression");
4128 return MatchOperand_ParseFail;
4130 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4132 Error(Loc, "constant expression expected");
4133 return MatchOperand_ParseFail;
4135 int Val = CE->getValue();
4136 if (Val < Low || Val > High) {
4137 Error(Loc, "immediate value out of range");
4138 return MatchOperand_ParseFail;
4141 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
4143 return MatchOperand_Success;
4146 ARMAsmParser::OperandMatchResultTy
4147 ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
4148 const AsmToken &Tok = Parser.getTok();
4149 SMLoc S = Tok.getLoc();
4150 if (Tok.isNot(AsmToken::Identifier)) {
4151 Error(S, "'be' or 'le' operand expected");
4152 return MatchOperand_ParseFail;
4154 int Val = StringSwitch<int>(Tok.getString().lower())
4158 Parser.Lex(); // Eat the token.
4161 Error(S, "'be' or 'le' operand expected");
4162 return MatchOperand_ParseFail;
4164 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4166 S, Tok.getEndLoc()));
4167 return MatchOperand_Success;
4170 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4171 /// instructions. Legal values are:
4172 /// lsl #n 'n' in [0,31]
4173 /// asr #n 'n' in [1,32]
4174 /// n == 32 encoded as n == 0.
4175 ARMAsmParser::OperandMatchResultTy
4176 ARMAsmParser::parseShifterImm(OperandVector &Operands) {
4177 const AsmToken &Tok = Parser.getTok();
4178 SMLoc S = Tok.getLoc();
4179 if (Tok.isNot(AsmToken::Identifier)) {
4180 Error(S, "shift operator 'asr' or 'lsl' expected");
4181 return MatchOperand_ParseFail;
4183 StringRef ShiftName = Tok.getString();
4185 if (ShiftName == "lsl" || ShiftName == "LSL")
4187 else if (ShiftName == "asr" || ShiftName == "ASR")
4190 Error(S, "shift operator 'asr' or 'lsl' expected");
4191 return MatchOperand_ParseFail;
4193 Parser.Lex(); // Eat the operator.
4195 // A '#' and a shift amount.
4196 if (Parser.getTok().isNot(AsmToken::Hash) &&
4197 Parser.getTok().isNot(AsmToken::Dollar)) {
4198 Error(Parser.getTok().getLoc(), "'#' expected");
4199 return MatchOperand_ParseFail;
4201 Parser.Lex(); // Eat hash token.
4202 SMLoc ExLoc = Parser.getTok().getLoc();
4204 const MCExpr *ShiftAmount;
4206 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
4207 Error(ExLoc, "malformed shift expression");
4208 return MatchOperand_ParseFail;
4210 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4212 Error(ExLoc, "shift amount must be an immediate");
4213 return MatchOperand_ParseFail;
4216 int64_t Val = CE->getValue();
4218 // Shift amount must be in [1,32]
4219 if (Val < 1 || Val > 32) {
4220 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
4221 return MatchOperand_ParseFail;
4223 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4224 if (isThumb() && Val == 32) {
4225 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
4226 return MatchOperand_ParseFail;
4228 if (Val == 32) Val = 0;
4230 // Shift amount must be in [1,32]
4231 if (Val < 0 || Val > 31) {
4232 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
4233 return MatchOperand_ParseFail;
4237 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
4239 return MatchOperand_Success;
4242 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4243 /// of instructions. Legal values are:
4244 /// ror #n 'n' in {0, 8, 16, 24}
4245 ARMAsmParser::OperandMatchResultTy
4246 ARMAsmParser::parseRotImm(OperandVector &Operands) {
4247 const AsmToken &Tok = Parser.getTok();
4248 SMLoc S = Tok.getLoc();
4249 if (Tok.isNot(AsmToken::Identifier))
4250 return MatchOperand_NoMatch;
4251 StringRef ShiftName = Tok.getString();
4252 if (ShiftName != "ror" && ShiftName != "ROR")
4253 return MatchOperand_NoMatch;
4254 Parser.Lex(); // Eat the operator.
4256 // A '#' and a rotate amount.
4257 if (Parser.getTok().isNot(AsmToken::Hash) &&
4258 Parser.getTok().isNot(AsmToken::Dollar)) {
4259 Error(Parser.getTok().getLoc(), "'#' expected");
4260 return MatchOperand_ParseFail;
4262 Parser.Lex(); // Eat hash token.
4263 SMLoc ExLoc = Parser.getTok().getLoc();
4265 const MCExpr *ShiftAmount;
4267 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
4268 Error(ExLoc, "malformed rotate expression");
4269 return MatchOperand_ParseFail;
4271 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4273 Error(ExLoc, "rotate amount must be an immediate");
4274 return MatchOperand_ParseFail;
4277 int64_t Val = CE->getValue();
4278 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4279 // normally, zero is represented in asm by omitting the rotate operand
4281 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
4282 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
4283 return MatchOperand_ParseFail;
4286 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
4288 return MatchOperand_Success;
4291 ARMAsmParser::OperandMatchResultTy
4292 ARMAsmParser::parseBitfield(OperandVector &Operands) {
4293 SMLoc S = Parser.getTok().getLoc();
4294 // The bitfield descriptor is really two operands, the LSB and the width.
4295 if (Parser.getTok().isNot(AsmToken::Hash) &&
4296 Parser.getTok().isNot(AsmToken::Dollar)) {
4297 Error(Parser.getTok().getLoc(), "'#' expected");
4298 return MatchOperand_ParseFail;
4300 Parser.Lex(); // Eat hash token.
4302 const MCExpr *LSBExpr;
4303 SMLoc E = Parser.getTok().getLoc();
4304 if (getParser().parseExpression(LSBExpr)) {
4305 Error(E, "malformed immediate expression");
4306 return MatchOperand_ParseFail;
4308 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4310 Error(E, "'lsb' operand must be an immediate");
4311 return MatchOperand_ParseFail;
4314 int64_t LSB = CE->getValue();
4315 // The LSB must be in the range [0,31]
4316 if (LSB < 0 || LSB > 31) {
4317 Error(E, "'lsb' operand must be in the range [0,31]");
4318 return MatchOperand_ParseFail;
4320 E = Parser.getTok().getLoc();
4322 // Expect another immediate operand.
4323 if (Parser.getTok().isNot(AsmToken::Comma)) {
4324 Error(Parser.getTok().getLoc(), "too few operands");
4325 return MatchOperand_ParseFail;
4327 Parser.Lex(); // Eat hash token.
4328 if (Parser.getTok().isNot(AsmToken::Hash) &&
4329 Parser.getTok().isNot(AsmToken::Dollar)) {
4330 Error(Parser.getTok().getLoc(), "'#' expected");
4331 return MatchOperand_ParseFail;
4333 Parser.Lex(); // Eat hash token.
4335 const MCExpr *WidthExpr;
4337 if (getParser().parseExpression(WidthExpr, EndLoc)) {
4338 Error(E, "malformed immediate expression");
4339 return MatchOperand_ParseFail;
4341 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4343 Error(E, "'width' operand must be an immediate");
4344 return MatchOperand_ParseFail;
4347 int64_t Width = CE->getValue();
4348 // The LSB must be in the range [1,32-lsb]
4349 if (Width < 1 || Width > 32 - LSB) {
4350 Error(E, "'width' operand must be in the range [1,32-lsb]");
4351 return MatchOperand_ParseFail;
4354 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
4356 return MatchOperand_Success;
4359 ARMAsmParser::OperandMatchResultTy
4360 ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
4361 // Check for a post-index addressing register operand. Specifically:
4362 // postidx_reg := '+' register {, shift}
4363 // | '-' register {, shift}
4364 // | register {, shift}
4366 // This method must return MatchOperand_NoMatch without consuming any tokens
4367 // in the case where there is no match, as other alternatives take other
4369 AsmToken Tok = Parser.getTok();
4370 SMLoc S = Tok.getLoc();
4371 bool haveEaten = false;
4373 if (Tok.is(AsmToken::Plus)) {
4374 Parser.Lex(); // Eat the '+' token.
4376 } else if (Tok.is(AsmToken::Minus)) {
4377 Parser.Lex(); // Eat the '-' token.
4382 SMLoc E = Parser.getTok().getEndLoc();
4383 int Reg = tryParseRegister();
4386 return MatchOperand_NoMatch;
4387 Error(Parser.getTok().getLoc(), "register expected");
4388 return MatchOperand_ParseFail;
4391 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4392 unsigned ShiftImm = 0;
4393 if (Parser.getTok().is(AsmToken::Comma)) {
4394 Parser.Lex(); // Eat the ','.
4395 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4396 return MatchOperand_ParseFail;
4398 // FIXME: Only approximates end...may include intervening whitespace.
4399 E = Parser.getTok().getLoc();
4402 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4405 return MatchOperand_Success;
4408 ARMAsmParser::OperandMatchResultTy
4409 ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
4410 // Check for a post-index addressing register operand. Specifically:
4411 // am3offset := '+' register
4418 // This method must return MatchOperand_NoMatch without consuming any tokens
4419 // in the case where there is no match, as other alternatives take other
4421 AsmToken Tok = Parser.getTok();
4422 SMLoc S = Tok.getLoc();
4424 // Do immediates first, as we always parse those if we have a '#'.
4425 if (Parser.getTok().is(AsmToken::Hash) ||
4426 Parser.getTok().is(AsmToken::Dollar)) {
4427 Parser.Lex(); // Eat '#' or '$'.
4428 // Explicitly look for a '-', as we need to encode negative zero
4430 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4431 const MCExpr *Offset;
4433 if (getParser().parseExpression(Offset, E))
4434 return MatchOperand_ParseFail;
4435 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4437 Error(S, "constant expression expected");
4438 return MatchOperand_ParseFail;
4440 // Negative zero is encoded as the flag value INT32_MIN.
4441 int32_t Val = CE->getValue();
4442 if (isNegative && Val == 0)
4446 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4448 return MatchOperand_Success;
4452 bool haveEaten = false;
4454 if (Tok.is(AsmToken::Plus)) {
4455 Parser.Lex(); // Eat the '+' token.
4457 } else if (Tok.is(AsmToken::Minus)) {
4458 Parser.Lex(); // Eat the '-' token.
4463 Tok = Parser.getTok();
4464 int Reg = tryParseRegister();
4467 return MatchOperand_NoMatch;
4468 Error(Tok.getLoc(), "register expected");
4469 return MatchOperand_ParseFail;
4472 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4473 0, S, Tok.getEndLoc()));
4475 return MatchOperand_Success;
4478 /// Convert parsed operands to MCInst. Needed here because this instruction
4479 /// only has two register operands, but multiplication is commutative so
4480 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4481 void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
4482 const OperandVector &Operands) {
4483 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
4484 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
4485 // If we have a three-operand form, make sure to set Rn to be the operand
4486 // that isn't the same as Rd.
4488 if (Operands.size() == 6 &&
4489 ((ARMOperand &)*Operands[4]).getReg() ==
4490 ((ARMOperand &)*Operands[3]).getReg())
4492 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
4493 Inst.addOperand(Inst.getOperand(0));
4494 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
4497 void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
4498 const OperandVector &Operands) {
4499 int CondOp = -1, ImmOp = -1;
4500 switch(Inst.getOpcode()) {
4502 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4505 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4507 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4509 // first decide whether or not the branch should be conditional
4510 // by looking at it's location relative to an IT block
4512 // inside an IT block we cannot have any conditional branches. any
4513 // such instructions needs to be converted to unconditional form
4514 switch(Inst.getOpcode()) {
4515 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4516 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4519 // outside IT blocks we can only have unconditional branches with AL
4520 // condition code or conditional branches with non-AL condition code
4521 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
4522 switch(Inst.getOpcode()) {
4525 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4529 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4534 // now decide on encoding size based on branch target range
4535 switch(Inst.getOpcode()) {
4536 // classify tB as either t2B or t1B based on range of immediate operand
4538 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4539 if (!op.isSignedOffset<11, 1>() && isThumbTwo())
4540 Inst.setOpcode(ARM::t2B);
4543 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4545 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4546 if (!op.isSignedOffset<8, 1>() && isThumbTwo())
4547 Inst.setOpcode(ARM::t2Bcc);
4551 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
4552 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
4555 /// Parse an ARM memory expression, return false if successful else return true
4556 /// or an error. The first token must be a '[' when called.
4557 bool ARMAsmParser::parseMemory(OperandVector &Operands) {
4559 assert(Parser.getTok().is(AsmToken::LBrac) &&
4560 "Token is not a Left Bracket");
4561 S = Parser.getTok().getLoc();
4562 Parser.Lex(); // Eat left bracket token.
4564 const AsmToken &BaseRegTok = Parser.getTok();
4565 int BaseRegNum = tryParseRegister();
4566 if (BaseRegNum == -1)
4567 return Error(BaseRegTok.getLoc(), "register expected");
4569 // The next token must either be a comma, a colon or a closing bracket.
4570 const AsmToken &Tok = Parser.getTok();
4571 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4572 !Tok.is(AsmToken::RBrac))
4573 return Error(Tok.getLoc(), "malformed memory operand");
4575 if (Tok.is(AsmToken::RBrac)) {
4576 E = Tok.getEndLoc();
4577 Parser.Lex(); // Eat right bracket token.
4579 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4580 ARM_AM::no_shift, 0, 0, false,
4583 // If there's a pre-indexing writeback marker, '!', just add it as a token
4584 // operand. It's rather odd, but syntactically valid.
4585 if (Parser.getTok().is(AsmToken::Exclaim)) {
4586 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4587 Parser.Lex(); // Eat the '!'.
4593 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4594 "Lost colon or comma in memory operand?!");
4595 if (Tok.is(AsmToken::Comma)) {
4596 Parser.Lex(); // Eat the comma.
4599 // If we have a ':', it's an alignment specifier.
4600 if (Parser.getTok().is(AsmToken::Colon)) {
4601 Parser.Lex(); // Eat the ':'.
4602 E = Parser.getTok().getLoc();
4603 SMLoc AlignmentLoc = Tok.getLoc();
4606 if (getParser().parseExpression(Expr))
4609 // The expression has to be a constant. Memory references with relocations
4610 // don't come through here, as they use the <label> forms of the relevant
4612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4614 return Error (E, "constant expression expected");
4617 switch (CE->getValue()) {
4620 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4621 case 16: Align = 2; break;
4622 case 32: Align = 4; break;
4623 case 64: Align = 8; break;
4624 case 128: Align = 16; break;
4625 case 256: Align = 32; break;
4628 // Now we should have the closing ']'
4629 if (Parser.getTok().isNot(AsmToken::RBrac))
4630 return Error(Parser.getTok().getLoc(), "']' expected");
4631 E = Parser.getTok().getEndLoc();
4632 Parser.Lex(); // Eat right bracket token.
4634 // Don't worry about range checking the value here. That's handled by
4635 // the is*() predicates.
4636 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4637 ARM_AM::no_shift, 0, Align,
4638 false, S, E, AlignmentLoc));
4640 // If there's a pre-indexing writeback marker, '!', just add it as a token
4642 if (Parser.getTok().is(AsmToken::Exclaim)) {
4643 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4644 Parser.Lex(); // Eat the '!'.
4650 // If we have a '#', it's an immediate offset, else assume it's a register
4651 // offset. Be friendly and also accept a plain integer (without a leading
4652 // hash) for gas compatibility.
4653 if (Parser.getTok().is(AsmToken::Hash) ||
4654 Parser.getTok().is(AsmToken::Dollar) ||
4655 Parser.getTok().is(AsmToken::Integer)) {
4656 if (Parser.getTok().isNot(AsmToken::Integer))
4657 Parser.Lex(); // Eat '#' or '$'.
4658 E = Parser.getTok().getLoc();
4660 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4661 const MCExpr *Offset;
4662 if (getParser().parseExpression(Offset))
4665 // The expression has to be a constant. Memory references with relocations
4666 // don't come through here, as they use the <label> forms of the relevant
4668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4670 return Error (E, "constant expression expected");
4672 // If the constant was #-0, represent it as INT32_MIN.
4673 int32_t Val = CE->getValue();
4674 if (isNegative && Val == 0)
4675 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4677 // Now we should have the closing ']'
4678 if (Parser.getTok().isNot(AsmToken::RBrac))
4679 return Error(Parser.getTok().getLoc(), "']' expected");
4680 E = Parser.getTok().getEndLoc();
4681 Parser.Lex(); // Eat right bracket token.
4683 // Don't worry about range checking the value here. That's handled by
4684 // the is*() predicates.
4685 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4686 ARM_AM::no_shift, 0, 0,
4689 // If there's a pre-indexing writeback marker, '!', just add it as a token
4691 if (Parser.getTok().is(AsmToken::Exclaim)) {
4692 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4693 Parser.Lex(); // Eat the '!'.
4699 // The register offset is optionally preceded by a '+' or '-'
4700 bool isNegative = false;
4701 if (Parser.getTok().is(AsmToken::Minus)) {
4703 Parser.Lex(); // Eat the '-'.
4704 } else if (Parser.getTok().is(AsmToken::Plus)) {
4706 Parser.Lex(); // Eat the '+'.
4709 E = Parser.getTok().getLoc();
4710 int OffsetRegNum = tryParseRegister();
4711 if (OffsetRegNum == -1)
4712 return Error(E, "register expected");
4714 // If there's a shift operator, handle it.
4715 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4716 unsigned ShiftImm = 0;
4717 if (Parser.getTok().is(AsmToken::Comma)) {
4718 Parser.Lex(); // Eat the ','.
4719 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4723 // Now we should have the closing ']'
4724 if (Parser.getTok().isNot(AsmToken::RBrac))
4725 return Error(Parser.getTok().getLoc(), "']' expected");
4726 E = Parser.getTok().getEndLoc();
4727 Parser.Lex(); // Eat right bracket token.
4729 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
4730 ShiftType, ShiftImm, 0, isNegative,
4733 // If there's a pre-indexing writeback marker, '!', just add it as a token
4735 if (Parser.getTok().is(AsmToken::Exclaim)) {
4736 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4737 Parser.Lex(); // Eat the '!'.
4743 /// parseMemRegOffsetShift - one of these two:
4744 /// ( lsl | lsr | asr | ror ) , # shift_amount
4746 /// return true if it parses a shift otherwise it returns false.
4747 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4749 SMLoc Loc = Parser.getTok().getLoc();
4750 const AsmToken &Tok = Parser.getTok();
4751 if (Tok.isNot(AsmToken::Identifier))
4753 StringRef ShiftName = Tok.getString();
4754 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4755 ShiftName == "asl" || ShiftName == "ASL")
4757 else if (ShiftName == "lsr" || ShiftName == "LSR")
4759 else if (ShiftName == "asr" || ShiftName == "ASR")
4761 else if (ShiftName == "ror" || ShiftName == "ROR")
4763 else if (ShiftName == "rrx" || ShiftName == "RRX")
4766 return Error(Loc, "illegal shift operator");
4767 Parser.Lex(); // Eat shift type token.
4769 // rrx stands alone.
4771 if (St != ARM_AM::rrx) {
4772 Loc = Parser.getTok().getLoc();
4773 // A '#' and a shift amount.
4774 const AsmToken &HashTok = Parser.getTok();
4775 if (HashTok.isNot(AsmToken::Hash) &&
4776 HashTok.isNot(AsmToken::Dollar))
4777 return Error(HashTok.getLoc(), "'#' expected");
4778 Parser.Lex(); // Eat hash token.
4781 if (getParser().parseExpression(Expr))
4783 // Range check the immediate.
4784 // lsl, ror: 0 <= imm <= 31
4785 // lsr, asr: 0 <= imm <= 32
4786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4788 return Error(Loc, "shift amount must be an immediate");
4789 int64_t Imm = CE->getValue();
4791 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4792 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4793 return Error(Loc, "immediate shift value out of range");
4794 // If <ShiftTy> #0, turn it into a no_shift.
4797 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4806 /// parseFPImm - A floating point immediate expression operand.
4807 ARMAsmParser::OperandMatchResultTy
4808 ARMAsmParser::parseFPImm(OperandVector &Operands) {
4809 // Anything that can accept a floating point constant as an operand
4810 // needs to go through here, as the regular parseExpression is
4813 // This routine still creates a generic Immediate operand, containing
4814 // a bitcast of the 64-bit floating point value. The various operands
4815 // that accept floats can check whether the value is valid for them
4816 // via the standard is*() predicates.
4818 SMLoc S = Parser.getTok().getLoc();
4820 if (Parser.getTok().isNot(AsmToken::Hash) &&
4821 Parser.getTok().isNot(AsmToken::Dollar))
4822 return MatchOperand_NoMatch;
4824 // Disambiguate the VMOV forms that can accept an FP immediate.
4825 // vmov.f32 <sreg>, #imm
4826 // vmov.f64 <dreg>, #imm
4827 // vmov.f32 <dreg>, #imm @ vector f32x2
4828 // vmov.f32 <qreg>, #imm @ vector f32x4
4830 // There are also the NEON VMOV instructions which expect an
4831 // integer constant. Make sure we don't try to parse an FPImm
4833 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4834 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
4835 bool isVmovf = TyOp.isToken() &&
4836 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64");
4837 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
4838 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
4839 Mnemonic.getToken() == "fconsts");
4840 if (!(isVmovf || isFconst))
4841 return MatchOperand_NoMatch;
4843 Parser.Lex(); // Eat '#' or '$'.
4845 // Handle negation, as that still comes through as a separate token.
4846 bool isNegative = false;
4847 if (Parser.getTok().is(AsmToken::Minus)) {
4851 const AsmToken &Tok = Parser.getTok();
4852 SMLoc Loc = Tok.getLoc();
4853 if (Tok.is(AsmToken::Real) && isVmovf) {
4854 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4855 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4856 // If we had a '-' in front, toggle the sign bit.
4857 IntVal ^= (uint64_t)isNegative << 31;
4858 Parser.Lex(); // Eat the token.
4859 Operands.push_back(ARMOperand::CreateImm(
4860 MCConstantExpr::Create(IntVal, getContext()),
4861 S, Parser.getTok().getLoc()));
4862 return MatchOperand_Success;
4864 // Also handle plain integers. Instructions which allow floating point
4865 // immediates also allow a raw encoded 8-bit value.
4866 if (Tok.is(AsmToken::Integer) && isFconst) {
4867 int64_t Val = Tok.getIntVal();
4868 Parser.Lex(); // Eat the token.
4869 if (Val > 255 || Val < 0) {
4870 Error(Loc, "encoded floating point value out of range");
4871 return MatchOperand_ParseFail;
4873 float RealVal = ARM_AM::getFPImmFloat(Val);
4874 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
4876 Operands.push_back(ARMOperand::CreateImm(
4877 MCConstantExpr::Create(Val, getContext()), S,
4878 Parser.getTok().getLoc()));
4879 return MatchOperand_Success;
4882 Error(Loc, "invalid floating point immediate");
4883 return MatchOperand_ParseFail;
4886 /// Parse a arm instruction operand. For now this parses the operand regardless
4887 /// of the mnemonic.
4888 bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
4891 // Check if the current operand has a custom associated parser, if so, try to
4892 // custom parse the operand, or fallback to the general approach.
4893 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4894 if (ResTy == MatchOperand_Success)
4896 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4897 // there was a match, but an error occurred, in which case, just return that
4898 // the operand parsing failed.
4899 if (ResTy == MatchOperand_ParseFail)
4902 switch (getLexer().getKind()) {
4904 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4906 case AsmToken::Identifier: {
4907 // If we've seen a branch mnemonic, the next operand must be a label. This
4908 // is true even if the label is a register name. So "br r1" means branch to
4910 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4912 if (!tryParseRegisterWithWriteBack(Operands))
4914 int Res = tryParseShiftRegister(Operands);
4915 if (Res == 0) // success
4917 else if (Res == -1) // irrecoverable error
4919 // If this is VMRS, check for the apsr_nzcv operand.
4920 if (Mnemonic == "vmrs" &&
4921 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4922 S = Parser.getTok().getLoc();
4924 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4929 // Fall though for the Identifier case that is not a register or a
4932 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4933 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4934 case AsmToken::String: // quoted label names.
4935 case AsmToken::Dot: { // . as a branch target
4936 // This was not a register so parse other operands that start with an
4937 // identifier (like labels) as expressions and create them as immediates.
4938 const MCExpr *IdVal;
4939 S = Parser.getTok().getLoc();
4940 if (getParser().parseExpression(IdVal))
4942 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4943 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4946 case AsmToken::LBrac:
4947 return parseMemory(Operands);
4948 case AsmToken::LCurly:
4949 return parseRegisterList(Operands);
4950 case AsmToken::Dollar:
4951 case AsmToken::Hash: {
4952 // #42 -> immediate.
4953 S = Parser.getTok().getLoc();
4956 if (Parser.getTok().isNot(AsmToken::Colon)) {
4957 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4958 const MCExpr *ImmVal;
4959 if (getParser().parseExpression(ImmVal))
4961 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4963 int32_t Val = CE->getValue();
4964 if (isNegative && Val == 0)
4965 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4967 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4968 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4970 // There can be a trailing '!' on operands that we want as a separate
4971 // '!' Token operand. Handle that here. For example, the compatibility
4972 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4973 if (Parser.getTok().is(AsmToken::Exclaim)) {
4974 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4975 Parser.getTok().getLoc()));
4976 Parser.Lex(); // Eat exclaim token
4980 // w/ a ':' after the '#', it's just like a plain ':'.
4983 case AsmToken::Colon: {
4984 // ":lower16:" and ":upper16:" expression prefixes
4985 // FIXME: Check it's an expression prefix,
4986 // e.g. (FOO - :lower16:BAR) isn't legal.
4987 ARMMCExpr::VariantKind RefKind;
4988 if (parsePrefix(RefKind))
4991 const MCExpr *SubExprVal;
4992 if (getParser().parseExpression(SubExprVal))
4995 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4997 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4998 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
5001 case AsmToken::Equal: {
5002 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
5003 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
5005 Parser.Lex(); // Eat '='
5006 const MCExpr *SubExprVal;
5007 if (getParser().parseExpression(SubExprVal))
5009 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5011 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
5012 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
5018 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
5019 // :lower16: and :upper16:.
5020 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
5021 RefKind = ARMMCExpr::VK_ARM_None;
5023 // consume an optional '#' (GNU compatibility)
5024 if (getLexer().is(AsmToken::Hash))
5027 // :lower16: and :upper16: modifiers
5028 assert(getLexer().is(AsmToken::Colon) && "expected a :");
5029 Parser.Lex(); // Eat ':'
5031 if (getLexer().isNot(AsmToken::Identifier)) {
5032 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
5036 StringRef IDVal = Parser.getTok().getIdentifier();
5037 if (IDVal == "lower16") {
5038 RefKind = ARMMCExpr::VK_ARM_LO16;
5039 } else if (IDVal == "upper16") {
5040 RefKind = ARMMCExpr::VK_ARM_HI16;
5042 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
5047 if (getLexer().isNot(AsmToken::Colon)) {
5048 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
5051 Parser.Lex(); // Eat the last ':'
5055 /// \brief Given a mnemonic, split out possible predication code and carry
5056 /// setting letters to form a canonical mnemonic and flags.
5058 // FIXME: Would be nice to autogen this.
5059 // FIXME: This is a bit of a maze of special cases.
5060 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
5061 unsigned &PredicationCode,
5063 unsigned &ProcessorIMod,
5064 StringRef &ITMask) {
5065 PredicationCode = ARMCC::AL;
5066 CarrySetting = false;
5069 // Ignore some mnemonics we know aren't predicated forms.
5071 // FIXME: Would be nice to autogen this.
5072 if ((Mnemonic == "movs" && isThumb()) ||
5073 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
5074 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
5075 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
5076 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
5077 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
5078 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
5079 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
5080 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
5081 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
5082 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
5083 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
5084 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
5087 // First, split out any predication code. Ignore mnemonics we know aren't
5088 // predicated but do have a carry-set and so weren't caught above.
5089 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
5090 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
5091 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
5092 Mnemonic != "sbcs" && Mnemonic != "rscs") {
5093 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
5094 .Case("eq", ARMCC::EQ)
5095 .Case("ne", ARMCC::NE)
5096 .Case("hs", ARMCC::HS)
5097 .Case("cs", ARMCC::HS)
5098 .Case("lo", ARMCC::LO)
5099 .Case("cc", ARMCC::LO)
5100 .Case("mi", ARMCC::MI)
5101 .Case("pl", ARMCC::PL)
5102 .Case("vs", ARMCC::VS)
5103 .Case("vc", ARMCC::VC)
5104 .Case("hi", ARMCC::HI)
5105 .Case("ls", ARMCC::LS)
5106 .Case("ge", ARMCC::GE)
5107 .Case("lt", ARMCC::LT)
5108 .Case("gt", ARMCC::GT)
5109 .Case("le", ARMCC::LE)
5110 .Case("al", ARMCC::AL)
5113 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5114 PredicationCode = CC;
5118 // Next, determine if we have a carry setting bit. We explicitly ignore all
5119 // the instructions we know end in 's'.
5120 if (Mnemonic.endswith("s") &&
5121 !(Mnemonic == "cps" || Mnemonic == "mls" ||
5122 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5123 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5124 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
5125 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
5126 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
5127 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
5128 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
5129 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
5130 (Mnemonic == "movs" && isThumb()))) {
5131 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5132 CarrySetting = true;
5135 // The "cps" instruction can have a interrupt mode operand which is glued into
5136 // the mnemonic. Check if this is the case, split it and parse the imod op
5137 if (Mnemonic.startswith("cps")) {
5138 // Split out any imod code.
5140 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5141 .Case("ie", ARM_PROC::IE)
5142 .Case("id", ARM_PROC::ID)
5145 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5146 ProcessorIMod = IMod;
5150 // The "it" instruction has the condition mask on the end of the mnemonic.
5151 if (Mnemonic.startswith("it")) {
5152 ITMask = Mnemonic.slice(2, Mnemonic.size());
5153 Mnemonic = Mnemonic.slice(0, 2);
5159 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
5160 /// inclusion of carry set or predication code operands.
5162 // FIXME: It would be nice to autogen this.
5164 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5165 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
5166 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5167 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
5168 Mnemonic == "add" || Mnemonic == "adc" ||
5169 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
5170 Mnemonic == "orr" || Mnemonic == "mvn" ||
5171 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
5172 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
5173 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
5174 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
5175 Mnemonic == "mla" || Mnemonic == "smlal" ||
5176 Mnemonic == "umlal" || Mnemonic == "umull"))) {
5177 CanAcceptCarrySet = true;
5179 CanAcceptCarrySet = false;
5181 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5182 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
5183 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5184 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
5185 Mnemonic.startswith("vsel") ||
5186 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
5187 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5188 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
5189 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
5190 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5191 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
5192 // These mnemonics are never predicable
5193 CanAcceptPredicationCode = false;
5194 } else if (!isThumb()) {
5195 // Some instructions are only predicable in Thumb mode
5196 CanAcceptPredicationCode
5197 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5198 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5199 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5200 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5201 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5202 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5203 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5204 } else if (isThumbOne()) {
5206 CanAcceptPredicationCode = Mnemonic != "movs";
5208 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
5210 CanAcceptPredicationCode = true;
5213 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
5214 OperandVector &Operands) {
5215 // FIXME: This is all horribly hacky. We really need a better way to deal
5216 // with optional operands like this in the matcher table.
5218 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5219 // another does not. Specifically, the MOVW instruction does not. So we
5220 // special case it here and remove the defaulted (non-setting) cc_out
5221 // operand if that's the instruction we're trying to match.
5223 // We do this as post-processing of the explicit operands rather than just
5224 // conditionally adding the cc_out in the first place because we need
5225 // to check the type of the parsed immediate operand.
5226 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
5227 !static_cast<ARMOperand &>(*Operands[4]).isARMSOImm() &&
5228 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5229 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
5232 // Register-register 'add' for thumb does not have a cc_out operand
5233 // when there are only two register operands.
5234 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
5235 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5236 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5237 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
5239 // Register-register 'add' for thumb does not have a cc_out operand
5240 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5241 // have to check the immediate range here since Thumb2 has a variant
5242 // that can handle a different range and has a cc_out operand.
5243 if (((isThumb() && Mnemonic == "add") ||
5244 (isThumbTwo() && Mnemonic == "sub")) &&
5245 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5246 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5247 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5248 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5249 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5250 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
5252 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5253 // imm0_4095 variant. That's the least-preferred variant when
5254 // selecting via the generic "add" mnemonic, so to know that we
5255 // should remove the cc_out operand, we have to explicitly check that
5256 // it's not one of the other variants. Ugh.
5257 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5258 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5259 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5260 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5261 // Nest conditions rather than one big 'if' statement for readability.
5263 // If both registers are low, we're in an IT block, and the immediate is
5264 // in range, we should use encoding T1 instead, which has a cc_out.
5266 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5267 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5268 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
5270 // Check against T3. If the second register is the PC, this is an
5271 // alternate form of ADR, which uses encoding T4, so check for that too.
5272 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5273 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
5276 // Otherwise, we use encoding T4, which does not have a cc_out
5281 // The thumb2 multiply instruction doesn't have a CCOut register, so
5282 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5283 // use the 16-bit encoding or not.
5284 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5285 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5286 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5287 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5288 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
5289 // If the registers aren't low regs, the destination reg isn't the
5290 // same as one of the source regs, or the cc_out operand is zero
5291 // outside of an IT block, we have to use the 32-bit encoding, so
5292 // remove the cc_out operand.
5293 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5294 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5295 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5296 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5297 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5298 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5299 static_cast<ARMOperand &>(*Operands[4]).getReg())))
5302 // Also check the 'mul' syntax variant that doesn't specify an explicit
5303 // destination register.
5304 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5305 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5306 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5307 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5308 // If the registers aren't low regs or the cc_out operand is zero
5309 // outside of an IT block, we have to use the 32-bit encoding, so
5310 // remove the cc_out operand.
5311 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5312 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5318 // Register-register 'add/sub' for thumb does not have a cc_out operand
5319 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5320 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5321 // right, this will result in better diagnostics (which operand is off)
5323 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5324 (Operands.size() == 5 || Operands.size() == 6) &&
5325 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5326 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5327 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5328 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
5329 (Operands.size() == 6 &&
5330 static_cast<ARMOperand &>(*Operands[5]).isImm())))
5336 bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5337 OperandVector &Operands) {
5338 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5339 unsigned RegIdx = 3;
5340 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5341 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5342 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5343 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
5346 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5347 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5348 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5349 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5350 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
5356 static bool isDataTypeToken(StringRef Tok) {
5357 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5358 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5359 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5360 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5361 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5362 Tok == ".f" || Tok == ".d";
5365 // FIXME: This bit should probably be handled via an explicit match class
5366 // in the .td files that matches the suffix instead of having it be
5367 // a literal string token the way it is now.
5368 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5369 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5371 static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features,
5372 unsigned VariantID);
5374 static bool RequiresVFPRegListValidation(StringRef Inst,
5375 bool &AcceptSinglePrecisionOnly,
5376 bool &AcceptDoublePrecisionOnly) {
5377 if (Inst.size() < 7)
5380 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5381 StringRef AddressingMode = Inst.substr(4, 2);
5382 if (AddressingMode == "ia" || AddressingMode == "db" ||
5383 AddressingMode == "ea" || AddressingMode == "fd") {
5384 AcceptSinglePrecisionOnly = Inst[6] == 's';
5385 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5393 /// Parse an arm instruction mnemonic followed by its operands.
5394 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5395 SMLoc NameLoc, OperandVector &Operands) {
5396 // FIXME: Can this be done via tablegen in some fashion?
5397 bool RequireVFPRegisterListCheck;
5398 bool AcceptSinglePrecisionOnly;
5399 bool AcceptDoublePrecisionOnly;
5400 RequireVFPRegisterListCheck =
5401 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5402 AcceptDoublePrecisionOnly);
5404 // Apply mnemonic aliases before doing anything else, as the destination
5405 // mnemonic may include suffices and we want to handle them normally.
5406 // The generic tblgen'erated code does this later, at the start of
5407 // MatchInstructionImpl(), but that's too late for aliases that include
5408 // any sort of suffix.
5409 uint64_t AvailableFeatures = getAvailableFeatures();
5410 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5411 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5413 // First check for the ARM-specific .req directive.
5414 if (Parser.getTok().is(AsmToken::Identifier) &&
5415 Parser.getTok().getIdentifier() == ".req") {
5416 parseDirectiveReq(Name, NameLoc);
5417 // We always return 'error' for this, as we're done with this
5418 // statement and don't need to match the 'instruction."
5422 // Create the leading tokens for the mnemonic, split by '.' characters.
5423 size_t Start = 0, Next = Name.find('.');
5424 StringRef Mnemonic = Name.slice(Start, Next);
5426 // Split out the predication code and carry setting flag from the mnemonic.
5427 unsigned PredicationCode;
5428 unsigned ProcessorIMod;
5431 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5432 ProcessorIMod, ITMask);
5434 // In Thumb1, only the branch (B) instruction can be predicated.
5435 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5436 Parser.eatToEndOfStatement();
5437 return Error(NameLoc, "conditional execution not supported in Thumb1");
5440 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5442 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5443 // is the mask as it will be for the IT encoding if the conditional
5444 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5445 // where the conditional bit0 is zero, the instruction post-processing
5446 // will adjust the mask accordingly.
5447 if (Mnemonic == "it") {
5448 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5449 if (ITMask.size() > 3) {
5450 Parser.eatToEndOfStatement();
5451 return Error(Loc, "too many conditions on IT instruction");
5454 for (unsigned i = ITMask.size(); i != 0; --i) {
5455 char pos = ITMask[i - 1];
5456 if (pos != 't' && pos != 'e') {
5457 Parser.eatToEndOfStatement();
5458 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5461 if (ITMask[i - 1] == 't')
5464 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5467 // FIXME: This is all a pretty gross hack. We should automatically handle
5468 // optional operands like this via tblgen.
5470 // Next, add the CCOut and ConditionCode operands, if needed.
5472 // For mnemonics which can ever incorporate a carry setting bit or predication
5473 // code, our matching model involves us always generating CCOut and
5474 // ConditionCode operands to match the mnemonic "as written" and then we let
5475 // the matcher deal with finding the right instruction or generating an
5476 // appropriate error.
5477 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5478 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5480 // If we had a carry-set on an instruction that can't do that, issue an
5482 if (!CanAcceptCarrySet && CarrySetting) {
5483 Parser.eatToEndOfStatement();
5484 return Error(NameLoc, "instruction '" + Mnemonic +
5485 "' can not set flags, but 's' suffix specified");
5487 // If we had a predication code on an instruction that can't do that, issue an
5489 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5490 Parser.eatToEndOfStatement();
5491 return Error(NameLoc, "instruction '" + Mnemonic +
5492 "' is not predicable, but condition code specified");
5495 // Add the carry setting operand, if necessary.
5496 if (CanAcceptCarrySet) {
5497 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5498 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5502 // Add the predication code operand, if necessary.
5503 if (CanAcceptPredicationCode) {
5504 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5506 Operands.push_back(ARMOperand::CreateCondCode(
5507 ARMCC::CondCodes(PredicationCode), Loc));
5510 // Add the processor imod operand, if necessary.
5511 if (ProcessorIMod) {
5512 Operands.push_back(ARMOperand::CreateImm(
5513 MCConstantExpr::Create(ProcessorIMod, getContext()),
5517 // Add the remaining tokens in the mnemonic.
5518 while (Next != StringRef::npos) {
5520 Next = Name.find('.', Start + 1);
5521 StringRef ExtraToken = Name.slice(Start, Next);
5523 // Some NEON instructions have an optional datatype suffix that is
5524 // completely ignored. Check for that.
5525 if (isDataTypeToken(ExtraToken) &&
5526 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5529 // For for ARM mode generate an error if the .n qualifier is used.
5530 if (ExtraToken == ".n" && !isThumb()) {
5531 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5532 Parser.eatToEndOfStatement();
5533 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5537 // The .n qualifier is always discarded as that is what the tables
5538 // and matcher expect. In ARM mode the .w qualifier has no effect,
5539 // so discard it to avoid errors that can be caused by the matcher.
5540 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5541 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5542 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5546 // Read the remaining operands.
5547 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5548 // Read the first operand.
5549 if (parseOperand(Operands, Mnemonic)) {
5550 Parser.eatToEndOfStatement();
5554 while (getLexer().is(AsmToken::Comma)) {
5555 Parser.Lex(); // Eat the comma.
5557 // Parse and remember the operand.
5558 if (parseOperand(Operands, Mnemonic)) {
5559 Parser.eatToEndOfStatement();
5565 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5566 SMLoc Loc = getLexer().getLoc();
5567 Parser.eatToEndOfStatement();
5568 return Error(Loc, "unexpected token in argument list");
5571 Parser.Lex(); // Consume the EndOfStatement
5573 if (RequireVFPRegisterListCheck) {
5574 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5575 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5576 return Error(Op.getStartLoc(),
5577 "VFP/Neon single precision register expected");
5578 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5579 return Error(Op.getStartLoc(),
5580 "VFP/Neon double precision register expected");
5583 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5584 // do and don't have a cc_out optional-def operand. With some spot-checks
5585 // of the operand list, we can figure out which variant we're trying to
5586 // parse and adjust accordingly before actually matching. We shouldn't ever
5587 // try to remove a cc_out operand that was explicitly set on the the
5588 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5589 // table driven matcher doesn't fit well with the ARM instruction set.
5590 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
5591 Operands.erase(Operands.begin() + 1);
5593 // Some instructions have the same mnemonic, but don't always
5594 // have a predicate. Distinguish them here and delete the
5595 // predicate if needed.
5596 if (shouldOmitPredicateOperand(Mnemonic, Operands))
5597 Operands.erase(Operands.begin() + 1);
5599 // ARM mode 'blx' need special handling, as the register operand version
5600 // is predicable, but the label operand version is not. So, we can't rely
5601 // on the Mnemonic based checking to correctly figure out when to put
5602 // a k_CondCode operand in the list. If we're trying to match the label
5603 // version, remove the k_CondCode operand here.
5604 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5605 static_cast<ARMOperand &>(*Operands[2]).isImm())
5606 Operands.erase(Operands.begin() + 1);
5608 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5609 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5610 // a single GPRPair reg operand is used in the .td file to replace the two
5611 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5612 // expressed as a GPRPair, so we have to manually merge them.
5613 // FIXME: We would really like to be able to tablegen'erate this.
5614 if (!isThumb() && Operands.size() > 4 &&
5615 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5616 Mnemonic == "stlexd")) {
5617 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5618 unsigned Idx = isLoad ? 2 : 3;
5619 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5620 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
5622 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5623 // Adjust only if Op1 and Op2 are GPRs.
5624 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5625 MRC.contains(Op2.getReg())) {
5626 unsigned Reg1 = Op1.getReg();
5627 unsigned Reg2 = Op2.getReg();
5628 unsigned Rt = MRI->getEncodingValue(Reg1);
5629 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5631 // Rt2 must be Rt + 1 and Rt must be even.
5632 if (Rt + 1 != Rt2 || (Rt & 1)) {
5633 Error(Op2.getStartLoc(), isLoad
5634 ? "destination operands must be sequential"
5635 : "source operands must be sequential");
5638 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5639 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5641 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5642 Operands.erase(Operands.begin() + Idx + 1);
5646 // GNU Assembler extension (compatibility)
5647 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
5648 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5649 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5651 assert(Op2.isReg() && "expected register argument");
5653 unsigned SuperReg = MRI->getMatchingSuperReg(
5654 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
5656 assert(SuperReg && "expected register pair");
5658 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
5661 Operands.begin() + 3,
5662 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
5666 // FIXME: As said above, this is all a pretty gross hack. This instruction
5667 // does not fit with other "subs" and tblgen.
5668 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5669 // so the Mnemonic is the original name "subs" and delete the predicate
5670 // operand so it will match the table entry.
5671 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5672 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5673 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5674 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5675 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5676 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5677 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
5678 Operands.erase(Operands.begin() + 1);
5683 // Validate context-sensitive operand constraints.
5685 // return 'true' if register list contains non-low GPR registers,
5686 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5687 // 'containsReg' to true.
5688 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5689 unsigned HiReg, bool &containsReg) {
5690 containsReg = false;
5691 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5692 unsigned OpReg = Inst.getOperand(i).getReg();
5695 // Anything other than a low register isn't legal here.
5696 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5702 // Check if the specified regisgter is in the register list of the inst,
5703 // starting at the indicated operand number.
5704 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5705 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5706 unsigned OpReg = Inst.getOperand(i).getReg();
5713 // Return true if instruction has the interesting property of being
5714 // allowed in IT blocks, but not being predicable.
5715 static bool instIsBreakpoint(const MCInst &Inst) {
5716 return Inst.getOpcode() == ARM::tBKPT ||
5717 Inst.getOpcode() == ARM::BKPT ||
5718 Inst.getOpcode() == ARM::tHLT ||
5719 Inst.getOpcode() == ARM::HLT;
5723 // FIXME: We would really like to be able to tablegen'erate this.
5724 bool ARMAsmParser::validateInstruction(MCInst &Inst,
5725 const OperandVector &Operands) {
5726 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
5727 SMLoc Loc = Operands[0]->getStartLoc();
5729 // Check the IT block state first.
5730 // NOTE: BKPT and HLT instructions have the interesting property of being
5731 // allowed in IT blocks, but not being predicable. They just always execute.
5732 if (inITBlock() && !instIsBreakpoint(Inst)) {
5734 if (ITState.FirstCond)
5735 ITState.FirstCond = false;
5737 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5738 // The instruction must be predicable.
5739 if (!MCID.isPredicable())
5740 return Error(Loc, "instructions in IT block must be predicable");
5741 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5742 unsigned ITCond = Bit ? ITState.Cond :
5743 ARMCC::getOppositeCondition(ITState.Cond);
5744 if (Cond != ITCond) {
5745 // Find the condition code Operand to get its SMLoc information.
5747 for (unsigned I = 1; I < Operands.size(); ++I)
5748 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
5749 CondLoc = Operands[I]->getStartLoc();
5750 return Error(CondLoc, "incorrect condition in IT block; got '" +
5751 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5752 "', but expected '" +
5753 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5755 // Check for non-'al' condition codes outside of the IT block.
5756 } else if (isThumbTwo() && MCID.isPredicable() &&
5757 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5758 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5759 Inst.getOpcode() != ARM::t2Bcc)
5760 return Error(Loc, "predicated instructions must be in IT block");
5762 const unsigned Opcode = Inst.getOpcode();
5766 case ARM::LDRD_POST: {
5767 const unsigned RtReg = Inst.getOperand(0).getReg();
5770 if (RtReg == ARM::LR)
5771 return Error(Operands[3]->getStartLoc(),
5774 const unsigned Rt = MRI->getEncodingValue(RtReg);
5775 // Rt must be even-numbered.
5777 return Error(Operands[3]->getStartLoc(),
5778 "Rt must be even-numbered");
5780 // Rt2 must be Rt + 1.
5781 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5783 return Error(Operands[3]->getStartLoc(),
5784 "destination operands must be sequential");
5786 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5787 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5788 // For addressing modes with writeback, the base register needs to be
5789 // different from the destination registers.
5790 if (Rn == Rt || Rn == Rt2)
5791 return Error(Operands[3]->getStartLoc(),
5792 "base register needs to be different from destination "
5799 case ARM::t2LDRD_PRE:
5800 case ARM::t2LDRD_POST: {
5801 // Rt2 must be different from Rt.
5802 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5803 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5805 return Error(Operands[3]->getStartLoc(),
5806 "destination operands can't be identical");
5810 // Rt2 must be Rt + 1.
5811 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5812 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5814 return Error(Operands[3]->getStartLoc(),
5815 "source operands must be sequential");
5819 case ARM::STRD_POST: {
5820 // Rt2 must be Rt + 1.
5821 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5822 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5824 return Error(Operands[3]->getStartLoc(),
5825 "source operands must be sequential");
5828 case ARM::STR_PRE_IMM:
5829 case ARM::STR_PRE_REG:
5830 case ARM::STR_POST_IMM:
5831 case ARM::STR_POST_REG:
5833 case ARM::STRH_POST:
5834 case ARM::STRB_PRE_IMM:
5835 case ARM::STRB_PRE_REG:
5836 case ARM::STRB_POST_IMM:
5837 case ARM::STRB_POST_REG: {
5838 // Rt must be different from Rn.
5839 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5840 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5843 return Error(Operands[3]->getStartLoc(),
5844 "source register and base register can't be identical");
5847 case ARM::LDR_PRE_IMM:
5848 case ARM::LDR_PRE_REG:
5849 case ARM::LDR_POST_IMM:
5850 case ARM::LDR_POST_REG:
5852 case ARM::LDRH_POST:
5853 case ARM::LDRSH_PRE:
5854 case ARM::LDRSH_POST:
5855 case ARM::LDRB_PRE_IMM:
5856 case ARM::LDRB_PRE_REG:
5857 case ARM::LDRB_POST_IMM:
5858 case ARM::LDRB_POST_REG:
5859 case ARM::LDRSB_PRE:
5860 case ARM::LDRSB_POST: {
5861 // Rt must be different from Rn.
5862 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5863 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5866 return Error(Operands[3]->getStartLoc(),
5867 "destination register and base register can't be identical");
5872 // Width must be in range [1, 32-lsb].
5873 unsigned LSB = Inst.getOperand(2).getImm();
5874 unsigned Widthm1 = Inst.getOperand(3).getImm();
5875 if (Widthm1 >= 32 - LSB)
5876 return Error(Operands[5]->getStartLoc(),
5877 "bitfield width must be in range [1,32-lsb]");
5880 // Notionally handles ARM::tLDMIA_UPD too.
5882 // If we're parsing Thumb2, the .w variant is available and handles
5883 // most cases that are normally illegal for a Thumb1 LDM instruction.
5884 // We'll make the transformation in processInstruction() if necessary.
5886 // Thumb LDM instructions are writeback iff the base register is not
5887 // in the register list.
5888 unsigned Rn = Inst.getOperand(0).getReg();
5889 bool HasWritebackToken =
5890 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5891 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
5892 bool ListContainsBase;
5893 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5894 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
5895 "registers must be in range r0-r7");
5896 // If we should have writeback, then there should be a '!' token.
5897 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
5898 return Error(Operands[2]->getStartLoc(),
5899 "writeback operator '!' expected");
5900 // If we should not have writeback, there must not be a '!'. This is
5901 // true even for the 32-bit wide encodings.
5902 if (ListContainsBase && HasWritebackToken)
5903 return Error(Operands[3]->getStartLoc(),
5904 "writeback operator '!' not allowed when base register "
5905 "in register list");
5909 case ARM::LDMIA_UPD:
5910 case ARM::LDMDB_UPD:
5911 case ARM::LDMIB_UPD:
5912 case ARM::LDMDA_UPD:
5913 // ARM variants loading and updating the same register are only officially
5914 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5918 case ARM::t2LDMIA_UPD:
5919 case ARM::t2LDMDB_UPD:
5920 case ARM::t2STMIA_UPD:
5921 case ARM::t2STMDB_UPD: {
5922 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5923 return Error(Operands.back()->getStartLoc(),
5924 "writeback register not allowed in register list");
5927 case ARM::sysLDMIA_UPD:
5928 case ARM::sysLDMDA_UPD:
5929 case ARM::sysLDMDB_UPD:
5930 case ARM::sysLDMIB_UPD:
5931 if (!listContainsReg(Inst, 3, ARM::PC))
5932 return Error(Operands[4]->getStartLoc(),
5933 "writeback register only allowed on system LDM "
5934 "if PC in register-list");
5936 case ARM::sysSTMIA_UPD:
5937 case ARM::sysSTMDA_UPD:
5938 case ARM::sysSTMDB_UPD:
5939 case ARM::sysSTMIB_UPD:
5940 return Error(Operands[2]->getStartLoc(),
5941 "system STM cannot have writeback register");
5943 // The second source operand must be the same register as the destination
5946 // In this case, we must directly check the parsed operands because the
5947 // cvtThumbMultiply() function is written in such a way that it guarantees
5948 // this first statement is always true for the new Inst. Essentially, the
5949 // destination is unconditionally copied into the second source operand
5950 // without checking to see if it matches what we actually parsed.
5951 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
5952 ((ARMOperand &)*Operands[5]).getReg()) &&
5953 (((ARMOperand &)*Operands[3]).getReg() !=
5954 ((ARMOperand &)*Operands[4]).getReg())) {
5955 return Error(Operands[3]->getStartLoc(),
5956 "destination register must match source register");
5960 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5961 // so only issue a diagnostic for thumb1. The instructions will be
5962 // switched to the t2 encodings in processInstruction() if necessary.
5964 bool ListContainsBase;
5965 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
5967 return Error(Operands[2]->getStartLoc(),
5968 "registers must be in range r0-r7 or pc");
5972 bool ListContainsBase;
5973 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
5975 return Error(Operands[2]->getStartLoc(),
5976 "registers must be in range r0-r7 or lr");
5979 case ARM::tSTMIA_UPD: {
5980 bool ListContainsBase, InvalidLowList;
5981 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5982 0, ListContainsBase);
5983 if (InvalidLowList && !isThumbTwo())
5984 return Error(Operands[4]->getStartLoc(),
5985 "registers must be in range r0-r7");
5987 // This would be converted to a 32-bit stm, but that's not valid if the
5988 // writeback register is in the list.
5989 if (InvalidLowList && ListContainsBase)
5990 return Error(Operands[4]->getStartLoc(),
5991 "writeback operator '!' not allowed when base register "
5992 "in register list");
5995 case ARM::tADDrSP: {
5996 // If the non-SP source operand and the destination operand are not the
5997 // same, we need thumb2 (for the wide encoding), or we have an error.
5998 if (!isThumbTwo() &&
5999 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
6000 return Error(Operands[4]->getStartLoc(),
6001 "source register must be the same as destination");
6005 // Final range checking for Thumb unconditional branch instructions.
6007 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
6008 return Error(Operands[2]->getStartLoc(), "branch target out of range");
6011 int op = (Operands[2]->isImm()) ? 2 : 3;
6012 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
6013 return Error(Operands[op]->getStartLoc(), "branch target out of range");
6016 // Final range checking for Thumb conditional branch instructions.
6018 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
6019 return Error(Operands[2]->getStartLoc(), "branch target out of range");
6022 int Op = (Operands[2]->isImm()) ? 2 : 3;
6023 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
6024 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
6029 case ARM::t2MOVTi16:
6031 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
6032 // especially when we turn it into a movw and the expression <symbol> does
6033 // not have a :lower16: or :upper16 as part of the expression. We don't
6034 // want the behavior of silently truncating, which can be unexpected and
6035 // lead to bugs that are difficult to find since this is an easy mistake
6037 int i = (Operands[3]->isImm()) ? 3 : 4;
6038 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
6039 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
6041 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
6043 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
6044 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
6045 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
6048 "immediate expression for mov requires :lower16: or :upper16");
6056 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
6058 default: llvm_unreachable("unexpected opcode!");
6060 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6061 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6062 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6063 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6064 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6065 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6066 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
6067 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
6068 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
6071 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6072 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6073 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6074 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6075 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
6077 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6078 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6079 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6080 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6081 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
6083 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
6084 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
6085 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
6086 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
6087 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
6090 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6091 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6092 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6093 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
6094 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6095 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6096 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6097 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6098 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
6099 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6100 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
6101 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
6102 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
6103 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6104 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
6107 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6108 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6109 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6110 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6111 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6112 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6113 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6114 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6115 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6116 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6117 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6118 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6119 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6120 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6121 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6122 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6123 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6124 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
6127 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6128 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6129 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6130 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6131 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6132 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6133 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6134 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6135 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6136 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6137 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6138 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6139 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6140 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6141 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6144 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6145 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6146 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6147 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6148 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6149 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6150 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6151 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6152 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6153 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6154 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6155 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6156 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6157 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6158 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6159 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6160 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6161 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
6165 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
6167 default: llvm_unreachable("unexpected opcode!");
6169 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6170 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6171 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6172 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6173 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6174 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6175 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6176 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6177 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
6180 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6181 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6182 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6183 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6184 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6185 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6186 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6187 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6188 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6189 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6190 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6191 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6192 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6193 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6194 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
6197 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6198 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6199 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6200 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
6201 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6202 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6203 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6204 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6205 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6206 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6207 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6208 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6209 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6210 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6211 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6212 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6213 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6214 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6217 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6218 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6219 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6220 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6221 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6222 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6223 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6224 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6225 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6226 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6227 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6228 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6229 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6230 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6231 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
6234 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6235 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6236 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6237 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6238 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6239 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6240 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6241 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6242 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6243 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6244 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6245 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6246 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6247 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6248 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6249 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6250 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6251 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
6254 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6255 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6256 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6257 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6258 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6259 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6260 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6261 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6262 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6263 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6264 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6265 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6266 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6267 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6268 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6271 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6272 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6273 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6274 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6275 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6276 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6277 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6278 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6279 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6280 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6281 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6282 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6283 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6284 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6285 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6286 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6287 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6288 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6291 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6292 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6293 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6294 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6295 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6296 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6297 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6298 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6299 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6300 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6301 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6302 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6303 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6304 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6305 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6306 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6307 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6308 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
6312 bool ARMAsmParser::processInstruction(MCInst &Inst,
6313 const OperandVector &Operands) {
6314 switch (Inst.getOpcode()) {
6315 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6316 case ARM::LDRT_POST:
6317 case ARM::LDRBT_POST: {
6318 const unsigned Opcode =
6319 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6320 : ARM::LDRBT_POST_IMM;
6322 TmpInst.setOpcode(Opcode);
6323 TmpInst.addOperand(Inst.getOperand(0));
6324 TmpInst.addOperand(Inst.getOperand(1));
6325 TmpInst.addOperand(Inst.getOperand(1));
6326 TmpInst.addOperand(MCOperand::CreateReg(0));
6327 TmpInst.addOperand(MCOperand::CreateImm(0));
6328 TmpInst.addOperand(Inst.getOperand(2));
6329 TmpInst.addOperand(Inst.getOperand(3));
6333 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6334 case ARM::STRT_POST:
6335 case ARM::STRBT_POST: {
6336 const unsigned Opcode =
6337 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6338 : ARM::STRBT_POST_IMM;
6340 TmpInst.setOpcode(Opcode);
6341 TmpInst.addOperand(Inst.getOperand(1));
6342 TmpInst.addOperand(Inst.getOperand(0));
6343 TmpInst.addOperand(Inst.getOperand(1));
6344 TmpInst.addOperand(MCOperand::CreateReg(0));
6345 TmpInst.addOperand(MCOperand::CreateImm(0));
6346 TmpInst.addOperand(Inst.getOperand(2));
6347 TmpInst.addOperand(Inst.getOperand(3));
6351 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6353 if (Inst.getOperand(1).getReg() != ARM::PC ||
6354 Inst.getOperand(5).getReg() != 0)
6357 TmpInst.setOpcode(ARM::ADR);
6358 TmpInst.addOperand(Inst.getOperand(0));
6359 TmpInst.addOperand(Inst.getOperand(2));
6360 TmpInst.addOperand(Inst.getOperand(3));
6361 TmpInst.addOperand(Inst.getOperand(4));
6365 // Aliases for alternate PC+imm syntax of LDR instructions.
6366 case ARM::t2LDRpcrel:
6367 // Select the narrow version if the immediate will fit.
6368 if (Inst.getOperand(1).getImm() > 0 &&
6369 Inst.getOperand(1).getImm() <= 0xff &&
6370 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6371 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
6372 Inst.setOpcode(ARM::tLDRpci);
6374 Inst.setOpcode(ARM::t2LDRpci);
6376 case ARM::t2LDRBpcrel:
6377 Inst.setOpcode(ARM::t2LDRBpci);
6379 case ARM::t2LDRHpcrel:
6380 Inst.setOpcode(ARM::t2LDRHpci);
6382 case ARM::t2LDRSBpcrel:
6383 Inst.setOpcode(ARM::t2LDRSBpci);
6385 case ARM::t2LDRSHpcrel:
6386 Inst.setOpcode(ARM::t2LDRSHpci);
6388 // Handle NEON VST complex aliases.
6389 case ARM::VST1LNdWB_register_Asm_8:
6390 case ARM::VST1LNdWB_register_Asm_16:
6391 case ARM::VST1LNdWB_register_Asm_32: {
6393 // Shuffle the operands around so the lane index operand is in the
6396 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6397 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6398 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6399 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6400 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6401 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6402 TmpInst.addOperand(Inst.getOperand(1)); // lane
6403 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6404 TmpInst.addOperand(Inst.getOperand(6));
6409 case ARM::VST2LNdWB_register_Asm_8:
6410 case ARM::VST2LNdWB_register_Asm_16:
6411 case ARM::VST2LNdWB_register_Asm_32:
6412 case ARM::VST2LNqWB_register_Asm_16:
6413 case ARM::VST2LNqWB_register_Asm_32: {
6415 // Shuffle the operands around so the lane index operand is in the
6418 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6419 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6420 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6421 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6422 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6423 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6424 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6426 TmpInst.addOperand(Inst.getOperand(1)); // lane
6427 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6428 TmpInst.addOperand(Inst.getOperand(6));
6433 case ARM::VST3LNdWB_register_Asm_8:
6434 case ARM::VST3LNdWB_register_Asm_16:
6435 case ARM::VST3LNdWB_register_Asm_32:
6436 case ARM::VST3LNqWB_register_Asm_16:
6437 case ARM::VST3LNqWB_register_Asm_32: {
6439 // Shuffle the operands around so the lane index operand is in the
6442 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6443 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6444 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6445 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6446 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6447 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6448 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6450 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6452 TmpInst.addOperand(Inst.getOperand(1)); // lane
6453 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6454 TmpInst.addOperand(Inst.getOperand(6));
6459 case ARM::VST4LNdWB_register_Asm_8:
6460 case ARM::VST4LNdWB_register_Asm_16:
6461 case ARM::VST4LNdWB_register_Asm_32:
6462 case ARM::VST4LNqWB_register_Asm_16:
6463 case ARM::VST4LNqWB_register_Asm_32: {
6465 // Shuffle the operands around so the lane index operand is in the
6468 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6469 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6470 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6471 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6472 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6473 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6474 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6476 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6478 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6480 TmpInst.addOperand(Inst.getOperand(1)); // lane
6481 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6482 TmpInst.addOperand(Inst.getOperand(6));
6487 case ARM::VST1LNdWB_fixed_Asm_8:
6488 case ARM::VST1LNdWB_fixed_Asm_16:
6489 case ARM::VST1LNdWB_fixed_Asm_32: {
6491 // Shuffle the operands around so the lane index operand is in the
6494 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6495 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6496 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6497 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6498 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6499 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6500 TmpInst.addOperand(Inst.getOperand(1)); // lane
6501 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6502 TmpInst.addOperand(Inst.getOperand(5));
6507 case ARM::VST2LNdWB_fixed_Asm_8:
6508 case ARM::VST2LNdWB_fixed_Asm_16:
6509 case ARM::VST2LNdWB_fixed_Asm_32:
6510 case ARM::VST2LNqWB_fixed_Asm_16:
6511 case ARM::VST2LNqWB_fixed_Asm_32: {
6513 // Shuffle the operands around so the lane index operand is in the
6516 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6517 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6518 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6519 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6520 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6521 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6522 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6524 TmpInst.addOperand(Inst.getOperand(1)); // lane
6525 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6526 TmpInst.addOperand(Inst.getOperand(5));
6531 case ARM::VST3LNdWB_fixed_Asm_8:
6532 case ARM::VST3LNdWB_fixed_Asm_16:
6533 case ARM::VST3LNdWB_fixed_Asm_32:
6534 case ARM::VST3LNqWB_fixed_Asm_16:
6535 case ARM::VST3LNqWB_fixed_Asm_32: {
6537 // Shuffle the operands around so the lane index operand is in the
6540 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6541 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6542 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6543 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6544 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6545 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6548 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6550 TmpInst.addOperand(Inst.getOperand(1)); // lane
6551 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6552 TmpInst.addOperand(Inst.getOperand(5));
6557 case ARM::VST4LNdWB_fixed_Asm_8:
6558 case ARM::VST4LNdWB_fixed_Asm_16:
6559 case ARM::VST4LNdWB_fixed_Asm_32:
6560 case ARM::VST4LNqWB_fixed_Asm_16:
6561 case ARM::VST4LNqWB_fixed_Asm_32: {
6563 // Shuffle the operands around so the lane index operand is in the
6566 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6567 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6568 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6569 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6570 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6571 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6574 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6578 TmpInst.addOperand(Inst.getOperand(1)); // lane
6579 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6580 TmpInst.addOperand(Inst.getOperand(5));
6585 case ARM::VST1LNdAsm_8:
6586 case ARM::VST1LNdAsm_16:
6587 case ARM::VST1LNdAsm_32: {
6589 // Shuffle the operands around so the lane index operand is in the
6592 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6593 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6594 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6595 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6596 TmpInst.addOperand(Inst.getOperand(1)); // lane
6597 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6598 TmpInst.addOperand(Inst.getOperand(5));
6603 case ARM::VST2LNdAsm_8:
6604 case ARM::VST2LNdAsm_16:
6605 case ARM::VST2LNdAsm_32:
6606 case ARM::VST2LNqAsm_16:
6607 case ARM::VST2LNqAsm_32: {
6609 // Shuffle the operands around so the lane index operand is in the
6612 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6613 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6614 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6615 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6616 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6618 TmpInst.addOperand(Inst.getOperand(1)); // lane
6619 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6620 TmpInst.addOperand(Inst.getOperand(5));
6625 case ARM::VST3LNdAsm_8:
6626 case ARM::VST3LNdAsm_16:
6627 case ARM::VST3LNdAsm_32:
6628 case ARM::VST3LNqAsm_16:
6629 case ARM::VST3LNqAsm_32: {
6631 // Shuffle the operands around so the lane index operand is in the
6634 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6635 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6636 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6637 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6638 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6640 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6642 TmpInst.addOperand(Inst.getOperand(1)); // lane
6643 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6644 TmpInst.addOperand(Inst.getOperand(5));
6649 case ARM::VST4LNdAsm_8:
6650 case ARM::VST4LNdAsm_16:
6651 case ARM::VST4LNdAsm_32:
6652 case ARM::VST4LNqAsm_16:
6653 case ARM::VST4LNqAsm_32: {
6655 // Shuffle the operands around so the lane index operand is in the
6658 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6659 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6660 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6661 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6662 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6664 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6666 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6668 TmpInst.addOperand(Inst.getOperand(1)); // lane
6669 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6670 TmpInst.addOperand(Inst.getOperand(5));
6675 // Handle NEON VLD complex aliases.
6676 case ARM::VLD1LNdWB_register_Asm_8:
6677 case ARM::VLD1LNdWB_register_Asm_16:
6678 case ARM::VLD1LNdWB_register_Asm_32: {
6680 // Shuffle the operands around so the lane index operand is in the
6683 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6684 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6685 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6686 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6687 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6688 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6689 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6690 TmpInst.addOperand(Inst.getOperand(1)); // lane
6691 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6692 TmpInst.addOperand(Inst.getOperand(6));
6697 case ARM::VLD2LNdWB_register_Asm_8:
6698 case ARM::VLD2LNdWB_register_Asm_16:
6699 case ARM::VLD2LNdWB_register_Asm_32:
6700 case ARM::VLD2LNqWB_register_Asm_16:
6701 case ARM::VLD2LNqWB_register_Asm_32: {
6703 // Shuffle the operands around so the lane index operand is in the
6706 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6707 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6708 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6710 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6711 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6712 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6713 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6714 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6715 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6717 TmpInst.addOperand(Inst.getOperand(1)); // lane
6718 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6719 TmpInst.addOperand(Inst.getOperand(6));
6724 case ARM::VLD3LNdWB_register_Asm_8:
6725 case ARM::VLD3LNdWB_register_Asm_16:
6726 case ARM::VLD3LNdWB_register_Asm_32:
6727 case ARM::VLD3LNqWB_register_Asm_16:
6728 case ARM::VLD3LNqWB_register_Asm_32: {
6730 // Shuffle the operands around so the lane index operand is in the
6733 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6734 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6735 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6737 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6739 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6740 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6741 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6742 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6743 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6744 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6746 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6748 TmpInst.addOperand(Inst.getOperand(1)); // lane
6749 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6750 TmpInst.addOperand(Inst.getOperand(6));
6755 case ARM::VLD4LNdWB_register_Asm_8:
6756 case ARM::VLD4LNdWB_register_Asm_16:
6757 case ARM::VLD4LNdWB_register_Asm_32:
6758 case ARM::VLD4LNqWB_register_Asm_16:
6759 case ARM::VLD4LNqWB_register_Asm_32: {
6761 // Shuffle the operands around so the lane index operand is in the
6764 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6765 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6766 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6768 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6770 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6772 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6773 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6774 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6775 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6776 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6783 TmpInst.addOperand(Inst.getOperand(1)); // lane
6784 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6785 TmpInst.addOperand(Inst.getOperand(6));
6790 case ARM::VLD1LNdWB_fixed_Asm_8:
6791 case ARM::VLD1LNdWB_fixed_Asm_16:
6792 case ARM::VLD1LNdWB_fixed_Asm_32: {
6794 // Shuffle the operands around so the lane index operand is in the
6797 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6798 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6799 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6800 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6801 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6802 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6803 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6804 TmpInst.addOperand(Inst.getOperand(1)); // lane
6805 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6806 TmpInst.addOperand(Inst.getOperand(5));
6811 case ARM::VLD2LNdWB_fixed_Asm_8:
6812 case ARM::VLD2LNdWB_fixed_Asm_16:
6813 case ARM::VLD2LNdWB_fixed_Asm_32:
6814 case ARM::VLD2LNqWB_fixed_Asm_16:
6815 case ARM::VLD2LNqWB_fixed_Asm_32: {
6817 // Shuffle the operands around so the lane index operand is in the
6820 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6821 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6822 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6824 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6825 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6826 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6827 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6828 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6829 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6831 TmpInst.addOperand(Inst.getOperand(1)); // lane
6832 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6833 TmpInst.addOperand(Inst.getOperand(5));
6838 case ARM::VLD3LNdWB_fixed_Asm_8:
6839 case ARM::VLD3LNdWB_fixed_Asm_16:
6840 case ARM::VLD3LNdWB_fixed_Asm_32:
6841 case ARM::VLD3LNqWB_fixed_Asm_16:
6842 case ARM::VLD3LNqWB_fixed_Asm_32: {
6844 // Shuffle the operands around so the lane index operand is in the
6847 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6848 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6853 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6854 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6855 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6856 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6857 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6860 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6862 TmpInst.addOperand(Inst.getOperand(1)); // lane
6863 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6864 TmpInst.addOperand(Inst.getOperand(5));
6869 case ARM::VLD4LNdWB_fixed_Asm_8:
6870 case ARM::VLD4LNdWB_fixed_Asm_16:
6871 case ARM::VLD4LNdWB_fixed_Asm_32:
6872 case ARM::VLD4LNqWB_fixed_Asm_16:
6873 case ARM::VLD4LNqWB_fixed_Asm_32: {
6875 // Shuffle the operands around so the lane index operand is in the
6878 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6879 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6880 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6884 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6886 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6887 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6888 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6889 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6890 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6891 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6893 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6895 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6897 TmpInst.addOperand(Inst.getOperand(1)); // lane
6898 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6899 TmpInst.addOperand(Inst.getOperand(5));
6904 case ARM::VLD1LNdAsm_8:
6905 case ARM::VLD1LNdAsm_16:
6906 case ARM::VLD1LNdAsm_32: {
6908 // Shuffle the operands around so the lane index operand is in the
6911 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6912 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6913 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6914 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6915 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6916 TmpInst.addOperand(Inst.getOperand(1)); // lane
6917 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6918 TmpInst.addOperand(Inst.getOperand(5));
6923 case ARM::VLD2LNdAsm_8:
6924 case ARM::VLD2LNdAsm_16:
6925 case ARM::VLD2LNdAsm_32:
6926 case ARM::VLD2LNqAsm_16:
6927 case ARM::VLD2LNqAsm_32: {
6929 // Shuffle the operands around so the lane index operand is in the
6932 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6933 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6934 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6936 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6937 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6938 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6939 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6941 TmpInst.addOperand(Inst.getOperand(1)); // lane
6942 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6943 TmpInst.addOperand(Inst.getOperand(5));
6948 case ARM::VLD3LNdAsm_8:
6949 case ARM::VLD3LNdAsm_16:
6950 case ARM::VLD3LNdAsm_32:
6951 case ARM::VLD3LNqAsm_16:
6952 case ARM::VLD3LNqAsm_32: {
6954 // Shuffle the operands around so the lane index operand is in the
6957 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6958 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6959 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6961 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6963 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6964 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6965 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6966 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6968 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6970 TmpInst.addOperand(Inst.getOperand(1)); // lane
6971 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6972 TmpInst.addOperand(Inst.getOperand(5));
6977 case ARM::VLD4LNdAsm_8:
6978 case ARM::VLD4LNdAsm_16:
6979 case ARM::VLD4LNdAsm_32:
6980 case ARM::VLD4LNqAsm_16:
6981 case ARM::VLD4LNqAsm_32: {
6983 // Shuffle the operands around so the lane index operand is in the
6986 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6987 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6988 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6990 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6992 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6994 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6995 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6996 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6997 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6999 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7001 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7003 TmpInst.addOperand(Inst.getOperand(1)); // lane
7004 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7005 TmpInst.addOperand(Inst.getOperand(5));
7010 // VLD3DUP single 3-element structure to all lanes instructions.
7011 case ARM::VLD3DUPdAsm_8:
7012 case ARM::VLD3DUPdAsm_16:
7013 case ARM::VLD3DUPdAsm_32:
7014 case ARM::VLD3DUPqAsm_8:
7015 case ARM::VLD3DUPqAsm_16:
7016 case ARM::VLD3DUPqAsm_32: {
7019 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7020 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7021 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7023 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7025 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7026 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7027 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7028 TmpInst.addOperand(Inst.getOperand(4));
7033 case ARM::VLD3DUPdWB_fixed_Asm_8:
7034 case ARM::VLD3DUPdWB_fixed_Asm_16:
7035 case ARM::VLD3DUPdWB_fixed_Asm_32:
7036 case ARM::VLD3DUPqWB_fixed_Asm_8:
7037 case ARM::VLD3DUPqWB_fixed_Asm_16:
7038 case ARM::VLD3DUPqWB_fixed_Asm_32: {
7041 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7042 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7043 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7045 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7047 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7048 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7049 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7050 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7051 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7052 TmpInst.addOperand(Inst.getOperand(4));
7057 case ARM::VLD3DUPdWB_register_Asm_8:
7058 case ARM::VLD3DUPdWB_register_Asm_16:
7059 case ARM::VLD3DUPdWB_register_Asm_32:
7060 case ARM::VLD3DUPqWB_register_Asm_8:
7061 case ARM::VLD3DUPqWB_register_Asm_16:
7062 case ARM::VLD3DUPqWB_register_Asm_32: {
7065 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7066 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7067 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7069 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7071 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7072 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7073 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7074 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7075 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7076 TmpInst.addOperand(Inst.getOperand(5));
7081 // VLD3 multiple 3-element structure instructions.
7082 case ARM::VLD3dAsm_8:
7083 case ARM::VLD3dAsm_16:
7084 case ARM::VLD3dAsm_32:
7085 case ARM::VLD3qAsm_8:
7086 case ARM::VLD3qAsm_16:
7087 case ARM::VLD3qAsm_32: {
7090 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7091 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7092 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7094 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7096 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7097 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7098 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7099 TmpInst.addOperand(Inst.getOperand(4));
7104 case ARM::VLD3dWB_fixed_Asm_8:
7105 case ARM::VLD3dWB_fixed_Asm_16:
7106 case ARM::VLD3dWB_fixed_Asm_32:
7107 case ARM::VLD3qWB_fixed_Asm_8:
7108 case ARM::VLD3qWB_fixed_Asm_16:
7109 case ARM::VLD3qWB_fixed_Asm_32: {
7112 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7113 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7114 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7116 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7118 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7119 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7120 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7121 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7122 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7123 TmpInst.addOperand(Inst.getOperand(4));
7128 case ARM::VLD3dWB_register_Asm_8:
7129 case ARM::VLD3dWB_register_Asm_16:
7130 case ARM::VLD3dWB_register_Asm_32:
7131 case ARM::VLD3qWB_register_Asm_8:
7132 case ARM::VLD3qWB_register_Asm_16:
7133 case ARM::VLD3qWB_register_Asm_32: {
7136 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7137 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7138 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7140 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7142 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7143 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7144 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7145 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7146 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7147 TmpInst.addOperand(Inst.getOperand(5));
7152 // VLD4DUP single 3-element structure to all lanes instructions.
7153 case ARM::VLD4DUPdAsm_8:
7154 case ARM::VLD4DUPdAsm_16:
7155 case ARM::VLD4DUPdAsm_32:
7156 case ARM::VLD4DUPqAsm_8:
7157 case ARM::VLD4DUPqAsm_16:
7158 case ARM::VLD4DUPqAsm_32: {
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(1)); // Rn
7170 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7171 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7172 TmpInst.addOperand(Inst.getOperand(4));
7177 case ARM::VLD4DUPdWB_fixed_Asm_8:
7178 case ARM::VLD4DUPdWB_fixed_Asm_16:
7179 case ARM::VLD4DUPdWB_fixed_Asm_32:
7180 case ARM::VLD4DUPqWB_fixed_Asm_8:
7181 case ARM::VLD4DUPqWB_fixed_Asm_16:
7182 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7185 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7186 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7187 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7191 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7193 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7194 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7195 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7196 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7197 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7198 TmpInst.addOperand(Inst.getOperand(4));
7203 case ARM::VLD4DUPdWB_register_Asm_8:
7204 case ARM::VLD4DUPdWB_register_Asm_16:
7205 case ARM::VLD4DUPdWB_register_Asm_32:
7206 case ARM::VLD4DUPqWB_register_Asm_8:
7207 case ARM::VLD4DUPqWB_register_Asm_16:
7208 case ARM::VLD4DUPqWB_register_Asm_32: {
7211 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7212 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7213 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7215 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7217 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7219 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7220 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7221 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7222 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7223 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7224 TmpInst.addOperand(Inst.getOperand(5));
7229 // VLD4 multiple 4-element structure instructions.
7230 case ARM::VLD4dAsm_8:
7231 case ARM::VLD4dAsm_16:
7232 case ARM::VLD4dAsm_32:
7233 case ARM::VLD4qAsm_8:
7234 case ARM::VLD4qAsm_16:
7235 case ARM::VLD4qAsm_32: {
7238 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7239 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7240 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7242 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7244 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7246 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7247 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7248 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7249 TmpInst.addOperand(Inst.getOperand(4));
7254 case ARM::VLD4dWB_fixed_Asm_8:
7255 case ARM::VLD4dWB_fixed_Asm_16:
7256 case ARM::VLD4dWB_fixed_Asm_32:
7257 case ARM::VLD4qWB_fixed_Asm_8:
7258 case ARM::VLD4qWB_fixed_Asm_16:
7259 case ARM::VLD4qWB_fixed_Asm_32: {
7262 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7263 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7264 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7266 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7268 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7270 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7271 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7272 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7273 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7274 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7275 TmpInst.addOperand(Inst.getOperand(4));
7280 case ARM::VLD4dWB_register_Asm_8:
7281 case ARM::VLD4dWB_register_Asm_16:
7282 case ARM::VLD4dWB_register_Asm_32:
7283 case ARM::VLD4qWB_register_Asm_8:
7284 case ARM::VLD4qWB_register_Asm_16:
7285 case ARM::VLD4qWB_register_Asm_32: {
7288 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7289 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7290 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7292 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7296 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7297 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7298 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7299 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7300 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7301 TmpInst.addOperand(Inst.getOperand(5));
7306 // VST3 multiple 3-element structure instructions.
7307 case ARM::VST3dAsm_8:
7308 case ARM::VST3dAsm_16:
7309 case ARM::VST3dAsm_32:
7310 case ARM::VST3qAsm_8:
7311 case ARM::VST3qAsm_16:
7312 case ARM::VST3qAsm_32: {
7315 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7316 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7317 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7318 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7319 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7321 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7323 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7324 TmpInst.addOperand(Inst.getOperand(4));
7329 case ARM::VST3dWB_fixed_Asm_8:
7330 case ARM::VST3dWB_fixed_Asm_16:
7331 case ARM::VST3dWB_fixed_Asm_32:
7332 case ARM::VST3qWB_fixed_Asm_8:
7333 case ARM::VST3qWB_fixed_Asm_16:
7334 case ARM::VST3qWB_fixed_Asm_32: {
7337 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7338 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7339 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7340 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7341 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7342 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7343 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7345 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7347 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7348 TmpInst.addOperand(Inst.getOperand(4));
7353 case ARM::VST3dWB_register_Asm_8:
7354 case ARM::VST3dWB_register_Asm_16:
7355 case ARM::VST3dWB_register_Asm_32:
7356 case ARM::VST3qWB_register_Asm_8:
7357 case ARM::VST3qWB_register_Asm_16:
7358 case ARM::VST3qWB_register_Asm_32: {
7361 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7362 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7363 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7364 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7365 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7366 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7367 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7369 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7371 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7372 TmpInst.addOperand(Inst.getOperand(5));
7377 // VST4 multiple 3-element structure instructions.
7378 case ARM::VST4dAsm_8:
7379 case ARM::VST4dAsm_16:
7380 case ARM::VST4dAsm_32:
7381 case ARM::VST4qAsm_8:
7382 case ARM::VST4qAsm_16:
7383 case ARM::VST4qAsm_32: {
7386 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7387 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7388 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7389 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7390 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7392 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7394 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7396 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7397 TmpInst.addOperand(Inst.getOperand(4));
7402 case ARM::VST4dWB_fixed_Asm_8:
7403 case ARM::VST4dWB_fixed_Asm_16:
7404 case ARM::VST4dWB_fixed_Asm_32:
7405 case ARM::VST4qWB_fixed_Asm_8:
7406 case ARM::VST4qWB_fixed_Asm_16:
7407 case ARM::VST4qWB_fixed_Asm_32: {
7410 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7411 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7412 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7413 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7414 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7415 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7416 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7418 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7422 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7423 TmpInst.addOperand(Inst.getOperand(4));
7428 case ARM::VST4dWB_register_Asm_8:
7429 case ARM::VST4dWB_register_Asm_16:
7430 case ARM::VST4dWB_register_Asm_32:
7431 case ARM::VST4qWB_register_Asm_8:
7432 case ARM::VST4qWB_register_Asm_16:
7433 case ARM::VST4qWB_register_Asm_32: {
7436 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7437 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7438 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7439 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7440 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7441 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7442 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7444 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7446 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7448 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7449 TmpInst.addOperand(Inst.getOperand(5));
7454 // Handle encoding choice for the shift-immediate instructions.
7457 case ARM::t2ASRri: {
7458 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7459 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7460 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7461 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7462 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
7464 switch (Inst.getOpcode()) {
7465 default: llvm_unreachable("unexpected opcode");
7466 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7467 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7468 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7470 // The Thumb1 operands aren't in the same order. Awesome, eh?
7472 TmpInst.setOpcode(NewOpc);
7473 TmpInst.addOperand(Inst.getOperand(0));
7474 TmpInst.addOperand(Inst.getOperand(5));
7475 TmpInst.addOperand(Inst.getOperand(1));
7476 TmpInst.addOperand(Inst.getOperand(2));
7477 TmpInst.addOperand(Inst.getOperand(3));
7478 TmpInst.addOperand(Inst.getOperand(4));
7485 // Handle the Thumb2 mode MOV complex aliases.
7487 case ARM::t2MOVSsr: {
7488 // Which instruction to expand to depends on the CCOut operand and
7489 // whether we're in an IT block if the register operands are low
7491 bool isNarrow = false;
7492 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7493 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7494 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7495 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7496 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7500 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7501 default: llvm_unreachable("unexpected opcode!");
7502 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7503 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7504 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7505 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7507 TmpInst.setOpcode(newOpc);
7508 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7510 TmpInst.addOperand(MCOperand::CreateReg(
7511 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7512 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7513 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7514 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7515 TmpInst.addOperand(Inst.getOperand(5));
7517 TmpInst.addOperand(MCOperand::CreateReg(
7518 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7523 case ARM::t2MOVSsi: {
7524 // Which instruction to expand to depends on the CCOut operand and
7525 // whether we're in an IT block if the register operands are low
7527 bool isNarrow = false;
7528 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7529 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7530 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7534 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7535 default: llvm_unreachable("unexpected opcode!");
7536 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7537 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7538 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7539 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7540 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7542 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7543 if (Amount == 32) Amount = 0;
7544 TmpInst.setOpcode(newOpc);
7545 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7547 TmpInst.addOperand(MCOperand::CreateReg(
7548 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7549 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7550 if (newOpc != ARM::t2RRX)
7551 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7552 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7553 TmpInst.addOperand(Inst.getOperand(4));
7555 TmpInst.addOperand(MCOperand::CreateReg(
7556 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7560 // Handle the ARM mode MOV complex aliases.
7565 ARM_AM::ShiftOpc ShiftTy;
7566 switch(Inst.getOpcode()) {
7567 default: llvm_unreachable("unexpected opcode!");
7568 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7569 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7570 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7571 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7573 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7575 TmpInst.setOpcode(ARM::MOVsr);
7576 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7577 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7578 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7579 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7580 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7581 TmpInst.addOperand(Inst.getOperand(4));
7582 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7590 ARM_AM::ShiftOpc ShiftTy;
7591 switch(Inst.getOpcode()) {
7592 default: llvm_unreachable("unexpected opcode!");
7593 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7594 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7595 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7596 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7598 // A shift by zero is a plain MOVr, not a MOVsi.
7599 unsigned Amt = Inst.getOperand(2).getImm();
7600 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7601 // A shift by 32 should be encoded as 0 when permitted
7602 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7604 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7606 TmpInst.setOpcode(Opc);
7607 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7608 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7609 if (Opc == ARM::MOVsi)
7610 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7611 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7612 TmpInst.addOperand(Inst.getOperand(4));
7613 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7618 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7620 TmpInst.setOpcode(ARM::MOVsi);
7621 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7622 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7623 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7624 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7625 TmpInst.addOperand(Inst.getOperand(3));
7626 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7630 case ARM::t2LDMIA_UPD: {
7631 // If this is a load of a single register, then we should use
7632 // a post-indexed LDR instruction instead, per the ARM ARM.
7633 if (Inst.getNumOperands() != 5)
7636 TmpInst.setOpcode(ARM::t2LDR_POST);
7637 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7638 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7639 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7640 TmpInst.addOperand(MCOperand::CreateImm(4));
7641 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7642 TmpInst.addOperand(Inst.getOperand(3));
7646 case ARM::t2STMDB_UPD: {
7647 // If this is a store of a single register, then we should use
7648 // a pre-indexed STR instruction instead, per the ARM ARM.
7649 if (Inst.getNumOperands() != 5)
7652 TmpInst.setOpcode(ARM::t2STR_PRE);
7653 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7654 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7655 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7656 TmpInst.addOperand(MCOperand::CreateImm(-4));
7657 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7658 TmpInst.addOperand(Inst.getOperand(3));
7662 case ARM::LDMIA_UPD:
7663 // If this is a load of a single register via a 'pop', then we should use
7664 // a post-indexed LDR instruction instead, per the ARM ARM.
7665 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
7666 Inst.getNumOperands() == 5) {
7668 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7669 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7670 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7671 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7672 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7673 TmpInst.addOperand(MCOperand::CreateImm(4));
7674 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7675 TmpInst.addOperand(Inst.getOperand(3));
7680 case ARM::STMDB_UPD:
7681 // If this is a store of a single register via a 'push', then we should use
7682 // a pre-indexed STR instruction instead, per the ARM ARM.
7683 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
7684 Inst.getNumOperands() == 5) {
7686 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7687 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7688 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7689 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7690 TmpInst.addOperand(MCOperand::CreateImm(-4));
7691 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7692 TmpInst.addOperand(Inst.getOperand(3));
7696 case ARM::t2ADDri12:
7697 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7698 // mnemonic was used (not "addw"), encoding T3 is preferred.
7699 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
7700 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7702 Inst.setOpcode(ARM::t2ADDri);
7703 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7705 case ARM::t2SUBri12:
7706 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7707 // mnemonic was used (not "subw"), encoding T3 is preferred.
7708 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
7709 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7711 Inst.setOpcode(ARM::t2SUBri);
7712 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7715 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7716 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7717 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7718 // to encoding T1 if <Rd> is omitted."
7719 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7720 Inst.setOpcode(ARM::tADDi3);
7725 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7726 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7727 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7728 // to encoding T1 if <Rd> is omitted."
7729 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7730 Inst.setOpcode(ARM::tSUBi3);
7735 case ARM::t2SUBri: {
7736 // If the destination and first source operand are the same, and
7737 // the flags are compatible with the current IT status, use encoding T2
7738 // instead of T3. For compatibility with the system 'as'. Make sure the
7739 // wide encoding wasn't explicit.
7740 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7741 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7742 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7743 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7744 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7745 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7746 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
7749 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7750 ARM::tADDi8 : ARM::tSUBi8);
7751 TmpInst.addOperand(Inst.getOperand(0));
7752 TmpInst.addOperand(Inst.getOperand(5));
7753 TmpInst.addOperand(Inst.getOperand(0));
7754 TmpInst.addOperand(Inst.getOperand(2));
7755 TmpInst.addOperand(Inst.getOperand(3));
7756 TmpInst.addOperand(Inst.getOperand(4));
7760 case ARM::t2ADDrr: {
7761 // If the destination and first source operand are the same, and
7762 // there's no setting of the flags, use encoding T2 instead of T3.
7763 // Note that this is only for ADD, not SUB. This mirrors the system
7764 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7765 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7766 Inst.getOperand(5).getReg() != 0 ||
7767 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7768 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
7771 TmpInst.setOpcode(ARM::tADDhirr);
7772 TmpInst.addOperand(Inst.getOperand(0));
7773 TmpInst.addOperand(Inst.getOperand(0));
7774 TmpInst.addOperand(Inst.getOperand(2));
7775 TmpInst.addOperand(Inst.getOperand(3));
7776 TmpInst.addOperand(Inst.getOperand(4));
7780 case ARM::tADDrSP: {
7781 // If the non-SP source operand and the destination operand are not the
7782 // same, we need to use the 32-bit encoding if it's available.
7783 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7784 Inst.setOpcode(ARM::t2ADDrr);
7785 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7791 // A Thumb conditional branch outside of an IT block is a tBcc.
7792 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7793 Inst.setOpcode(ARM::tBcc);
7798 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7799 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7800 Inst.setOpcode(ARM::t2Bcc);
7805 // If the conditional is AL or we're in an IT block, we really want t2B.
7806 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7807 Inst.setOpcode(ARM::t2B);
7812 // If the conditional is AL, we really want tB.
7813 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7814 Inst.setOpcode(ARM::tB);
7819 // If the register list contains any high registers, or if the writeback
7820 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7821 // instead if we're in Thumb2. Otherwise, this should have generated
7822 // an error in validateInstruction().
7823 unsigned Rn = Inst.getOperand(0).getReg();
7824 bool hasWritebackToken =
7825 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7826 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
7827 bool listContainsBase;
7828 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7829 (!listContainsBase && !hasWritebackToken) ||
7830 (listContainsBase && hasWritebackToken)) {
7831 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7832 assert (isThumbTwo());
7833 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7834 // If we're switching to the updating version, we need to insert
7835 // the writeback tied operand.
7836 if (hasWritebackToken)
7837 Inst.insert(Inst.begin(),
7838 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7843 case ARM::tSTMIA_UPD: {
7844 // If the register list contains any high registers, we need to use
7845 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7846 // should have generated an error in validateInstruction().
7847 unsigned Rn = Inst.getOperand(0).getReg();
7848 bool listContainsBase;
7849 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7850 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7851 assert (isThumbTwo());
7852 Inst.setOpcode(ARM::t2STMIA_UPD);
7858 bool listContainsBase;
7859 // If the register list contains any high registers, we need to use
7860 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7861 // should have generated an error in validateInstruction().
7862 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7864 assert (isThumbTwo());
7865 Inst.setOpcode(ARM::t2LDMIA_UPD);
7866 // Add the base register and writeback operands.
7867 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7868 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7872 bool listContainsBase;
7873 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7875 assert (isThumbTwo());
7876 Inst.setOpcode(ARM::t2STMDB_UPD);
7877 // Add the base register and writeback operands.
7878 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7879 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7883 // If we can use the 16-bit encoding and the user didn't explicitly
7884 // request the 32-bit variant, transform it here.
7885 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7886 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7887 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7888 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7889 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7890 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7891 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
7892 // The operands aren't in the same order for tMOVi8...
7894 TmpInst.setOpcode(ARM::tMOVi8);
7895 TmpInst.addOperand(Inst.getOperand(0));
7896 TmpInst.addOperand(Inst.getOperand(4));
7897 TmpInst.addOperand(Inst.getOperand(1));
7898 TmpInst.addOperand(Inst.getOperand(2));
7899 TmpInst.addOperand(Inst.getOperand(3));
7906 // If we can use the 16-bit encoding and the user didn't explicitly
7907 // request the 32-bit variant, transform it here.
7908 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7909 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7910 Inst.getOperand(2).getImm() == ARMCC::AL &&
7911 Inst.getOperand(4).getReg() == ARM::CPSR &&
7912 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7913 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
7914 // The operands aren't the same for tMOV[S]r... (no cc_out)
7916 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7917 TmpInst.addOperand(Inst.getOperand(0));
7918 TmpInst.addOperand(Inst.getOperand(1));
7919 TmpInst.addOperand(Inst.getOperand(2));
7920 TmpInst.addOperand(Inst.getOperand(3));
7930 // If we can use the 16-bit encoding and the user didn't explicitly
7931 // request the 32-bit variant, transform it here.
7932 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7933 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7934 Inst.getOperand(2).getImm() == 0 &&
7935 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
7936 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
7938 switch (Inst.getOpcode()) {
7939 default: llvm_unreachable("Illegal opcode!");
7940 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7941 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7942 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7943 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7945 // The operands aren't the same for thumb1 (no rotate operand).
7947 TmpInst.setOpcode(NewOpc);
7948 TmpInst.addOperand(Inst.getOperand(0));
7949 TmpInst.addOperand(Inst.getOperand(1));
7950 TmpInst.addOperand(Inst.getOperand(3));
7951 TmpInst.addOperand(Inst.getOperand(4));
7958 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7959 // rrx shifts and asr/lsr of #32 is encoded as 0
7960 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7962 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7963 // Shifting by zero is accepted as a vanilla 'MOVr'
7965 TmpInst.setOpcode(ARM::MOVr);
7966 TmpInst.addOperand(Inst.getOperand(0));
7967 TmpInst.addOperand(Inst.getOperand(1));
7968 TmpInst.addOperand(Inst.getOperand(3));
7969 TmpInst.addOperand(Inst.getOperand(4));
7970 TmpInst.addOperand(Inst.getOperand(5));
7983 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7984 if (SOpc == ARM_AM::rrx) return false;
7985 switch (Inst.getOpcode()) {
7986 default: llvm_unreachable("unexpected opcode!");
7987 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7988 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7989 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7990 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7991 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7992 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7994 // If the shift is by zero, use the non-shifted instruction definition.
7995 // The exception is for right shifts, where 0 == 32
7996 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7997 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7999 TmpInst.setOpcode(newOpc);
8000 TmpInst.addOperand(Inst.getOperand(0));
8001 TmpInst.addOperand(Inst.getOperand(1));
8002 TmpInst.addOperand(Inst.getOperand(2));
8003 TmpInst.addOperand(Inst.getOperand(4));
8004 TmpInst.addOperand(Inst.getOperand(5));
8005 TmpInst.addOperand(Inst.getOperand(6));
8013 // The mask bits for all but the first condition are represented as
8014 // the low bit of the condition code value implies 't'. We currently
8015 // always have 1 implies 't', so XOR toggle the bits if the low bit
8016 // of the condition code is zero.
8017 MCOperand &MO = Inst.getOperand(1);
8018 unsigned Mask = MO.getImm();
8019 unsigned OrigMask = Mask;
8020 unsigned TZ = countTrailingZeros(Mask);
8021 if ((Inst.getOperand(0).getImm() & 1) == 0) {
8022 assert(Mask && TZ <= 3 && "illegal IT mask value!");
8023 Mask ^= (0xE << TZ) & 0xF;
8027 // Set up the IT block state according to the IT instruction we just
8029 assert(!inITBlock() && "nested IT blocks?!");
8030 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
8031 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
8032 ITState.CurPosition = 0;
8033 ITState.FirstCond = true;
8043 // Assemblers should use the narrow encodings of these instructions when permissible.
8044 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8045 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8046 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
8047 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
8048 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8049 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8050 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8053 switch (Inst.getOpcode()) {
8054 default: llvm_unreachable("unexpected opcode");
8055 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
8056 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
8057 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
8058 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
8059 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
8060 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
8063 TmpInst.setOpcode(NewOpc);
8064 TmpInst.addOperand(Inst.getOperand(0));
8065 TmpInst.addOperand(Inst.getOperand(5));
8066 TmpInst.addOperand(Inst.getOperand(1));
8067 TmpInst.addOperand(Inst.getOperand(2));
8068 TmpInst.addOperand(Inst.getOperand(3));
8069 TmpInst.addOperand(Inst.getOperand(4));
8080 // Assemblers should use the narrow encodings of these instructions when permissible.
8081 // These instructions are special in that they are commutable, so shorter encodings
8082 // are available more often.
8083 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8084 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8085 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
8086 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
8087 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
8088 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8089 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8090 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8093 switch (Inst.getOpcode()) {
8094 default: llvm_unreachable("unexpected opcode");
8095 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
8096 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
8097 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
8098 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
8101 TmpInst.setOpcode(NewOpc);
8102 TmpInst.addOperand(Inst.getOperand(0));
8103 TmpInst.addOperand(Inst.getOperand(5));
8104 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8105 TmpInst.addOperand(Inst.getOperand(1));
8106 TmpInst.addOperand(Inst.getOperand(2));
8108 TmpInst.addOperand(Inst.getOperand(2));
8109 TmpInst.addOperand(Inst.getOperand(1));
8111 TmpInst.addOperand(Inst.getOperand(3));
8112 TmpInst.addOperand(Inst.getOperand(4));
8122 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8123 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8124 // suffix depending on whether they're in an IT block or not.
8125 unsigned Opc = Inst.getOpcode();
8126 const MCInstrDesc &MCID = MII.get(Opc);
8127 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8128 assert(MCID.hasOptionalDef() &&
8129 "optionally flag setting instruction missing optional def operand");
8130 assert(MCID.NumOperands == Inst.getNumOperands() &&
8131 "operand count mismatch!");
8132 // Find the optional-def operand (cc_out).
8135 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8138 // If we're parsing Thumb1, reject it completely.
8139 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8140 return Match_MnemonicFail;
8141 // If we're parsing Thumb2, which form is legal depends on whether we're
8143 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8145 return Match_RequiresITBlock;
8146 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8148 return Match_RequiresNotITBlock;
8150 // Some high-register supporting Thumb1 encodings only allow both registers
8151 // to be from r0-r7 when in Thumb2.
8152 else if (Opc == ARM::tADDhirr && isThumbOne() &&
8153 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8154 isARMLowRegister(Inst.getOperand(2).getReg()))
8155 return Match_RequiresThumb2;
8156 // Others only require ARMv6 or later.
8157 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
8158 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8159 isARMLowRegister(Inst.getOperand(1).getReg()))
8160 return Match_RequiresV6;
8161 return Match_Success;
8165 template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
8166 return true; // In an assembly source, no need to second-guess
8170 static const char *getSubtargetFeatureName(uint64_t Val);
8171 bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8172 OperandVector &Operands,
8173 MCStreamer &Out, uint64_t &ErrorInfo,
8174 bool MatchingInlineAsm) {
8176 unsigned MatchResult;
8178 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
8180 switch (MatchResult) {
8183 // Context sensitive operand constraints aren't handled by the matcher,
8184 // so check them here.
8185 if (validateInstruction(Inst, Operands)) {
8186 // Still progress the IT block, otherwise one wrong condition causes
8187 // nasty cascading errors.
8188 forwardITPosition();
8192 { // processInstruction() updates inITBlock state, we need to save it away
8193 bool wasInITBlock = inITBlock();
8195 // Some instructions need post-processing to, for example, tweak which
8196 // encoding is selected. Loop on it while changes happen so the
8197 // individual transformations can chain off each other. E.g.,
8198 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
8199 while (processInstruction(Inst, Operands))
8202 // Only after the instruction is fully processed, we can validate it
8203 if (wasInITBlock && hasV8Ops() && isThumb() &&
8204 !isV8EligibleForIT(&Inst)) {
8205 Warning(IDLoc, "deprecated instruction in IT block");
8209 // Only move forward at the very end so that everything in validate
8210 // and process gets a consistent answer about whether we're in an IT
8212 forwardITPosition();
8214 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8215 // doesn't actually encode.
8216 if (Inst.getOpcode() == ARM::ITasm)
8220 Out.EmitInstruction(Inst, STI);
8222 case Match_MissingFeature: {
8223 assert(ErrorInfo && "Unknown missing feature!");
8224 // Special case the error message for the very common case where only
8225 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8226 std::string Msg = "instruction requires:";
8228 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8229 if (ErrorInfo & Mask) {
8231 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8235 return Error(IDLoc, Msg);
8237 case Match_InvalidOperand: {
8238 SMLoc ErrorLoc = IDLoc;
8239 if (ErrorInfo != ~0ULL) {
8240 if (ErrorInfo >= Operands.size())
8241 return Error(IDLoc, "too few operands for instruction");
8243 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
8244 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8247 return Error(ErrorLoc, "invalid operand for instruction");
8249 case Match_MnemonicFail:
8250 return Error(IDLoc, "invalid instruction",
8251 ((ARMOperand &)*Operands[0]).getLocRange());
8252 case Match_RequiresNotITBlock:
8253 return Error(IDLoc, "flag setting instruction only valid outside IT block");
8254 case Match_RequiresITBlock:
8255 return Error(IDLoc, "instruction only valid inside IT block");
8256 case Match_RequiresV6:
8257 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8258 case Match_RequiresThumb2:
8259 return Error(IDLoc, "instruction variant requires Thumb2");
8260 case Match_ImmRange0_15: {
8261 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
8262 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8263 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8265 case Match_ImmRange0_239: {
8266 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
8267 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8268 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8270 case Match_AlignedMemoryRequiresNone:
8271 case Match_DupAlignedMemoryRequiresNone:
8272 case Match_AlignedMemoryRequires16:
8273 case Match_DupAlignedMemoryRequires16:
8274 case Match_AlignedMemoryRequires32:
8275 case Match_DupAlignedMemoryRequires32:
8276 case Match_AlignedMemoryRequires64:
8277 case Match_DupAlignedMemoryRequires64:
8278 case Match_AlignedMemoryRequires64or128:
8279 case Match_DupAlignedMemoryRequires64or128:
8280 case Match_AlignedMemoryRequires64or128or256:
8282 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
8283 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8284 switch (MatchResult) {
8286 llvm_unreachable("Missing Match_Aligned type");
8287 case Match_AlignedMemoryRequiresNone:
8288 case Match_DupAlignedMemoryRequiresNone:
8289 return Error(ErrorLoc, "alignment must be omitted");
8290 case Match_AlignedMemoryRequires16:
8291 case Match_DupAlignedMemoryRequires16:
8292 return Error(ErrorLoc, "alignment must be 16 or omitted");
8293 case Match_AlignedMemoryRequires32:
8294 case Match_DupAlignedMemoryRequires32:
8295 return Error(ErrorLoc, "alignment must be 32 or omitted");
8296 case Match_AlignedMemoryRequires64:
8297 case Match_DupAlignedMemoryRequires64:
8298 return Error(ErrorLoc, "alignment must be 64 or omitted");
8299 case Match_AlignedMemoryRequires64or128:
8300 case Match_DupAlignedMemoryRequires64or128:
8301 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8302 case Match_AlignedMemoryRequires64or128or256:
8303 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8308 llvm_unreachable("Implement any new match types added!");
8311 /// parseDirective parses the arm specific directives
8312 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
8313 const MCObjectFileInfo::Environment Format =
8314 getContext().getObjectFileInfo()->getObjectFileType();
8315 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
8317 StringRef IDVal = DirectiveID.getIdentifier();
8318 if (IDVal == ".word")
8319 return parseLiteralValues(4, DirectiveID.getLoc());
8320 else if (IDVal == ".short" || IDVal == ".hword")
8321 return parseLiteralValues(2, DirectiveID.getLoc());
8322 else if (IDVal == ".thumb")
8323 return parseDirectiveThumb(DirectiveID.getLoc());
8324 else if (IDVal == ".arm")
8325 return parseDirectiveARM(DirectiveID.getLoc());
8326 else if (IDVal == ".thumb_func")
8327 return parseDirectiveThumbFunc(DirectiveID.getLoc());
8328 else if (IDVal == ".code")
8329 return parseDirectiveCode(DirectiveID.getLoc());
8330 else if (IDVal == ".syntax")
8331 return parseDirectiveSyntax(DirectiveID.getLoc());
8332 else if (IDVal == ".unreq")
8333 return parseDirectiveUnreq(DirectiveID.getLoc());
8334 else if (IDVal == ".fnend")
8335 return parseDirectiveFnEnd(DirectiveID.getLoc());
8336 else if (IDVal == ".cantunwind")
8337 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8338 else if (IDVal == ".personality")
8339 return parseDirectivePersonality(DirectiveID.getLoc());
8340 else if (IDVal == ".handlerdata")
8341 return parseDirectiveHandlerData(DirectiveID.getLoc());
8342 else if (IDVal == ".setfp")
8343 return parseDirectiveSetFP(DirectiveID.getLoc());
8344 else if (IDVal == ".pad")
8345 return parseDirectivePad(DirectiveID.getLoc());
8346 else if (IDVal == ".save")
8347 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8348 else if (IDVal == ".vsave")
8349 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
8350 else if (IDVal == ".ltorg" || IDVal == ".pool")
8351 return parseDirectiveLtorg(DirectiveID.getLoc());
8352 else if (IDVal == ".even")
8353 return parseDirectiveEven(DirectiveID.getLoc());
8354 else if (IDVal == ".personalityindex")
8355 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
8356 else if (IDVal == ".unwind_raw")
8357 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
8358 else if (IDVal == ".movsp")
8359 return parseDirectiveMovSP(DirectiveID.getLoc());
8360 else if (IDVal == ".arch_extension")
8361 return parseDirectiveArchExtension(DirectiveID.getLoc());
8362 else if (IDVal == ".align")
8363 return parseDirectiveAlign(DirectiveID.getLoc());
8364 else if (IDVal == ".thumb_set")
8365 return parseDirectiveThumbSet(DirectiveID.getLoc());
8368 if (IDVal == ".arch")
8369 return parseDirectiveArch(DirectiveID.getLoc());
8370 else if (IDVal == ".cpu")
8371 return parseDirectiveCPU(DirectiveID.getLoc());
8372 else if (IDVal == ".eabi_attribute")
8373 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8374 else if (IDVal == ".fpu")
8375 return parseDirectiveFPU(DirectiveID.getLoc());
8376 else if (IDVal == ".fnstart")
8377 return parseDirectiveFnStart(DirectiveID.getLoc());
8378 else if (IDVal == ".inst")
8379 return parseDirectiveInst(DirectiveID.getLoc());
8380 else if (IDVal == ".inst.n")
8381 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8382 else if (IDVal == ".inst.w")
8383 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8384 else if (IDVal == ".object_arch")
8385 return parseDirectiveObjectArch(DirectiveID.getLoc());
8386 else if (IDVal == ".tlsdescseq")
8387 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8393 /// parseLiteralValues
8394 /// ::= .hword expression [, expression]*
8395 /// ::= .short expression [, expression]*
8396 /// ::= .word expression [, expression]*
8397 bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
8398 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8400 const MCExpr *Value;
8401 if (getParser().parseExpression(Value)) {
8402 Parser.eatToEndOfStatement();
8406 getParser().getStreamer().EmitValue(Value, Size);
8408 if (getLexer().is(AsmToken::EndOfStatement))
8411 // FIXME: Improve diagnostic.
8412 if (getLexer().isNot(AsmToken::Comma)) {
8413 Error(L, "unexpected token in directive");
8424 /// parseDirectiveThumb
8426 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
8427 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8428 Error(L, "unexpected token in directive");
8434 Error(L, "target does not support Thumb mode");
8441 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8445 /// parseDirectiveARM
8447 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
8448 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8449 Error(L, "unexpected token in directive");
8455 Error(L, "target does not support ARM mode");
8462 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8466 void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8467 if (NextSymbolIsThumb) {
8468 getParser().getStreamer().EmitThumbFunc(Symbol);
8469 NextSymbolIsThumb = false;
8473 /// parseDirectiveThumbFunc
8474 /// ::= .thumbfunc symbol_name
8475 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
8476 const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
8477 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
8479 // Darwin asm has (optionally) function name after .thumb_func direction
8482 const AsmToken &Tok = Parser.getTok();
8483 if (Tok.isNot(AsmToken::EndOfStatement)) {
8484 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8485 Error(L, "unexpected token in .thumb_func directive");
8490 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8491 getParser().getStreamer().EmitThumbFunc(Func);
8492 Parser.Lex(); // Consume the identifier token.
8497 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8498 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8499 Parser.eatToEndOfStatement();
8503 NextSymbolIsThumb = true;
8507 /// parseDirectiveSyntax
8508 /// ::= .syntax unified | divided
8509 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
8510 const AsmToken &Tok = Parser.getTok();
8511 if (Tok.isNot(AsmToken::Identifier)) {
8512 Error(L, "unexpected token in .syntax directive");
8516 StringRef Mode = Tok.getString();
8517 if (Mode == "unified" || Mode == "UNIFIED") {
8519 } else if (Mode == "divided" || Mode == "DIVIDED") {
8520 Error(L, "'.syntax divided' arm asssembly not supported");
8523 Error(L, "unrecognized syntax mode in .syntax directive");
8527 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8528 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8533 // TODO tell the MC streamer the mode
8534 // getParser().getStreamer().Emit???();
8538 /// parseDirectiveCode
8539 /// ::= .code 16 | 32
8540 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
8541 const AsmToken &Tok = Parser.getTok();
8542 if (Tok.isNot(AsmToken::Integer)) {
8543 Error(L, "unexpected token in .code directive");
8546 int64_t Val = Parser.getTok().getIntVal();
8547 if (Val != 16 && Val != 32) {
8548 Error(L, "invalid operand to .code directive");
8553 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8554 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8561 Error(L, "target does not support Thumb mode");
8567 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8570 Error(L, "target does not support ARM mode");
8576 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8582 /// parseDirectiveReq
8583 /// ::= name .req registername
8584 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8585 Parser.Lex(); // Eat the '.req' token.
8587 SMLoc SRegLoc, ERegLoc;
8588 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
8589 Parser.eatToEndOfStatement();
8590 Error(SRegLoc, "register name expected");
8594 // Shouldn't be anything else.
8595 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
8596 Parser.eatToEndOfStatement();
8597 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8601 Parser.Lex(); // Consume the EndOfStatement
8603 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) {
8604 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8611 /// parseDirectiveUneq
8612 /// ::= .unreq registername
8613 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8614 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8615 Parser.eatToEndOfStatement();
8616 Error(L, "unexpected input in .unreq directive.");
8619 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
8620 Parser.Lex(); // Eat the identifier.
8624 /// parseDirectiveArch
8626 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8627 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8629 unsigned ID = StringSwitch<unsigned>(Arch)
8630 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8631 .Case(NAME, ARM::ID)
8632 #define ARM_ARCH_ALIAS(NAME, ID) \
8633 .Case(NAME, ARM::ID)
8634 #include "MCTargetDesc/ARMArchName.def"
8635 .Default(ARM::INVALID_ARCH);
8637 if (ID == ARM::INVALID_ARCH) {
8638 Error(L, "Unknown arch name");
8642 getTargetStreamer().emitArch(ID);
8646 /// parseDirectiveEabiAttr
8647 /// ::= .eabi_attribute int, int [, "str"]
8648 /// ::= .eabi_attribute Tag_name, int [, "str"]
8649 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8652 TagLoc = Parser.getTok().getLoc();
8653 if (Parser.getTok().is(AsmToken::Identifier)) {
8654 StringRef Name = Parser.getTok().getIdentifier();
8655 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
8657 Error(TagLoc, "attribute name not recognised: " + Name);
8658 Parser.eatToEndOfStatement();
8663 const MCExpr *AttrExpr;
8665 TagLoc = Parser.getTok().getLoc();
8666 if (Parser.parseExpression(AttrExpr)) {
8667 Parser.eatToEndOfStatement();
8671 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
8673 Error(TagLoc, "expected numeric constant");
8674 Parser.eatToEndOfStatement();
8678 Tag = CE->getValue();
8681 if (Parser.getTok().isNot(AsmToken::Comma)) {
8682 Error(Parser.getTok().getLoc(), "comma expected");
8683 Parser.eatToEndOfStatement();
8686 Parser.Lex(); // skip comma
8688 StringRef StringValue = "";
8689 bool IsStringValue = false;
8691 int64_t IntegerValue = 0;
8692 bool IsIntegerValue = false;
8694 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
8695 IsStringValue = true;
8696 else if (Tag == ARMBuildAttrs::compatibility) {
8697 IsStringValue = true;
8698 IsIntegerValue = true;
8699 } else if (Tag < 32 || Tag % 2 == 0)
8700 IsIntegerValue = true;
8701 else if (Tag % 2 == 1)
8702 IsStringValue = true;
8704 llvm_unreachable("invalid tag type");
8706 if (IsIntegerValue) {
8707 const MCExpr *ValueExpr;
8708 SMLoc ValueExprLoc = Parser.getTok().getLoc();
8709 if (Parser.parseExpression(ValueExpr)) {
8710 Parser.eatToEndOfStatement();
8714 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
8716 Error(ValueExprLoc, "expected numeric constant");
8717 Parser.eatToEndOfStatement();
8721 IntegerValue = CE->getValue();
8724 if (Tag == ARMBuildAttrs::compatibility) {
8725 if (Parser.getTok().isNot(AsmToken::Comma))
8726 IsStringValue = false;
8731 if (IsStringValue) {
8732 if (Parser.getTok().isNot(AsmToken::String)) {
8733 Error(Parser.getTok().getLoc(), "bad string constant");
8734 Parser.eatToEndOfStatement();
8738 StringValue = Parser.getTok().getStringContents();
8742 if (IsIntegerValue && IsStringValue) {
8743 assert(Tag == ARMBuildAttrs::compatibility);
8744 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
8745 } else if (IsIntegerValue)
8746 getTargetStreamer().emitAttribute(Tag, IntegerValue);
8747 else if (IsStringValue)
8748 getTargetStreamer().emitTextAttribute(Tag, StringValue);
8752 /// parseDirectiveCPU
8754 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8755 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8756 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8760 // FIXME: This is duplicated in getARMFPUFeatures() in
8761 // tools/clang/lib/Driver/Tools.cpp
8762 static const struct {
8764 const uint64_t Enabled;
8765 const uint64_t Disabled;
8767 {ARM::VFP, ARM::FeatureVFP2, ARM::FeatureNEON},
8768 {ARM::VFPV2, ARM::FeatureVFP2, ARM::FeatureNEON},
8769 {ARM::VFPV3, ARM::FeatureVFP3, ARM::FeatureNEON},
8770 {ARM::VFPV3_D16, ARM::FeatureVFP3 | ARM::FeatureD16, ARM::FeatureNEON},
8771 {ARM::VFPV4, ARM::FeatureVFP4, ARM::FeatureNEON},
8772 {ARM::VFPV4_D16, ARM::FeatureVFP4 | ARM::FeatureD16, ARM::FeatureNEON},
8773 {ARM::FP_ARMV8, ARM::FeatureFPARMv8,
8774 ARM::FeatureNEON | ARM::FeatureCrypto},
8775 {ARM::NEON, ARM::FeatureNEON, 0},
8776 {ARM::NEON_VFPV4, ARM::FeatureVFP4 | ARM::FeatureNEON, 0},
8777 {ARM::NEON_FP_ARMV8, ARM::FeatureFPARMv8 | ARM::FeatureNEON,
8778 ARM::FeatureCrypto},
8779 {ARM::CRYPTO_NEON_FP_ARMV8,
8780 ARM::FeatureFPARMv8 | ARM::FeatureNEON | ARM::FeatureCrypto, 0},
8781 {ARM::SOFTVFP, 0, 0},
8784 /// parseDirectiveFPU
8786 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8787 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8789 unsigned ID = StringSwitch<unsigned>(FPU)
8790 #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8791 #include "ARMFPUName.def"
8792 .Default(ARM::INVALID_FPU);
8794 if (ID == ARM::INVALID_FPU) {
8795 Error(L, "Unknown FPU name");
8799 for (const auto &Fpu : Fpus) {
8803 // Need to toggle features that should be on but are off and that
8804 // should off but are on.
8805 uint64_t Toggle = (Fpu.Enabled & ~STI.getFeatureBits()) |
8806 (Fpu.Disabled & STI.getFeatureBits());
8807 setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle)));
8811 getTargetStreamer().emitFPU(ID);
8815 /// parseDirectiveFnStart
8817 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8818 if (UC.hasFnStart()) {
8819 Error(L, ".fnstart starts before the end of previous one");
8820 UC.emitFnStartLocNotes();
8824 // Reset the unwind directives parser state
8827 getTargetStreamer().emitFnStart();
8829 UC.recordFnStart(L);
8833 /// parseDirectiveFnEnd
8835 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8836 // Check the ordering of unwind directives
8837 if (!UC.hasFnStart()) {
8838 Error(L, ".fnstart must precede .fnend directive");
8842 // Reset the unwind directives parser state
8843 getTargetStreamer().emitFnEnd();
8849 /// parseDirectiveCantUnwind
8851 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8852 UC.recordCantUnwind(L);
8854 // Check the ordering of unwind directives
8855 if (!UC.hasFnStart()) {
8856 Error(L, ".fnstart must precede .cantunwind directive");
8859 if (UC.hasHandlerData()) {
8860 Error(L, ".cantunwind can't be used with .handlerdata directive");
8861 UC.emitHandlerDataLocNotes();
8864 if (UC.hasPersonality()) {
8865 Error(L, ".cantunwind can't be used with .personality directive");
8866 UC.emitPersonalityLocNotes();
8870 getTargetStreamer().emitCantUnwind();
8874 /// parseDirectivePersonality
8875 /// ::= .personality name
8876 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8877 bool HasExistingPersonality = UC.hasPersonality();
8879 UC.recordPersonality(L);
8881 // Check the ordering of unwind directives
8882 if (!UC.hasFnStart()) {
8883 Error(L, ".fnstart must precede .personality directive");
8886 if (UC.cantUnwind()) {
8887 Error(L, ".personality can't be used with .cantunwind directive");
8888 UC.emitCantUnwindLocNotes();
8891 if (UC.hasHandlerData()) {
8892 Error(L, ".personality must precede .handlerdata directive");
8893 UC.emitHandlerDataLocNotes();
8896 if (HasExistingPersonality) {
8897 Parser.eatToEndOfStatement();
8898 Error(L, "multiple personality directives");
8899 UC.emitPersonalityLocNotes();
8903 // Parse the name of the personality routine
8904 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8905 Parser.eatToEndOfStatement();
8906 Error(L, "unexpected input in .personality directive.");
8909 StringRef Name(Parser.getTok().getIdentifier());
8912 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8913 getTargetStreamer().emitPersonality(PR);
8917 /// parseDirectiveHandlerData
8918 /// ::= .handlerdata
8919 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8920 UC.recordHandlerData(L);
8922 // Check the ordering of unwind directives
8923 if (!UC.hasFnStart()) {
8924 Error(L, ".fnstart must precede .personality directive");
8927 if (UC.cantUnwind()) {
8928 Error(L, ".handlerdata can't be used with .cantunwind directive");
8929 UC.emitCantUnwindLocNotes();
8933 getTargetStreamer().emitHandlerData();
8937 /// parseDirectiveSetFP
8938 /// ::= .setfp fpreg, spreg [, offset]
8939 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8940 // Check the ordering of unwind directives
8941 if (!UC.hasFnStart()) {
8942 Error(L, ".fnstart must precede .setfp directive");
8945 if (UC.hasHandlerData()) {
8946 Error(L, ".setfp must precede .handlerdata directive");
8951 SMLoc FPRegLoc = Parser.getTok().getLoc();
8952 int FPReg = tryParseRegister();
8954 Error(FPRegLoc, "frame pointer register expected");
8959 if (Parser.getTok().isNot(AsmToken::Comma)) {
8960 Error(Parser.getTok().getLoc(), "comma expected");
8963 Parser.Lex(); // skip comma
8966 SMLoc SPRegLoc = Parser.getTok().getLoc();
8967 int SPReg = tryParseRegister();
8969 Error(SPRegLoc, "stack pointer register expected");
8973 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
8974 Error(SPRegLoc, "register should be either $sp or the latest fp register");
8978 // Update the frame pointer register
8979 UC.saveFPReg(FPReg);
8983 if (Parser.getTok().is(AsmToken::Comma)) {
8984 Parser.Lex(); // skip comma
8986 if (Parser.getTok().isNot(AsmToken::Hash) &&
8987 Parser.getTok().isNot(AsmToken::Dollar)) {
8988 Error(Parser.getTok().getLoc(), "'#' expected");
8991 Parser.Lex(); // skip hash token.
8993 const MCExpr *OffsetExpr;
8994 SMLoc ExLoc = Parser.getTok().getLoc();
8996 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8997 Error(ExLoc, "malformed setfp offset");
9000 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9002 Error(ExLoc, "setfp offset must be an immediate");
9006 Offset = CE->getValue();
9009 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
9010 static_cast<unsigned>(SPReg), Offset);
9016 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
9017 // Check the ordering of unwind directives
9018 if (!UC.hasFnStart()) {
9019 Error(L, ".fnstart must precede .pad directive");
9022 if (UC.hasHandlerData()) {
9023 Error(L, ".pad must precede .handlerdata directive");
9028 if (Parser.getTok().isNot(AsmToken::Hash) &&
9029 Parser.getTok().isNot(AsmToken::Dollar)) {
9030 Error(Parser.getTok().getLoc(), "'#' expected");
9033 Parser.Lex(); // skip hash token.
9035 const MCExpr *OffsetExpr;
9036 SMLoc ExLoc = Parser.getTok().getLoc();
9038 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9039 Error(ExLoc, "malformed pad offset");
9042 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9044 Error(ExLoc, "pad offset must be an immediate");
9048 getTargetStreamer().emitPad(CE->getValue());
9052 /// parseDirectiveRegSave
9053 /// ::= .save { registers }
9054 /// ::= .vsave { registers }
9055 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
9056 // Check the ordering of unwind directives
9057 if (!UC.hasFnStart()) {
9058 Error(L, ".fnstart must precede .save or .vsave directives");
9061 if (UC.hasHandlerData()) {
9062 Error(L, ".save or .vsave must precede .handlerdata directive");
9066 // RAII object to make sure parsed operands are deleted.
9067 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
9069 // Parse the register list
9070 if (parseRegisterList(Operands))
9072 ARMOperand &Op = (ARMOperand &)*Operands[0];
9073 if (!IsVector && !Op.isRegList()) {
9074 Error(L, ".save expects GPR registers");
9077 if (IsVector && !Op.isDPRRegList()) {
9078 Error(L, ".vsave expects DPR registers");
9082 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
9086 /// parseDirectiveInst
9087 /// ::= .inst opcode [, ...]
9088 /// ::= .inst.n opcode [, ...]
9089 /// ::= .inst.w opcode [, ...]
9090 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
9102 Parser.eatToEndOfStatement();
9103 Error(Loc, "cannot determine Thumb instruction size, "
9104 "use inst.n/inst.w instead");
9109 Parser.eatToEndOfStatement();
9110 Error(Loc, "width suffixes are invalid in ARM mode");
9116 if (getLexer().is(AsmToken::EndOfStatement)) {
9117 Parser.eatToEndOfStatement();
9118 Error(Loc, "expected expression following directive");
9125 if (getParser().parseExpression(Expr)) {
9126 Error(Loc, "expected expression");
9130 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
9132 Error(Loc, "expected constant expression");
9138 if (Value->getValue() > 0xffff) {
9139 Error(Loc, "inst.n operand is too big, use inst.w instead");
9144 if (Value->getValue() > 0xffffffff) {
9146 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9151 llvm_unreachable("only supported widths are 2 and 4");
9154 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9156 if (getLexer().is(AsmToken::EndOfStatement))
9159 if (getLexer().isNot(AsmToken::Comma)) {
9160 Error(Loc, "unexpected token in directive");
9171 /// parseDirectiveLtorg
9172 /// ::= .ltorg | .pool
9173 bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
9174 getTargetStreamer().emitCurrentConstantPool();
9178 bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9179 const MCSection *Section = getStreamer().getCurrentSection().first;
9181 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9182 TokError("unexpected token in directive");
9187 getStreamer().InitSections();
9188 Section = getStreamer().getCurrentSection().first;
9191 assert(Section && "must have section to emit alignment");
9192 if (Section->UseCodeAlign())
9193 getStreamer().EmitCodeAlignment(2);
9195 getStreamer().EmitValueToAlignment(2);
9200 /// parseDirectivePersonalityIndex
9201 /// ::= .personalityindex index
9202 bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
9203 bool HasExistingPersonality = UC.hasPersonality();
9205 UC.recordPersonalityIndex(L);
9207 if (!UC.hasFnStart()) {
9208 Parser.eatToEndOfStatement();
9209 Error(L, ".fnstart must precede .personalityindex directive");
9212 if (UC.cantUnwind()) {
9213 Parser.eatToEndOfStatement();
9214 Error(L, ".personalityindex cannot be used with .cantunwind");
9215 UC.emitCantUnwindLocNotes();
9218 if (UC.hasHandlerData()) {
9219 Parser.eatToEndOfStatement();
9220 Error(L, ".personalityindex must precede .handlerdata directive");
9221 UC.emitHandlerDataLocNotes();
9224 if (HasExistingPersonality) {
9225 Parser.eatToEndOfStatement();
9226 Error(L, "multiple personality directives");
9227 UC.emitPersonalityLocNotes();
9231 const MCExpr *IndexExpression;
9232 SMLoc IndexLoc = Parser.getTok().getLoc();
9233 if (Parser.parseExpression(IndexExpression)) {
9234 Parser.eatToEndOfStatement();
9238 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9240 Parser.eatToEndOfStatement();
9241 Error(IndexLoc, "index must be a constant number");
9244 if (CE->getValue() < 0 ||
9245 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9246 Parser.eatToEndOfStatement();
9247 Error(IndexLoc, "personality routine index should be in range [0-3]");
9251 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9255 /// parseDirectiveUnwindRaw
9256 /// ::= .unwind_raw offset, opcode [, opcode...]
9257 bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
9258 if (!UC.hasFnStart()) {
9259 Parser.eatToEndOfStatement();
9260 Error(L, ".fnstart must precede .unwind_raw directives");
9264 int64_t StackOffset;
9266 const MCExpr *OffsetExpr;
9267 SMLoc OffsetLoc = getLexer().getLoc();
9268 if (getLexer().is(AsmToken::EndOfStatement) ||
9269 getParser().parseExpression(OffsetExpr)) {
9270 Error(OffsetLoc, "expected expression");
9271 Parser.eatToEndOfStatement();
9275 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9277 Error(OffsetLoc, "offset must be a constant");
9278 Parser.eatToEndOfStatement();
9282 StackOffset = CE->getValue();
9284 if (getLexer().isNot(AsmToken::Comma)) {
9285 Error(getLexer().getLoc(), "expected comma");
9286 Parser.eatToEndOfStatement();
9291 SmallVector<uint8_t, 16> Opcodes;
9295 SMLoc OpcodeLoc = getLexer().getLoc();
9296 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9297 Error(OpcodeLoc, "expected opcode expression");
9298 Parser.eatToEndOfStatement();
9302 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9304 Error(OpcodeLoc, "opcode value must be a constant");
9305 Parser.eatToEndOfStatement();
9309 const int64_t Opcode = OC->getValue();
9310 if (Opcode & ~0xff) {
9311 Error(OpcodeLoc, "invalid opcode");
9312 Parser.eatToEndOfStatement();
9316 Opcodes.push_back(uint8_t(Opcode));
9318 if (getLexer().is(AsmToken::EndOfStatement))
9321 if (getLexer().isNot(AsmToken::Comma)) {
9322 Error(getLexer().getLoc(), "unexpected token in directive");
9323 Parser.eatToEndOfStatement();
9330 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9336 /// parseDirectiveTLSDescSeq
9337 /// ::= .tlsdescseq tls-variable
9338 bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
9339 if (getLexer().isNot(AsmToken::Identifier)) {
9340 TokError("expected variable after '.tlsdescseq' directive");
9341 Parser.eatToEndOfStatement();
9345 const MCSymbolRefExpr *SRE =
9346 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9347 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9350 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9351 Error(Parser.getTok().getLoc(), "unexpected token");
9352 Parser.eatToEndOfStatement();
9356 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9360 /// parseDirectiveMovSP
9361 /// ::= .movsp reg [, #offset]
9362 bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
9363 if (!UC.hasFnStart()) {
9364 Parser.eatToEndOfStatement();
9365 Error(L, ".fnstart must precede .movsp directives");
9368 if (UC.getFPReg() != ARM::SP) {
9369 Parser.eatToEndOfStatement();
9370 Error(L, "unexpected .movsp directive");
9374 SMLoc SPRegLoc = Parser.getTok().getLoc();
9375 int SPReg = tryParseRegister();
9377 Parser.eatToEndOfStatement();
9378 Error(SPRegLoc, "register expected");
9382 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9383 Parser.eatToEndOfStatement();
9384 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9389 if (Parser.getTok().is(AsmToken::Comma)) {
9392 if (Parser.getTok().isNot(AsmToken::Hash)) {
9393 Error(Parser.getTok().getLoc(), "expected #constant");
9394 Parser.eatToEndOfStatement();
9399 const MCExpr *OffsetExpr;
9400 SMLoc OffsetLoc = Parser.getTok().getLoc();
9401 if (Parser.parseExpression(OffsetExpr)) {
9402 Parser.eatToEndOfStatement();
9403 Error(OffsetLoc, "malformed offset expression");
9407 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9409 Parser.eatToEndOfStatement();
9410 Error(OffsetLoc, "offset must be an immediate constant");
9414 Offset = CE->getValue();
9417 getTargetStreamer().emitMovSP(SPReg, Offset);
9418 UC.saveFPReg(SPReg);
9423 /// parseDirectiveObjectArch
9424 /// ::= .object_arch name
9425 bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
9426 if (getLexer().isNot(AsmToken::Identifier)) {
9427 Error(getLexer().getLoc(), "unexpected token");
9428 Parser.eatToEndOfStatement();
9432 StringRef Arch = Parser.getTok().getString();
9433 SMLoc ArchLoc = Parser.getTok().getLoc();
9436 unsigned ID = StringSwitch<unsigned>(Arch)
9437 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9438 .Case(NAME, ARM::ID)
9439 #define ARM_ARCH_ALIAS(NAME, ID) \
9440 .Case(NAME, ARM::ID)
9441 #include "MCTargetDesc/ARMArchName.def"
9442 #undef ARM_ARCH_NAME
9443 #undef ARM_ARCH_ALIAS
9444 .Default(ARM::INVALID_ARCH);
9446 if (ID == ARM::INVALID_ARCH) {
9447 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9448 Parser.eatToEndOfStatement();
9452 getTargetStreamer().emitObjectArch(ID);
9454 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9455 Error(getLexer().getLoc(), "unexpected token");
9456 Parser.eatToEndOfStatement();
9462 /// parseDirectiveAlign
9464 bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9465 // NOTE: if this is not the end of the statement, fall back to the target
9466 // agnostic handling for this directive which will correctly handle this.
9467 if (getLexer().isNot(AsmToken::EndOfStatement))
9470 // '.align' is target specifically handled to mean 2**2 byte alignment.
9471 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9472 getStreamer().EmitCodeAlignment(4, 0);
9474 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9479 /// parseDirectiveThumbSet
9480 /// ::= .thumb_set name, value
9481 bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
9483 if (Parser.parseIdentifier(Name)) {
9484 TokError("expected identifier after '.thumb_set'");
9485 Parser.eatToEndOfStatement();
9489 if (getLexer().isNot(AsmToken::Comma)) {
9490 TokError("expected comma after name '" + Name + "'");
9491 Parser.eatToEndOfStatement();
9496 const MCExpr *Value;
9497 if (Parser.parseExpression(Value)) {
9498 TokError("missing expression");
9499 Parser.eatToEndOfStatement();
9503 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9504 TokError("unexpected token");
9505 Parser.eatToEndOfStatement();
9510 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
9511 getTargetStreamer().emitThumbSet(Alias, Value);
9515 /// Force static initialization.
9516 extern "C" void LLVMInitializeARMAsmParser() {
9517 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9518 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9519 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9520 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
9523 #define GET_REGISTER_MATCHER
9524 #define GET_SUBTARGET_FEATURE_NAME
9525 #define GET_MATCHER_IMPLEMENTATION
9526 #include "ARMGenAsmMatcher.inc"
9528 static const struct {
9530 const unsigned ArchCheck;
9531 const uint64_t Features;
9533 { "crc", Feature_HasV8, ARM::FeatureCRC },
9534 { "crypto", Feature_HasV8,
9535 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9536 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
9537 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
9538 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
9539 // FIXME: iWMMXT not supported
9540 { "iwmmxt", Feature_None, 0 },
9541 // FIXME: iWMMXT2 not supported
9542 { "iwmmxt2", Feature_None, 0 },
9543 // FIXME: Maverick not supported
9544 { "maverick", Feature_None, 0 },
9545 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
9546 // FIXME: ARMv6-m OS Extensions feature not checked
9547 { "os", Feature_None, 0 },
9548 // FIXME: Also available in ARMv6-K
9549 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
9550 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
9551 // FIXME: Only available in A-class, isel not predicated
9552 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
9553 // FIXME: xscale not supported
9554 { "xscale", Feature_None, 0 },
9557 /// parseDirectiveArchExtension
9558 /// ::= .arch_extension [no]feature
9559 bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
9560 if (getLexer().isNot(AsmToken::Identifier)) {
9561 Error(getLexer().getLoc(), "unexpected token");
9562 Parser.eatToEndOfStatement();
9566 StringRef Name = Parser.getTok().getString();
9567 SMLoc ExtLoc = Parser.getTok().getLoc();
9570 bool EnableFeature = true;
9571 if (Name.startswith_lower("no")) {
9572 EnableFeature = false;
9573 Name = Name.substr(2);
9576 for (const auto &Extension : Extensions) {
9577 if (Extension.Name != Name)
9580 if (!Extension.Features)
9581 report_fatal_error("unsupported architectural extension: " + Name);
9583 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) {
9584 Error(ExtLoc, "architectural extension '" + Name + "' is not "
9585 "allowed for the current base architecture");
9589 uint64_t ToggleFeatures = EnableFeature
9590 ? (~STI.getFeatureBits() & Extension.Features)
9591 : ( STI.getFeatureBits() & Extension.Features);
9593 ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
9594 setAvailableFeatures(Features);
9598 Error(ExtLoc, "unknown architectural extension: " + Name);
9599 Parser.eatToEndOfStatement();
9603 // Define this matcher function after the auto-generated include so we
9604 // have the match class enum definitions.
9605 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
9607 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
9608 // If the kind is a token for a literal immediate, check if our asm
9609 // operand matches. This is for InstAliases which have a fixed-value
9610 // immediate in the syntax.
9615 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
9616 if (CE->getValue() == 0)
9617 return Match_Success;
9621 const MCExpr *SOExpr = Op.getImm();
9623 if (!SOExpr->EvaluateAsAbsolute(Value))
9624 return Match_Success;
9625 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
9626 "expression value must be representable in 32 bits");
9631 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
9632 return Match_Success;
9635 return Match_InvalidOperand;