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 "llvm/MC/MCTargetAsmParser.h"
13 #include "MCTargetDesc/ARMAddressingModes.h"
14 #include "MCTargetDesc/ARMBuildAttrs.h"
15 #include "MCTargetDesc/ARMArchName.h"
16 #include "MCTargetDesc/ARMBaseInfo.h"
17 #include "MCTargetDesc/ARMMCExpr.h"
18 #include "llvm/ADT/BitVector.h"
19 #include "llvm/ADT/MapVector.h"
20 #include "llvm/ADT/OwningPtr.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringExtras.h"
24 #include "llvm/ADT/StringSwitch.h"
25 #include "llvm/ADT/Twine.h"
26 #include "llvm/MC/MCAsmInfo.h"
27 #include "llvm/MC/MCAssembler.h"
28 #include "llvm/MC/MCContext.h"
29 #include "llvm/MC/MCDisassembler.h"
30 #include "llvm/MC/MCELFStreamer.h"
31 #include "llvm/MC/MCExpr.h"
32 #include "llvm/MC/MCInst.h"
33 #include "llvm/MC/MCInstrDesc.h"
34 #include "llvm/MC/MCInstrInfo.h"
35 #include "llvm/MC/MCSection.h"
36 #include "llvm/MC/MCParser/MCAsmLexer.h"
37 #include "llvm/MC/MCParser/MCAsmParser.h"
38 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
39 #include "llvm/MC/MCRegisterInfo.h"
40 #include "llvm/MC/MCStreamer.h"
41 #include "llvm/MC/MCSubtargetInfo.h"
42 #include "llvm/MC/MCSymbol.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 };
58 // A class to keep track of assembler-generated constant pools that are use to
59 // implement the ldr-pseudo.
61 typedef SmallVector<std::pair<MCSymbol *, const MCExpr *>, 4> EntryVecTy;
65 // Initialize a new empty constant pool
68 // Add a new entry to the constant pool in the next slot.
69 // \param Value is the new entry to put in the constant pool.
71 // \returns a MCExpr that references the newly inserted value
72 const MCExpr *addEntry(const MCExpr *Value, MCContext &Context) {
73 MCSymbol *CPEntryLabel = Context.CreateTempSymbol();
75 Entries.push_back(std::make_pair(CPEntryLabel, Value));
76 return MCSymbolRefExpr::Create(CPEntryLabel, Context);
79 // Emit the contents of the constant pool using the provided streamer.
80 void emitEntries(MCStreamer &Streamer) {
83 Streamer.EmitCodeAlignment(4); // align to 4-byte address
84 Streamer.EmitDataRegion(MCDR_DataRegion);
85 for (EntryVecTy::const_iterator I = Entries.begin(), E = Entries.end();
87 Streamer.EmitLabel(I->first);
88 Streamer.EmitValue(I->second, 4);
90 Streamer.EmitDataRegion(MCDR_DataRegionEnd);
94 // Return true if the constant pool is empty
96 return Entries.empty();
100 // Map type used to keep track of per-Section constant pools used by the
101 // ldr-pseudo opcode. The map associates a section to its constant pool. The
102 // constant pool is a vector of (label, value) pairs. When the ldr
103 // pseudo is parsed we insert a new (label, value) pair into the constant pool
104 // for the current section and add MCSymbolRefExpr to the new label as
105 // an opcode to the ldr. After we have parsed all the user input we
106 // output the (label, value) pairs in each constant pool at the end of the
109 // We use the MapVector for the map type to ensure stable iteration of
110 // the sections at the end of the parse. We need to iterate over the
111 // sections in a stable order to ensure that we have print the
112 // constant pools in a deterministic order when printing an assembly
114 typedef MapVector<const MCSection *, ConstantPool> ConstantPoolMapTy;
116 class ARMAsmParser : public MCTargetAsmParser {
117 MCSubtargetInfo &STI;
119 const MCInstrInfo &MII;
120 const MCRegisterInfo *MRI;
121 ConstantPoolMapTy ConstantPools;
123 // Assembler created constant pools for ldr pseudo
124 ConstantPool *getConstantPool(const MCSection *Section) {
125 ConstantPoolMapTy::iterator CP = ConstantPools.find(Section);
126 if (CP == ConstantPools.end())
132 ConstantPool &getOrCreateConstantPool(const MCSection *Section) {
133 return ConstantPools[Section];
136 ARMTargetStreamer &getTargetStreamer() {
137 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
138 return static_cast<ARMTargetStreamer &>(TS);
141 // Unwind directives state
144 SMLoc PersonalityLoc;
145 SMLoc HandlerDataLoc;
147 void resetUnwindDirectiveParserState() {
148 FnStartLoc = SMLoc();
149 CantUnwindLoc = SMLoc();
150 PersonalityLoc = SMLoc();
151 HandlerDataLoc = SMLoc();
155 // Map of register aliases registers via the .req directive.
156 StringMap<unsigned> RegisterReqs;
158 bool NextSymbolIsThumb;
161 ARMCC::CondCodes Cond; // Condition for IT block.
162 unsigned Mask:4; // Condition mask for instructions.
163 // Starting at first 1 (from lsb).
164 // '1' condition as indicated in IT.
165 // '0' inverse of condition (else).
166 // Count of instructions in IT block is
167 // 4 - trailingzeroes(mask)
169 bool FirstCond; // Explicit flag for when we're parsing the
170 // First instruction in the IT block. It's
171 // implied in the mask, so needs special
174 unsigned CurPosition; // Current position in parsing of IT
175 // block. In range [0,3]. Initialized
176 // according to count of instructions in block.
177 // ~0U if no active IT block.
179 bool inITBlock() { return ITState.CurPosition != ~0U;}
180 void forwardITPosition() {
181 if (!inITBlock()) return;
182 // Move to the next instruction in the IT block, if there is one. If not,
183 // mark the block as done.
184 unsigned TZ = countTrailingZeros(ITState.Mask);
185 if (++ITState.CurPosition == 5 - TZ)
186 ITState.CurPosition = ~0U; // Done with the IT block after this.
190 MCAsmParser &getParser() const { return Parser; }
191 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
193 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
194 return Parser.Note(L, Msg, Ranges);
196 bool Warning(SMLoc L, const Twine &Msg,
197 ArrayRef<SMRange> Ranges = None) {
198 return Parser.Warning(L, Msg, Ranges);
200 bool Error(SMLoc L, const Twine &Msg,
201 ArrayRef<SMRange> Ranges = None) {
202 return Parser.Error(L, Msg, Ranges);
205 int tryParseRegister();
206 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
207 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
208 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
209 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
210 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
211 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
212 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
213 unsigned &ShiftAmount);
214 bool parseDirectiveWord(unsigned Size, SMLoc L);
215 bool parseDirectiveThumb(SMLoc L);
216 bool parseDirectiveARM(SMLoc L);
217 bool parseDirectiveThumbFunc(SMLoc L);
218 bool parseDirectiveCode(SMLoc L);
219 bool parseDirectiveSyntax(SMLoc L);
220 bool parseDirectiveReq(StringRef Name, SMLoc L);
221 bool parseDirectiveUnreq(SMLoc L);
222 bool parseDirectiveArch(SMLoc L);
223 bool parseDirectiveEabiAttr(SMLoc L);
224 bool parseDirectiveCPU(SMLoc L);
225 bool parseDirectiveFPU(SMLoc L);
226 bool parseDirectiveFnStart(SMLoc L);
227 bool parseDirectiveFnEnd(SMLoc L);
228 bool parseDirectiveCantUnwind(SMLoc L);
229 bool parseDirectivePersonality(SMLoc L);
230 bool parseDirectiveHandlerData(SMLoc L);
231 bool parseDirectiveSetFP(SMLoc L);
232 bool parseDirectivePad(SMLoc L);
233 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
234 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
235 bool parseDirectiveLtorg(SMLoc L);
236 bool parseDirectiveEven(SMLoc L);
238 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
239 bool &CarrySetting, unsigned &ProcessorIMod,
241 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
242 bool &CanAcceptCarrySet,
243 bool &CanAcceptPredicationCode);
245 bool isThumb() const {
246 // FIXME: Can tablegen auto-generate this?
247 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
249 bool isThumbOne() const {
250 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
252 bool isThumbTwo() const {
253 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
255 bool hasThumb() const {
256 return STI.getFeatureBits() & ARM::HasV4TOps;
258 bool hasV6Ops() const {
259 return STI.getFeatureBits() & ARM::HasV6Ops;
261 bool hasV6MOps() const {
262 return STI.getFeatureBits() & ARM::HasV6MOps;
264 bool hasV7Ops() const {
265 return STI.getFeatureBits() & ARM::HasV7Ops;
267 bool hasV8Ops() const {
268 return STI.getFeatureBits() & ARM::HasV8Ops;
270 bool hasARM() const {
271 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
275 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
276 setAvailableFeatures(FB);
278 bool isMClass() const {
279 return STI.getFeatureBits() & ARM::FeatureMClass;
282 /// @name Auto-generated Match Functions
285 #define GET_ASSEMBLER_HEADER
286 #include "ARMGenAsmMatcher.inc"
290 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
291 OperandMatchResultTy parseCoprocNumOperand(
292 SmallVectorImpl<MCParsedAsmOperand*>&);
293 OperandMatchResultTy parseCoprocRegOperand(
294 SmallVectorImpl<MCParsedAsmOperand*>&);
295 OperandMatchResultTy parseCoprocOptionOperand(
296 SmallVectorImpl<MCParsedAsmOperand*>&);
297 OperandMatchResultTy parseMemBarrierOptOperand(
298 SmallVectorImpl<MCParsedAsmOperand*>&);
299 OperandMatchResultTy parseInstSyncBarrierOptOperand(
300 SmallVectorImpl<MCParsedAsmOperand*>&);
301 OperandMatchResultTy parseProcIFlagsOperand(
302 SmallVectorImpl<MCParsedAsmOperand*>&);
303 OperandMatchResultTy parseMSRMaskOperand(
304 SmallVectorImpl<MCParsedAsmOperand*>&);
305 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
306 StringRef Op, int Low, int High);
307 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
308 return parsePKHImm(O, "lsl", 0, 31);
310 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
311 return parsePKHImm(O, "asr", 1, 32);
313 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
314 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
315 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
316 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
317 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
318 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
319 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
320 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
321 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
324 // Asm Match Converter Methods
325 void cvtThumbMultiply(MCInst &Inst,
326 const SmallVectorImpl<MCParsedAsmOperand*> &);
327 void cvtThumbBranches(MCInst &Inst,
328 const SmallVectorImpl<MCParsedAsmOperand*> &);
330 bool validateInstruction(MCInst &Inst,
331 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
332 bool processInstruction(MCInst &Inst,
333 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
334 bool shouldOmitCCOutOperand(StringRef Mnemonic,
335 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
336 bool shouldOmitPredicateOperand(StringRef Mnemonic,
337 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
339 enum ARMMatchResultTy {
340 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
341 Match_RequiresNotITBlock,
343 Match_RequiresThumb2,
344 #define GET_OPERAND_DIAGNOSTIC_TYPES
345 #include "ARMGenAsmMatcher.inc"
349 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
350 const MCInstrInfo &MII)
351 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
352 MCAsmParserExtension::Initialize(_Parser);
354 // Cache the MCRegisterInfo.
355 MRI = getContext().getRegisterInfo();
357 // Initialize the set of available features.
358 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
360 // Not in an ITBlock to start with.
361 ITState.CurPosition = ~0U;
363 NextSymbolIsThumb = false;
366 // Implementation of the MCTargetAsmParser interface:
367 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
368 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
370 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
371 bool ParseDirective(AsmToken DirectiveID);
373 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
374 unsigned checkTargetMatchPredicate(MCInst &Inst);
376 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
377 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
378 MCStreamer &Out, unsigned &ErrorInfo,
379 bool MatchingInlineAsm);
380 void onLabelParsed(MCSymbol *Symbol);
383 } // end anonymous namespace
387 /// ARMOperand - Instances of this class represent a parsed ARM machine
389 class ARMOperand : public MCParsedAsmOperand {
399 k_InstSyncBarrierOpt,
410 k_VectorListAllLanes,
416 k_BitfieldDescriptor,
420 SMLoc StartLoc, EndLoc;
421 SmallVector<unsigned, 8> Registers;
424 ARMCC::CondCodes Val;
431 struct CoprocOptionOp {
444 ARM_ISB::InstSyncBOpt Val;
448 ARM_PROC::IFlags Val;
464 // A vector register list is a sequential list of 1 to 4 registers.
465 struct VectorListOp {
472 struct VectorIndexOp {
480 /// Combined record for all forms of ARM address expressions.
483 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
485 const MCConstantExpr *OffsetImm; // Offset immediate value
486 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
487 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
488 unsigned ShiftImm; // shift for OffsetReg.
489 unsigned Alignment; // 0 = no alignment specified
490 // n = alignment in bytes (2, 4, 8, 16, or 32)
491 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
494 struct PostIdxRegOp {
497 ARM_AM::ShiftOpc ShiftTy;
501 struct ShifterImmOp {
506 struct RegShiftedRegOp {
507 ARM_AM::ShiftOpc ShiftTy;
513 struct RegShiftedImmOp {
514 ARM_AM::ShiftOpc ShiftTy;
531 struct CoprocOptionOp CoprocOption;
532 struct MBOptOp MBOpt;
533 struct ISBOptOp ISBOpt;
534 struct ITMaskOp ITMask;
535 struct IFlagsOp IFlags;
536 struct MMaskOp MMask;
539 struct VectorListOp VectorList;
540 struct VectorIndexOp VectorIndex;
542 struct MemoryOp Memory;
543 struct PostIdxRegOp PostIdxReg;
544 struct ShifterImmOp ShifterImm;
545 struct RegShiftedRegOp RegShiftedReg;
546 struct RegShiftedImmOp RegShiftedImm;
547 struct RotImmOp RotImm;
548 struct BitfieldOp Bitfield;
551 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
553 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
555 StartLoc = o.StartLoc;
572 case k_DPRRegisterList:
573 case k_SPRRegisterList:
574 Registers = o.Registers;
577 case k_VectorListAllLanes:
578 case k_VectorListIndexed:
579 VectorList = o.VectorList;
586 CoprocOption = o.CoprocOption;
591 case k_MemBarrierOpt:
594 case k_InstSyncBarrierOpt:
599 case k_PostIndexRegister:
600 PostIdxReg = o.PostIdxReg;
608 case k_ShifterImmediate:
609 ShifterImm = o.ShifterImm;
611 case k_ShiftedRegister:
612 RegShiftedReg = o.RegShiftedReg;
614 case k_ShiftedImmediate:
615 RegShiftedImm = o.RegShiftedImm;
617 case k_RotateImmediate:
620 case k_BitfieldDescriptor:
621 Bitfield = o.Bitfield;
624 VectorIndex = o.VectorIndex;
629 /// getStartLoc - Get the location of the first token of this operand.
630 SMLoc getStartLoc() const { return StartLoc; }
631 /// getEndLoc - Get the location of the last token of this operand.
632 SMLoc getEndLoc() const { return EndLoc; }
633 /// getLocRange - Get the range between the first and last token of this
635 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
637 ARMCC::CondCodes getCondCode() const {
638 assert(Kind == k_CondCode && "Invalid access!");
642 unsigned getCoproc() const {
643 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
647 StringRef getToken() const {
648 assert(Kind == k_Token && "Invalid access!");
649 return StringRef(Tok.Data, Tok.Length);
652 unsigned getReg() const {
653 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
657 const SmallVectorImpl<unsigned> &getRegList() const {
658 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
659 Kind == k_SPRRegisterList) && "Invalid access!");
663 const MCExpr *getImm() const {
664 assert(isImm() && "Invalid access!");
668 unsigned getVectorIndex() const {
669 assert(Kind == k_VectorIndex && "Invalid access!");
670 return VectorIndex.Val;
673 ARM_MB::MemBOpt getMemBarrierOpt() const {
674 assert(Kind == k_MemBarrierOpt && "Invalid access!");
678 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
679 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
683 ARM_PROC::IFlags getProcIFlags() const {
684 assert(Kind == k_ProcIFlags && "Invalid access!");
688 unsigned getMSRMask() const {
689 assert(Kind == k_MSRMask && "Invalid access!");
693 bool isCoprocNum() const { return Kind == k_CoprocNum; }
694 bool isCoprocReg() const { return Kind == k_CoprocReg; }
695 bool isCoprocOption() const { return Kind == k_CoprocOption; }
696 bool isCondCode() const { return Kind == k_CondCode; }
697 bool isCCOut() const { return Kind == k_CCOut; }
698 bool isITMask() const { return Kind == k_ITCondMask; }
699 bool isITCondCode() const { return Kind == k_CondCode; }
700 bool isImm() const { return Kind == k_Immediate; }
701 // checks whether this operand is an unsigned offset which fits is a field
702 // of specified width and scaled by a specific number of bits
703 template<unsigned width, unsigned scale>
704 bool isUnsignedOffset() const {
705 if (!isImm()) return false;
706 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
707 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
708 int64_t Val = CE->getValue();
709 int64_t Align = 1LL << scale;
710 int64_t Max = Align * ((1LL << width) - 1);
711 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
715 // checks whether this operand is an signed offset which fits is a field
716 // of specified width and scaled by a specific number of bits
717 template<unsigned width, unsigned scale>
718 bool isSignedOffset() const {
719 if (!isImm()) return false;
720 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
721 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
722 int64_t Val = CE->getValue();
723 int64_t Align = 1LL << scale;
724 int64_t Max = Align * ((1LL << (width-1)) - 1);
725 int64_t Min = -Align * (1LL << (width-1));
726 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
731 // checks whether this operand is a memory operand computed as an offset
732 // applied to PC. the offset may have 8 bits of magnitude and is represented
733 // with two bits of shift. textually it may be either [pc, #imm], #imm or
734 // relocable expression...
735 bool isThumbMemPC() const {
738 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
739 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
740 if (!CE) return false;
741 Val = CE->getValue();
744 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
745 if(Memory.BaseRegNum != ARM::PC) return false;
746 Val = Memory.OffsetImm->getValue();
749 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
751 bool isFPImm() const {
752 if (!isImm()) return false;
753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
754 if (!CE) return false;
755 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
758 bool isFBits16() const {
759 if (!isImm()) return false;
760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
761 if (!CE) return false;
762 int64_t Value = CE->getValue();
763 return Value >= 0 && Value <= 16;
765 bool isFBits32() 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 >= 1 && Value <= 32;
772 bool isImm8s4() 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 & 3) == 0) && Value >= -1020 && Value <= 1020;
779 bool isImm0_1020s4() 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 >= 0 && Value <= 1020;
786 bool isImm0_508s4() 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 <= 508;
793 bool isImm0_508s4Neg() 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 // explicitly exclude zero. we want that to use the normal 0_508 version.
799 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
801 bool isImm0_239() const {
802 if (!isImm()) return false;
803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
804 if (!CE) return false;
805 int64_t Value = CE->getValue();
806 return Value >= 0 && Value < 240;
808 bool isImm0_255() 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 < 256;
815 bool isImm0_4095() 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 < 4096;
822 bool isImm0_4095Neg() 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_1() 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 < 2;
836 bool isImm0_3() 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 < 4;
843 bool isImm0_7() 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 < 8;
850 bool isImm0_15() 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 < 16;
857 bool isImm0_31() 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 < 32;
864 bool isImm0_63() 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 < 64;
871 bool isImm8() 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();
878 bool isImm16() 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 isImm32() 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 isShrImm8() 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();
897 return Value > 0 && Value <= 8;
899 bool isShrImm16() 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 <= 16;
906 bool isShrImm32() 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 <= 32;
913 bool isShrImm64() 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 <= 64;
920 bool isImm1_7() 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 < 8;
927 bool isImm1_15() 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 < 16;
934 bool isImm1_31() 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 < 32;
941 bool isImm1_16() 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 < 17;
948 bool isImm1_32() 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 < 33;
955 bool isImm0_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_65535() 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 < 65536;
969 bool isImm256_65535Expr() const {
970 if (!isImm()) return false;
971 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
972 // If it's not a constant expression, it'll generate a fixup and be
974 if (!CE) return true;
975 int64_t Value = CE->getValue();
976 return Value >= 256 && Value < 65536;
978 bool isImm0_65535Expr() const {
979 if (!isImm()) return false;
980 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
981 // If it's not a constant expression, it'll generate a fixup and be
983 if (!CE) return true;
984 int64_t Value = CE->getValue();
985 return Value >= 0 && Value < 65536;
987 bool isImm24bit() const {
988 if (!isImm()) return false;
989 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
990 if (!CE) return false;
991 int64_t Value = CE->getValue();
992 return Value >= 0 && Value <= 0xffffff;
994 bool isImmThumbSR() 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 < 33;
1001 bool isPKHLSLImm() 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 < 32;
1008 bool isPKHASRImm() 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 isAdrLabel() const {
1016 // If we have an immediate that's not a constant, treat it as a label
1017 // reference needing a fixup. If it is a constant, but it can't fit
1018 // into shift immediate encoding, we reject it.
1019 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1020 else return (isARMSOImm() || isARMSOImmNeg());
1022 bool isARMSOImm() const {
1023 if (!isImm()) return false;
1024 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1025 if (!CE) return false;
1026 int64_t Value = CE->getValue();
1027 return ARM_AM::getSOImmVal(Value) != -1;
1029 bool isARMSOImmNot() 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 isARMSOImmNeg() 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 // Only use this when not representable as a plain so_imm.
1042 return ARM_AM::getSOImmVal(Value) == -1 &&
1043 ARM_AM::getSOImmVal(-Value) != -1;
1045 bool isT2SOImm() const {
1046 if (!isImm()) return false;
1047 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1048 if (!CE) return false;
1049 int64_t Value = CE->getValue();
1050 return ARM_AM::getT2SOImmVal(Value) != -1;
1052 bool isT2SOImmNot() 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 &&
1058 ARM_AM::getT2SOImmVal(~Value) != -1;
1060 bool isT2SOImmNeg() const {
1061 if (!isImm()) return false;
1062 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1063 if (!CE) return false;
1064 int64_t Value = CE->getValue();
1065 // Only use this when not representable as a plain so_imm.
1066 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1067 ARM_AM::getT2SOImmVal(-Value) != -1;
1069 bool isSetEndImm() const {
1070 if (!isImm()) return false;
1071 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1072 if (!CE) return false;
1073 int64_t Value = CE->getValue();
1074 return Value == 1 || Value == 0;
1076 bool isReg() const { return Kind == k_Register; }
1077 bool isRegList() const { return Kind == k_RegisterList; }
1078 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1079 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
1080 bool isToken() const { return Kind == k_Token; }
1081 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
1082 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
1083 bool isMem() const { return Kind == k_Memory; }
1084 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1085 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1086 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1087 bool isRotImm() const { return Kind == k_RotateImmediate; }
1088 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1089 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
1090 bool isPostIdxReg() const {
1091 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
1093 bool isMemNoOffset(bool alignOK = false) const {
1096 // No offset of any kind.
1097 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1098 (alignOK || Memory.Alignment == 0);
1100 bool isMemPCRelImm12() const {
1101 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1103 // Base register must be PC.
1104 if (Memory.BaseRegNum != ARM::PC)
1106 // Immediate offset in range [-4095, 4095].
1107 if (!Memory.OffsetImm) return true;
1108 int64_t Val = Memory.OffsetImm->getValue();
1109 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1111 bool isAlignedMemory() const {
1112 return isMemNoOffset(true);
1114 bool isAddrMode2() const {
1115 if (!isMem() || Memory.Alignment != 0) return false;
1116 // Check for register offset.
1117 if (Memory.OffsetRegNum) return true;
1118 // Immediate offset in range [-4095, 4095].
1119 if (!Memory.OffsetImm) return true;
1120 int64_t Val = Memory.OffsetImm->getValue();
1121 return Val > -4096 && Val < 4096;
1123 bool isAM2OffsetImm() const {
1124 if (!isImm()) return false;
1125 // Immediate offset in range [-4095, 4095].
1126 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1127 if (!CE) return false;
1128 int64_t Val = CE->getValue();
1129 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1131 bool isAddrMode3() const {
1132 // If we have an immediate that's not a constant, treat it as a label
1133 // reference needing a fixup. If it is a constant, it's something else
1134 // and we reject it.
1135 if (isImm() && !isa<MCConstantExpr>(getImm()))
1137 if (!isMem() || Memory.Alignment != 0) return false;
1138 // No shifts are legal for AM3.
1139 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1140 // Check for register offset.
1141 if (Memory.OffsetRegNum) return true;
1142 // Immediate offset in range [-255, 255].
1143 if (!Memory.OffsetImm) return true;
1144 int64_t Val = Memory.OffsetImm->getValue();
1145 // The #-0 offset is encoded as INT32_MIN, and we have to check
1147 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1149 bool isAM3Offset() const {
1150 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1152 if (Kind == k_PostIndexRegister)
1153 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1154 // Immediate offset in range [-255, 255].
1155 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1156 if (!CE) return false;
1157 int64_t Val = CE->getValue();
1158 // Special case, #-0 is INT32_MIN.
1159 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1161 bool isAddrMode5() const {
1162 // If we have an immediate that's not a constant, treat it as a label
1163 // reference needing a fixup. If it is a constant, it's something else
1164 // and we reject it.
1165 if (isImm() && !isa<MCConstantExpr>(getImm()))
1167 if (!isMem() || Memory.Alignment != 0) return false;
1168 // Check for register offset.
1169 if (Memory.OffsetRegNum) return false;
1170 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1171 if (!Memory.OffsetImm) return true;
1172 int64_t Val = Memory.OffsetImm->getValue();
1173 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1176 bool isMemTBB() const {
1177 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1178 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1182 bool isMemTBH() const {
1183 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1184 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1185 Memory.Alignment != 0 )
1189 bool isMemRegOffset() const {
1190 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1194 bool isT2MemRegOffset() const {
1195 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1196 Memory.Alignment != 0)
1198 // Only lsl #{0, 1, 2, 3} allowed.
1199 if (Memory.ShiftType == ARM_AM::no_shift)
1201 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1205 bool isMemThumbRR() const {
1206 // Thumb reg+reg addressing is simple. Just two registers, a base and
1207 // an offset. No shifts, negations or any other complicating factors.
1208 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1209 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1211 return isARMLowRegister(Memory.BaseRegNum) &&
1212 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1214 bool isMemThumbRIs4() const {
1215 if (!isMem() || Memory.OffsetRegNum != 0 ||
1216 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1218 // Immediate offset, multiple of 4 in range [0, 124].
1219 if (!Memory.OffsetImm) return true;
1220 int64_t Val = Memory.OffsetImm->getValue();
1221 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1223 bool isMemThumbRIs2() const {
1224 if (!isMem() || Memory.OffsetRegNum != 0 ||
1225 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1227 // Immediate offset, multiple of 4 in range [0, 62].
1228 if (!Memory.OffsetImm) return true;
1229 int64_t Val = Memory.OffsetImm->getValue();
1230 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1232 bool isMemThumbRIs1() const {
1233 if (!isMem() || Memory.OffsetRegNum != 0 ||
1234 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1236 // Immediate offset in range [0, 31].
1237 if (!Memory.OffsetImm) return true;
1238 int64_t Val = Memory.OffsetImm->getValue();
1239 return Val >= 0 && Val <= 31;
1241 bool isMemThumbSPI() const {
1242 if (!isMem() || Memory.OffsetRegNum != 0 ||
1243 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1245 // Immediate offset, multiple of 4 in range [0, 1020].
1246 if (!Memory.OffsetImm) return true;
1247 int64_t Val = Memory.OffsetImm->getValue();
1248 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1250 bool isMemImm8s4Offset() const {
1251 // If we have an immediate that's not a constant, treat it as a label
1252 // reference needing a fixup. If it is a constant, it's something else
1253 // and we reject it.
1254 if (isImm() && !isa<MCConstantExpr>(getImm()))
1256 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1258 // Immediate offset a multiple of 4 in range [-1020, 1020].
1259 if (!Memory.OffsetImm) return true;
1260 int64_t Val = Memory.OffsetImm->getValue();
1261 // Special case, #-0 is INT32_MIN.
1262 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1264 bool isMemImm0_1020s4Offset() const {
1265 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1267 // Immediate offset a multiple of 4 in range [0, 1020].
1268 if (!Memory.OffsetImm) return true;
1269 int64_t Val = Memory.OffsetImm->getValue();
1270 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1272 bool isMemImm8Offset() const {
1273 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1275 // Base reg of PC isn't allowed for these encodings.
1276 if (Memory.BaseRegNum == ARM::PC) return false;
1277 // Immediate offset in range [-255, 255].
1278 if (!Memory.OffsetImm) return true;
1279 int64_t Val = Memory.OffsetImm->getValue();
1280 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1282 bool isMemPosImm8Offset() const {
1283 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1285 // Immediate offset in range [0, 255].
1286 if (!Memory.OffsetImm) return true;
1287 int64_t Val = Memory.OffsetImm->getValue();
1288 return Val >= 0 && Val < 256;
1290 bool isMemNegImm8Offset() const {
1291 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1293 // Base reg of PC isn't allowed for these encodings.
1294 if (Memory.BaseRegNum == ARM::PC) return false;
1295 // Immediate offset in range [-255, -1].
1296 if (!Memory.OffsetImm) return false;
1297 int64_t Val = Memory.OffsetImm->getValue();
1298 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1300 bool isMemUImm12Offset() const {
1301 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1303 // Immediate offset in range [0, 4095].
1304 if (!Memory.OffsetImm) return true;
1305 int64_t Val = Memory.OffsetImm->getValue();
1306 return (Val >= 0 && Val < 4096);
1308 bool isMemImm12Offset() const {
1309 // If we have an immediate that's not a constant, treat it as a label
1310 // reference needing a fixup. If it is a constant, it's something else
1311 // and we reject it.
1312 if (isImm() && !isa<MCConstantExpr>(getImm()))
1315 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1317 // Immediate offset in range [-4095, 4095].
1318 if (!Memory.OffsetImm) return true;
1319 int64_t Val = Memory.OffsetImm->getValue();
1320 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1322 bool isPostIdxImm8() const {
1323 if (!isImm()) return false;
1324 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1325 if (!CE) return false;
1326 int64_t Val = CE->getValue();
1327 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1329 bool isPostIdxImm8s4() const {
1330 if (!isImm()) return false;
1331 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1332 if (!CE) return false;
1333 int64_t Val = CE->getValue();
1334 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1338 bool isMSRMask() const { return Kind == k_MSRMask; }
1339 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1342 bool isSingleSpacedVectorList() const {
1343 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1345 bool isDoubleSpacedVectorList() const {
1346 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1348 bool isVecListOneD() const {
1349 if (!isSingleSpacedVectorList()) return false;
1350 return VectorList.Count == 1;
1353 bool isVecListDPair() const {
1354 if (!isSingleSpacedVectorList()) return false;
1355 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1356 .contains(VectorList.RegNum));
1359 bool isVecListThreeD() const {
1360 if (!isSingleSpacedVectorList()) return false;
1361 return VectorList.Count == 3;
1364 bool isVecListFourD() const {
1365 if (!isSingleSpacedVectorList()) return false;
1366 return VectorList.Count == 4;
1369 bool isVecListDPairSpaced() const {
1370 if (isSingleSpacedVectorList()) return false;
1371 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1372 .contains(VectorList.RegNum));
1375 bool isVecListThreeQ() const {
1376 if (!isDoubleSpacedVectorList()) return false;
1377 return VectorList.Count == 3;
1380 bool isVecListFourQ() const {
1381 if (!isDoubleSpacedVectorList()) return false;
1382 return VectorList.Count == 4;
1385 bool isSingleSpacedVectorAllLanes() const {
1386 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1388 bool isDoubleSpacedVectorAllLanes() const {
1389 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1391 bool isVecListOneDAllLanes() const {
1392 if (!isSingleSpacedVectorAllLanes()) return false;
1393 return VectorList.Count == 1;
1396 bool isVecListDPairAllLanes() const {
1397 if (!isSingleSpacedVectorAllLanes()) return false;
1398 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1399 .contains(VectorList.RegNum));
1402 bool isVecListDPairSpacedAllLanes() const {
1403 if (!isDoubleSpacedVectorAllLanes()) return false;
1404 return VectorList.Count == 2;
1407 bool isVecListThreeDAllLanes() const {
1408 if (!isSingleSpacedVectorAllLanes()) return false;
1409 return VectorList.Count == 3;
1412 bool isVecListThreeQAllLanes() const {
1413 if (!isDoubleSpacedVectorAllLanes()) return false;
1414 return VectorList.Count == 3;
1417 bool isVecListFourDAllLanes() const {
1418 if (!isSingleSpacedVectorAllLanes()) return false;
1419 return VectorList.Count == 4;
1422 bool isVecListFourQAllLanes() const {
1423 if (!isDoubleSpacedVectorAllLanes()) return false;
1424 return VectorList.Count == 4;
1427 bool isSingleSpacedVectorIndexed() const {
1428 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1430 bool isDoubleSpacedVectorIndexed() const {
1431 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1433 bool isVecListOneDByteIndexed() const {
1434 if (!isSingleSpacedVectorIndexed()) return false;
1435 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1438 bool isVecListOneDHWordIndexed() const {
1439 if (!isSingleSpacedVectorIndexed()) return false;
1440 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1443 bool isVecListOneDWordIndexed() const {
1444 if (!isSingleSpacedVectorIndexed()) return false;
1445 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1448 bool isVecListTwoDByteIndexed() const {
1449 if (!isSingleSpacedVectorIndexed()) return false;
1450 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1453 bool isVecListTwoDHWordIndexed() const {
1454 if (!isSingleSpacedVectorIndexed()) return false;
1455 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1458 bool isVecListTwoQWordIndexed() const {
1459 if (!isDoubleSpacedVectorIndexed()) return false;
1460 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1463 bool isVecListTwoQHWordIndexed() const {
1464 if (!isDoubleSpacedVectorIndexed()) return false;
1465 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1468 bool isVecListTwoDWordIndexed() const {
1469 if (!isSingleSpacedVectorIndexed()) return false;
1470 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1473 bool isVecListThreeDByteIndexed() const {
1474 if (!isSingleSpacedVectorIndexed()) return false;
1475 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1478 bool isVecListThreeDHWordIndexed() const {
1479 if (!isSingleSpacedVectorIndexed()) return false;
1480 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1483 bool isVecListThreeQWordIndexed() const {
1484 if (!isDoubleSpacedVectorIndexed()) return false;
1485 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1488 bool isVecListThreeQHWordIndexed() const {
1489 if (!isDoubleSpacedVectorIndexed()) return false;
1490 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1493 bool isVecListThreeDWordIndexed() const {
1494 if (!isSingleSpacedVectorIndexed()) return false;
1495 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1498 bool isVecListFourDByteIndexed() const {
1499 if (!isSingleSpacedVectorIndexed()) return false;
1500 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1503 bool isVecListFourDHWordIndexed() const {
1504 if (!isSingleSpacedVectorIndexed()) return false;
1505 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1508 bool isVecListFourQWordIndexed() const {
1509 if (!isDoubleSpacedVectorIndexed()) return false;
1510 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1513 bool isVecListFourQHWordIndexed() const {
1514 if (!isDoubleSpacedVectorIndexed()) return false;
1515 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1518 bool isVecListFourDWordIndexed() const {
1519 if (!isSingleSpacedVectorIndexed()) return false;
1520 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1523 bool isVectorIndex8() const {
1524 if (Kind != k_VectorIndex) return false;
1525 return VectorIndex.Val < 8;
1527 bool isVectorIndex16() const {
1528 if (Kind != k_VectorIndex) return false;
1529 return VectorIndex.Val < 4;
1531 bool isVectorIndex32() const {
1532 if (Kind != k_VectorIndex) return false;
1533 return VectorIndex.Val < 2;
1536 bool isNEONi8splat() const {
1537 if (!isImm()) return false;
1538 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1539 // Must be a constant.
1540 if (!CE) return false;
1541 int64_t Value = CE->getValue();
1542 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1544 return Value >= 0 && Value < 256;
1547 bool isNEONi16splat() const {
1548 if (!isImm()) return false;
1549 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1550 // Must be a constant.
1551 if (!CE) return false;
1552 int64_t Value = CE->getValue();
1553 // i16 value in the range [0,255] or [0x0100, 0xff00]
1554 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1557 bool isNEONi32splat() const {
1558 if (!isImm()) return false;
1559 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1560 // Must be a constant.
1561 if (!CE) return false;
1562 int64_t Value = CE->getValue();
1563 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1564 return (Value >= 0 && Value < 256) ||
1565 (Value >= 0x0100 && Value <= 0xff00) ||
1566 (Value >= 0x010000 && Value <= 0xff0000) ||
1567 (Value >= 0x01000000 && Value <= 0xff000000);
1570 bool isNEONi32vmov() const {
1571 if (!isImm()) return false;
1572 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1573 // Must be a constant.
1574 if (!CE) return false;
1575 int64_t Value = CE->getValue();
1576 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1577 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1578 return (Value >= 0 && Value < 256) ||
1579 (Value >= 0x0100 && Value <= 0xff00) ||
1580 (Value >= 0x010000 && Value <= 0xff0000) ||
1581 (Value >= 0x01000000 && Value <= 0xff000000) ||
1582 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1583 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1585 bool isNEONi32vmovNeg() const {
1586 if (!isImm()) return false;
1587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1588 // Must be a constant.
1589 if (!CE) return false;
1590 int64_t Value = ~CE->getValue();
1591 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1592 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1593 return (Value >= 0 && Value < 256) ||
1594 (Value >= 0x0100 && Value <= 0xff00) ||
1595 (Value >= 0x010000 && Value <= 0xff0000) ||
1596 (Value >= 0x01000000 && Value <= 0xff000000) ||
1597 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1598 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1601 bool isNEONi64splat() const {
1602 if (!isImm()) return false;
1603 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1604 // Must be a constant.
1605 if (!CE) return false;
1606 uint64_t Value = CE->getValue();
1607 // i64 value with each byte being either 0 or 0xff.
1608 for (unsigned i = 0; i < 8; ++i)
1609 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1613 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1614 // Add as immediates when possible. Null MCExpr = 0.
1616 Inst.addOperand(MCOperand::CreateImm(0));
1617 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1618 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1620 Inst.addOperand(MCOperand::CreateExpr(Expr));
1623 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1624 assert(N == 2 && "Invalid number of operands!");
1625 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1626 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1627 Inst.addOperand(MCOperand::CreateReg(RegNum));
1630 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1631 assert(N == 1 && "Invalid number of operands!");
1632 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1635 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1636 assert(N == 1 && "Invalid number of operands!");
1637 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1640 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1641 assert(N == 1 && "Invalid number of operands!");
1642 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1645 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1646 assert(N == 1 && "Invalid number of operands!");
1647 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1650 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1651 assert(N == 1 && "Invalid number of operands!");
1652 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1655 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1656 assert(N == 1 && "Invalid number of operands!");
1657 Inst.addOperand(MCOperand::CreateReg(getReg()));
1660 void addRegOperands(MCInst &Inst, unsigned N) const {
1661 assert(N == 1 && "Invalid number of operands!");
1662 Inst.addOperand(MCOperand::CreateReg(getReg()));
1665 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1666 assert(N == 3 && "Invalid number of operands!");
1667 assert(isRegShiftedReg() &&
1668 "addRegShiftedRegOperands() on non-RegShiftedReg!");
1669 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1670 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1671 Inst.addOperand(MCOperand::CreateImm(
1672 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1675 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1676 assert(N == 2 && "Invalid number of operands!");
1677 assert(isRegShiftedImm() &&
1678 "addRegShiftedImmOperands() on non-RegShiftedImm!");
1679 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1680 // Shift of #32 is encoded as 0 where permitted
1681 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1682 Inst.addOperand(MCOperand::CreateImm(
1683 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1686 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1687 assert(N == 1 && "Invalid number of operands!");
1688 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1692 void addRegListOperands(MCInst &Inst, unsigned N) const {
1693 assert(N == 1 && "Invalid number of operands!");
1694 const SmallVectorImpl<unsigned> &RegList = getRegList();
1695 for (SmallVectorImpl<unsigned>::const_iterator
1696 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1697 Inst.addOperand(MCOperand::CreateReg(*I));
1700 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1701 addRegListOperands(Inst, N);
1704 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1705 addRegListOperands(Inst, N);
1708 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1709 assert(N == 1 && "Invalid number of operands!");
1710 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1711 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1714 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1715 assert(N == 1 && "Invalid number of operands!");
1716 // Munge the lsb/width into a bitfield mask.
1717 unsigned lsb = Bitfield.LSB;
1718 unsigned width = Bitfield.Width;
1719 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1720 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1721 (32 - (lsb + width)));
1722 Inst.addOperand(MCOperand::CreateImm(Mask));
1725 void addImmOperands(MCInst &Inst, unsigned N) const {
1726 assert(N == 1 && "Invalid number of operands!");
1727 addExpr(Inst, getImm());
1730 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1731 assert(N == 1 && "Invalid number of operands!");
1732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1733 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1736 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1737 assert(N == 1 && "Invalid number of operands!");
1738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1739 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1742 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1743 assert(N == 1 && "Invalid number of operands!");
1744 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1745 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1746 Inst.addOperand(MCOperand::CreateImm(Val));
1749 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1750 assert(N == 1 && "Invalid number of operands!");
1751 // FIXME: We really want to scale the value here, but the LDRD/STRD
1752 // instruction don't encode operands that way yet.
1753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1754 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1757 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1758 assert(N == 1 && "Invalid number of operands!");
1759 // The immediate is scaled by four in the encoding and is stored
1760 // in the MCInst as such. Lop off the low two bits here.
1761 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1762 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1765 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1766 assert(N == 1 && "Invalid number of operands!");
1767 // The immediate is scaled by four in the encoding and is stored
1768 // in the MCInst as such. Lop off the low two bits here.
1769 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1770 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1773 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1774 assert(N == 1 && "Invalid number of operands!");
1775 // The immediate is scaled by four in the encoding and is stored
1776 // in the MCInst as such. Lop off the low two bits here.
1777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1778 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1781 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1782 assert(N == 1 && "Invalid number of operands!");
1783 // The constant encodes as the immediate-1, and we store in the instruction
1784 // the bits as encoded, so subtract off one here.
1785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1786 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1789 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1790 assert(N == 1 && "Invalid number of operands!");
1791 // The constant encodes as the immediate-1, and we store in the instruction
1792 // the bits as encoded, so subtract off one here.
1793 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1794 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1797 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1798 assert(N == 1 && "Invalid number of operands!");
1799 // The constant encodes as the immediate, except for 32, which encodes as
1801 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1802 unsigned Imm = CE->getValue();
1803 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1806 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1807 assert(N == 1 && "Invalid number of operands!");
1808 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1809 // the instruction as well.
1810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1811 int Val = CE->getValue();
1812 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1815 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1816 assert(N == 1 && "Invalid number of operands!");
1817 // The operand is actually a t2_so_imm, but we have its bitwise
1818 // negation in the assembly source, so twiddle it here.
1819 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1820 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1823 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1824 assert(N == 1 && "Invalid number of operands!");
1825 // The operand is actually a t2_so_imm, but we have its
1826 // negation in the assembly source, so twiddle it here.
1827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1828 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1831 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1832 assert(N == 1 && "Invalid number of operands!");
1833 // The operand is actually an imm0_4095, but we have its
1834 // negation in the assembly source, so twiddle it here.
1835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1836 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1839 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1840 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1841 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1845 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1846 assert(SR && "Unknown value type!");
1847 Inst.addOperand(MCOperand::CreateExpr(SR));
1850 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1851 assert(N == 1 && "Invalid number of operands!");
1853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1855 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1859 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1860 assert(SR && "Unknown value type!");
1861 Inst.addOperand(MCOperand::CreateExpr(SR));
1865 assert(isMem() && "Unknown value type!");
1866 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1867 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1870 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1871 assert(N == 1 && "Invalid number of operands!");
1872 // The operand is actually a so_imm, but we have its bitwise
1873 // negation in the assembly source, so twiddle it here.
1874 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1875 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1878 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1879 assert(N == 1 && "Invalid number of operands!");
1880 // The operand is actually a so_imm, but we have its
1881 // negation in the assembly source, so twiddle it here.
1882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1883 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1886 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1887 assert(N == 1 && "Invalid number of operands!");
1888 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1891 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1892 assert(N == 1 && "Invalid number of operands!");
1893 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1896 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1897 assert(N == 1 && "Invalid number of operands!");
1898 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1901 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1902 assert(N == 1 && "Invalid number of operands!");
1903 int32_t Imm = Memory.OffsetImm->getValue();
1904 Inst.addOperand(MCOperand::CreateImm(Imm));
1907 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1908 assert(N == 1 && "Invalid number of operands!");
1909 assert(isImm() && "Not an immediate!");
1911 // If we have an immediate that's not a constant, treat it as a label
1912 // reference needing a fixup.
1913 if (!isa<MCConstantExpr>(getImm())) {
1914 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1919 int Val = CE->getValue();
1920 Inst.addOperand(MCOperand::CreateImm(Val));
1923 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1924 assert(N == 2 && "Invalid number of operands!");
1925 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1926 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1929 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1930 assert(N == 3 && "Invalid number of operands!");
1931 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1932 if (!Memory.OffsetRegNum) {
1933 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1934 // Special case for #-0
1935 if (Val == INT32_MIN) Val = 0;
1936 if (Val < 0) Val = -Val;
1937 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1939 // For register offset, we encode the shift type and negation flag
1941 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1942 Memory.ShiftImm, Memory.ShiftType);
1944 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1945 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1946 Inst.addOperand(MCOperand::CreateImm(Val));
1949 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1950 assert(N == 2 && "Invalid number of operands!");
1951 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1952 assert(CE && "non-constant AM2OffsetImm operand!");
1953 int32_t Val = CE->getValue();
1954 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1955 // Special case for #-0
1956 if (Val == INT32_MIN) Val = 0;
1957 if (Val < 0) Val = -Val;
1958 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1959 Inst.addOperand(MCOperand::CreateReg(0));
1960 Inst.addOperand(MCOperand::CreateImm(Val));
1963 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1964 assert(N == 3 && "Invalid number of operands!");
1965 // If we have an immediate that's not a constant, treat it as a label
1966 // reference needing a fixup. If it is a constant, it's something else
1967 // and we reject it.
1969 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1970 Inst.addOperand(MCOperand::CreateReg(0));
1971 Inst.addOperand(MCOperand::CreateImm(0));
1975 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1976 if (!Memory.OffsetRegNum) {
1977 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1978 // Special case for #-0
1979 if (Val == INT32_MIN) Val = 0;
1980 if (Val < 0) Val = -Val;
1981 Val = ARM_AM::getAM3Opc(AddSub, Val);
1983 // For register offset, we encode the shift type and negation flag
1985 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1987 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1988 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1989 Inst.addOperand(MCOperand::CreateImm(Val));
1992 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1993 assert(N == 2 && "Invalid number of operands!");
1994 if (Kind == k_PostIndexRegister) {
1996 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1997 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1998 Inst.addOperand(MCOperand::CreateImm(Val));
2003 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2004 int32_t Val = CE->getValue();
2005 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2006 // Special case for #-0
2007 if (Val == INT32_MIN) Val = 0;
2008 if (Val < 0) Val = -Val;
2009 Val = ARM_AM::getAM3Opc(AddSub, Val);
2010 Inst.addOperand(MCOperand::CreateReg(0));
2011 Inst.addOperand(MCOperand::CreateImm(Val));
2014 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2015 assert(N == 2 && "Invalid number of operands!");
2016 // If we have an immediate that's not a constant, treat it as a label
2017 // reference needing a fixup. If it is a constant, it's something else
2018 // and we reject it.
2020 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2021 Inst.addOperand(MCOperand::CreateImm(0));
2025 // The lower two bits are always zero and as such are not encoded.
2026 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2027 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2028 // Special case for #-0
2029 if (Val == INT32_MIN) Val = 0;
2030 if (Val < 0) Val = -Val;
2031 Val = ARM_AM::getAM5Opc(AddSub, Val);
2032 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2033 Inst.addOperand(MCOperand::CreateImm(Val));
2036 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2037 assert(N == 2 && "Invalid number of operands!");
2038 // If we have an immediate that's not a constant, treat it as a label
2039 // reference needing a fixup. If it is a constant, it's something else
2040 // and we reject it.
2042 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2043 Inst.addOperand(MCOperand::CreateImm(0));
2047 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2048 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2049 Inst.addOperand(MCOperand::CreateImm(Val));
2052 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2053 assert(N == 2 && "Invalid number of operands!");
2054 // The lower two bits are always zero and as such are not encoded.
2055 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2056 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2057 Inst.addOperand(MCOperand::CreateImm(Val));
2060 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2061 assert(N == 2 && "Invalid number of operands!");
2062 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2063 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2064 Inst.addOperand(MCOperand::CreateImm(Val));
2067 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2068 addMemImm8OffsetOperands(Inst, N);
2071 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2072 addMemImm8OffsetOperands(Inst, N);
2075 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2076 assert(N == 2 && "Invalid number of operands!");
2077 // If this is an immediate, it's a label reference.
2079 addExpr(Inst, getImm());
2080 Inst.addOperand(MCOperand::CreateImm(0));
2084 // Otherwise, it's a normal memory reg+offset.
2085 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2086 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2087 Inst.addOperand(MCOperand::CreateImm(Val));
2090 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2091 assert(N == 2 && "Invalid number of operands!");
2092 // If this is an immediate, it's a label reference.
2094 addExpr(Inst, getImm());
2095 Inst.addOperand(MCOperand::CreateImm(0));
2099 // Otherwise, it's a normal memory reg+offset.
2100 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2101 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2102 Inst.addOperand(MCOperand::CreateImm(Val));
2105 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2106 assert(N == 2 && "Invalid number of operands!");
2107 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2108 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2111 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2112 assert(N == 2 && "Invalid number of operands!");
2113 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2114 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2117 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2118 assert(N == 3 && "Invalid number of operands!");
2120 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2121 Memory.ShiftImm, Memory.ShiftType);
2122 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2123 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2124 Inst.addOperand(MCOperand::CreateImm(Val));
2127 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2128 assert(N == 3 && "Invalid number of operands!");
2129 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2130 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2131 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2134 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2135 assert(N == 2 && "Invalid number of operands!");
2136 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2137 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2140 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2141 assert(N == 2 && "Invalid number of operands!");
2142 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2143 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2144 Inst.addOperand(MCOperand::CreateImm(Val));
2147 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2148 assert(N == 2 && "Invalid number of operands!");
2149 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2150 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2151 Inst.addOperand(MCOperand::CreateImm(Val));
2154 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2155 assert(N == 2 && "Invalid number of operands!");
2156 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2157 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2158 Inst.addOperand(MCOperand::CreateImm(Val));
2161 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2162 assert(N == 2 && "Invalid number of operands!");
2163 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2164 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2165 Inst.addOperand(MCOperand::CreateImm(Val));
2168 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2169 assert(N == 1 && "Invalid number of operands!");
2170 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2171 assert(CE && "non-constant post-idx-imm8 operand!");
2172 int Imm = CE->getValue();
2173 bool isAdd = Imm >= 0;
2174 if (Imm == INT32_MIN) Imm = 0;
2175 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2176 Inst.addOperand(MCOperand::CreateImm(Imm));
2179 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2180 assert(N == 1 && "Invalid number of operands!");
2181 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2182 assert(CE && "non-constant post-idx-imm8s4 operand!");
2183 int Imm = CE->getValue();
2184 bool isAdd = Imm >= 0;
2185 if (Imm == INT32_MIN) Imm = 0;
2186 // Immediate is scaled by 4.
2187 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2188 Inst.addOperand(MCOperand::CreateImm(Imm));
2191 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2192 assert(N == 2 && "Invalid number of operands!");
2193 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2194 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2197 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2198 assert(N == 2 && "Invalid number of operands!");
2199 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2200 // The sign, shift type, and shift amount are encoded in a single operand
2201 // using the AM2 encoding helpers.
2202 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2203 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2204 PostIdxReg.ShiftTy);
2205 Inst.addOperand(MCOperand::CreateImm(Imm));
2208 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2209 assert(N == 1 && "Invalid number of operands!");
2210 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2213 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2214 assert(N == 1 && "Invalid number of operands!");
2215 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2218 void addVecListOperands(MCInst &Inst, unsigned N) const {
2219 assert(N == 1 && "Invalid number of operands!");
2220 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2223 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2224 assert(N == 2 && "Invalid number of operands!");
2225 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2226 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2229 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2230 assert(N == 1 && "Invalid number of operands!");
2231 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2234 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2235 assert(N == 1 && "Invalid number of operands!");
2236 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2239 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2240 assert(N == 1 && "Invalid number of operands!");
2241 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2244 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2245 assert(N == 1 && "Invalid number of operands!");
2246 // The immediate encodes the type of constant as well as the value.
2247 // Mask in that this is an i8 splat.
2248 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2249 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2252 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2253 assert(N == 1 && "Invalid number of operands!");
2254 // The immediate encodes the type of constant as well as the value.
2255 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2256 unsigned Value = CE->getValue();
2258 Value = (Value >> 8) | 0xa00;
2261 Inst.addOperand(MCOperand::CreateImm(Value));
2264 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2265 assert(N == 1 && "Invalid number of operands!");
2266 // The immediate encodes the type of constant as well as the value.
2267 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2268 unsigned Value = CE->getValue();
2269 if (Value >= 256 && Value <= 0xff00)
2270 Value = (Value >> 8) | 0x200;
2271 else if (Value > 0xffff && Value <= 0xff0000)
2272 Value = (Value >> 16) | 0x400;
2273 else if (Value > 0xffffff)
2274 Value = (Value >> 24) | 0x600;
2275 Inst.addOperand(MCOperand::CreateImm(Value));
2278 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2279 assert(N == 1 && "Invalid number of operands!");
2280 // The immediate encodes the type of constant as well as the value.
2281 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2282 unsigned Value = CE->getValue();
2283 if (Value >= 256 && Value <= 0xffff)
2284 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2285 else if (Value > 0xffff && Value <= 0xffffff)
2286 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2287 else if (Value > 0xffffff)
2288 Value = (Value >> 24) | 0x600;
2289 Inst.addOperand(MCOperand::CreateImm(Value));
2292 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2293 assert(N == 1 && "Invalid number of operands!");
2294 // The immediate encodes the type of constant as well as the value.
2295 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2296 unsigned Value = ~CE->getValue();
2297 if (Value >= 256 && Value <= 0xffff)
2298 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2299 else if (Value > 0xffff && Value <= 0xffffff)
2300 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2301 else if (Value > 0xffffff)
2302 Value = (Value >> 24) | 0x600;
2303 Inst.addOperand(MCOperand::CreateImm(Value));
2306 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2307 assert(N == 1 && "Invalid number of operands!");
2308 // The immediate encodes the type of constant as well as the value.
2309 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2310 uint64_t Value = CE->getValue();
2312 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2313 Imm |= (Value & 1) << i;
2315 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2318 virtual void print(raw_ostream &OS) const;
2320 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2321 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2322 Op->ITMask.Mask = Mask;
2328 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2329 ARMOperand *Op = new ARMOperand(k_CondCode);
2336 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2337 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2338 Op->Cop.Val = CopVal;
2344 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2345 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2346 Op->Cop.Val = CopVal;
2352 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2353 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2360 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2361 ARMOperand *Op = new ARMOperand(k_CCOut);
2362 Op->Reg.RegNum = RegNum;
2368 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2369 ARMOperand *Op = new ARMOperand(k_Token);
2370 Op->Tok.Data = Str.data();
2371 Op->Tok.Length = Str.size();
2377 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2378 ARMOperand *Op = new ARMOperand(k_Register);
2379 Op->Reg.RegNum = RegNum;
2385 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2390 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2391 Op->RegShiftedReg.ShiftTy = ShTy;
2392 Op->RegShiftedReg.SrcReg = SrcReg;
2393 Op->RegShiftedReg.ShiftReg = ShiftReg;
2394 Op->RegShiftedReg.ShiftImm = ShiftImm;
2400 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2404 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2405 Op->RegShiftedImm.ShiftTy = ShTy;
2406 Op->RegShiftedImm.SrcReg = SrcReg;
2407 Op->RegShiftedImm.ShiftImm = ShiftImm;
2413 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2415 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2416 Op->ShifterImm.isASR = isASR;
2417 Op->ShifterImm.Imm = Imm;
2423 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2424 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2425 Op->RotImm.Imm = Imm;
2431 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2433 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2434 Op->Bitfield.LSB = LSB;
2435 Op->Bitfield.Width = Width;
2442 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2443 SMLoc StartLoc, SMLoc EndLoc) {
2444 assert (Regs.size() > 0 && "RegList contains no registers?");
2445 KindTy Kind = k_RegisterList;
2447 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2448 Kind = k_DPRRegisterList;
2449 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2450 contains(Regs.front().second))
2451 Kind = k_SPRRegisterList;
2453 // Sort based on the register encoding values.
2454 array_pod_sort(Regs.begin(), Regs.end());
2456 ARMOperand *Op = new ARMOperand(Kind);
2457 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2458 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2459 Op->Registers.push_back(I->second);
2460 Op->StartLoc = StartLoc;
2461 Op->EndLoc = EndLoc;
2465 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2466 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2467 ARMOperand *Op = new ARMOperand(k_VectorList);
2468 Op->VectorList.RegNum = RegNum;
2469 Op->VectorList.Count = Count;
2470 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2476 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2477 bool isDoubleSpaced,
2479 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2480 Op->VectorList.RegNum = RegNum;
2481 Op->VectorList.Count = Count;
2482 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2488 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2490 bool isDoubleSpaced,
2492 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2493 Op->VectorList.RegNum = RegNum;
2494 Op->VectorList.Count = Count;
2495 Op->VectorList.LaneIndex = Index;
2496 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2502 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2504 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2505 Op->VectorIndex.Val = Idx;
2511 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2512 ARMOperand *Op = new ARMOperand(k_Immediate);
2519 static ARMOperand *CreateMem(unsigned BaseRegNum,
2520 const MCConstantExpr *OffsetImm,
2521 unsigned OffsetRegNum,
2522 ARM_AM::ShiftOpc ShiftType,
2527 ARMOperand *Op = new ARMOperand(k_Memory);
2528 Op->Memory.BaseRegNum = BaseRegNum;
2529 Op->Memory.OffsetImm = OffsetImm;
2530 Op->Memory.OffsetRegNum = OffsetRegNum;
2531 Op->Memory.ShiftType = ShiftType;
2532 Op->Memory.ShiftImm = ShiftImm;
2533 Op->Memory.Alignment = Alignment;
2534 Op->Memory.isNegative = isNegative;
2540 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2541 ARM_AM::ShiftOpc ShiftTy,
2544 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2545 Op->PostIdxReg.RegNum = RegNum;
2546 Op->PostIdxReg.isAdd = isAdd;
2547 Op->PostIdxReg.ShiftTy = ShiftTy;
2548 Op->PostIdxReg.ShiftImm = ShiftImm;
2554 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2555 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2556 Op->MBOpt.Val = Opt;
2562 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2564 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2565 Op->ISBOpt.Val = Opt;
2571 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2572 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2573 Op->IFlags.Val = IFlags;
2579 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2580 ARMOperand *Op = new ARMOperand(k_MSRMask);
2581 Op->MMask.Val = MMask;
2588 } // end anonymous namespace.
2590 void ARMOperand::print(raw_ostream &OS) const {
2593 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2596 OS << "<ccout " << getReg() << ">";
2598 case k_ITCondMask: {
2599 static const char *const MaskStr[] = {
2600 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2601 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2603 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2604 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2608 OS << "<coprocessor number: " << getCoproc() << ">";
2611 OS << "<coprocessor register: " << getCoproc() << ">";
2613 case k_CoprocOption:
2614 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2617 OS << "<mask: " << getMSRMask() << ">";
2620 getImm()->print(OS);
2622 case k_MemBarrierOpt:
2623 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2625 case k_InstSyncBarrierOpt:
2626 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2630 << " base:" << Memory.BaseRegNum;
2633 case k_PostIndexRegister:
2634 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2635 << PostIdxReg.RegNum;
2636 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2637 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2638 << PostIdxReg.ShiftImm;
2641 case k_ProcIFlags: {
2642 OS << "<ARM_PROC::";
2643 unsigned IFlags = getProcIFlags();
2644 for (int i=2; i >= 0; --i)
2645 if (IFlags & (1 << i))
2646 OS << ARM_PROC::IFlagsToString(1 << i);
2651 OS << "<register " << getReg() << ">";
2653 case k_ShifterImmediate:
2654 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2655 << " #" << ShifterImm.Imm << ">";
2657 case k_ShiftedRegister:
2658 OS << "<so_reg_reg "
2659 << RegShiftedReg.SrcReg << " "
2660 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2661 << " " << RegShiftedReg.ShiftReg << ">";
2663 case k_ShiftedImmediate:
2664 OS << "<so_reg_imm "
2665 << RegShiftedImm.SrcReg << " "
2666 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2667 << " #" << RegShiftedImm.ShiftImm << ">";
2669 case k_RotateImmediate:
2670 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2672 case k_BitfieldDescriptor:
2673 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2674 << ", width: " << Bitfield.Width << ">";
2676 case k_RegisterList:
2677 case k_DPRRegisterList:
2678 case k_SPRRegisterList: {
2679 OS << "<register_list ";
2681 const SmallVectorImpl<unsigned> &RegList = getRegList();
2682 for (SmallVectorImpl<unsigned>::const_iterator
2683 I = RegList.begin(), E = RegList.end(); I != E; ) {
2685 if (++I < E) OS << ", ";
2692 OS << "<vector_list " << VectorList.Count << " * "
2693 << VectorList.RegNum << ">";
2695 case k_VectorListAllLanes:
2696 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2697 << VectorList.RegNum << ">";
2699 case k_VectorListIndexed:
2700 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2701 << VectorList.Count << " * " << VectorList.RegNum << ">";
2704 OS << "'" << getToken() << "'";
2707 OS << "<vectorindex " << getVectorIndex() << ">";
2712 /// @name Auto-generated Match Functions
2715 static unsigned MatchRegisterName(StringRef Name);
2719 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2720 SMLoc &StartLoc, SMLoc &EndLoc) {
2721 StartLoc = Parser.getTok().getLoc();
2722 EndLoc = Parser.getTok().getEndLoc();
2723 RegNo = tryParseRegister();
2725 return (RegNo == (unsigned)-1);
2728 /// Try to parse a register name. The token must be an Identifier when called,
2729 /// and if it is a register name the token is eaten and the register number is
2730 /// returned. Otherwise return -1.
2732 int ARMAsmParser::tryParseRegister() {
2733 const AsmToken &Tok = Parser.getTok();
2734 if (Tok.isNot(AsmToken::Identifier)) return -1;
2736 std::string lowerCase = Tok.getString().lower();
2737 unsigned RegNum = MatchRegisterName(lowerCase);
2739 RegNum = StringSwitch<unsigned>(lowerCase)
2740 .Case("r13", ARM::SP)
2741 .Case("r14", ARM::LR)
2742 .Case("r15", ARM::PC)
2743 .Case("ip", ARM::R12)
2744 // Additional register name aliases for 'gas' compatibility.
2745 .Case("a1", ARM::R0)
2746 .Case("a2", ARM::R1)
2747 .Case("a3", ARM::R2)
2748 .Case("a4", ARM::R3)
2749 .Case("v1", ARM::R4)
2750 .Case("v2", ARM::R5)
2751 .Case("v3", ARM::R6)
2752 .Case("v4", ARM::R7)
2753 .Case("v5", ARM::R8)
2754 .Case("v6", ARM::R9)
2755 .Case("v7", ARM::R10)
2756 .Case("v8", ARM::R11)
2757 .Case("sb", ARM::R9)
2758 .Case("sl", ARM::R10)
2759 .Case("fp", ARM::R11)
2763 // Check for aliases registered via .req. Canonicalize to lower case.
2764 // That's more consistent since register names are case insensitive, and
2765 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2766 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2767 // If no match, return failure.
2768 if (Entry == RegisterReqs.end())
2770 Parser.Lex(); // Eat identifier token.
2771 return Entry->getValue();
2774 Parser.Lex(); // Eat identifier token.
2779 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2780 // If a recoverable error occurs, return 1. If an irrecoverable error
2781 // occurs, return -1. An irrecoverable error is one where tokens have been
2782 // consumed in the process of trying to parse the shifter (i.e., when it is
2783 // indeed a shifter operand, but malformed).
2784 int ARMAsmParser::tryParseShiftRegister(
2785 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2786 SMLoc S = Parser.getTok().getLoc();
2787 const AsmToken &Tok = Parser.getTok();
2788 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2790 std::string lowerCase = Tok.getString().lower();
2791 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2792 .Case("asl", ARM_AM::lsl)
2793 .Case("lsl", ARM_AM::lsl)
2794 .Case("lsr", ARM_AM::lsr)
2795 .Case("asr", ARM_AM::asr)
2796 .Case("ror", ARM_AM::ror)
2797 .Case("rrx", ARM_AM::rrx)
2798 .Default(ARM_AM::no_shift);
2800 if (ShiftTy == ARM_AM::no_shift)
2803 Parser.Lex(); // Eat the operator.
2805 // The source register for the shift has already been added to the
2806 // operand list, so we need to pop it off and combine it into the shifted
2807 // register operand instead.
2808 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2809 if (!PrevOp->isReg())
2810 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2811 int SrcReg = PrevOp->getReg();
2816 if (ShiftTy == ARM_AM::rrx) {
2817 // RRX Doesn't have an explicit shift amount. The encoder expects
2818 // the shift register to be the same as the source register. Seems odd,
2822 // Figure out if this is shifted by a constant or a register (for non-RRX).
2823 if (Parser.getTok().is(AsmToken::Hash) ||
2824 Parser.getTok().is(AsmToken::Dollar)) {
2825 Parser.Lex(); // Eat hash.
2826 SMLoc ImmLoc = Parser.getTok().getLoc();
2827 const MCExpr *ShiftExpr = 0;
2828 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2829 Error(ImmLoc, "invalid immediate shift value");
2832 // The expression must be evaluatable as an immediate.
2833 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2835 Error(ImmLoc, "invalid immediate shift value");
2838 // Range check the immediate.
2839 // lsl, ror: 0 <= imm <= 31
2840 // lsr, asr: 0 <= imm <= 32
2841 Imm = CE->getValue();
2843 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2844 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2845 Error(ImmLoc, "immediate shift value out of range");
2848 // shift by zero is a nop. Always send it through as lsl.
2849 // ('as' compatibility)
2851 ShiftTy = ARM_AM::lsl;
2852 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2853 SMLoc L = Parser.getTok().getLoc();
2854 EndLoc = Parser.getTok().getEndLoc();
2855 ShiftReg = tryParseRegister();
2856 if (ShiftReg == -1) {
2857 Error (L, "expected immediate or register in shift operand");
2861 Error (Parser.getTok().getLoc(),
2862 "expected immediate or register in shift operand");
2867 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2868 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2872 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2879 /// Try to parse a register name. The token must be an Identifier when called.
2880 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2881 /// if there is a "writeback". 'true' if it's not a register.
2883 /// TODO this is likely to change to allow different register types and or to
2884 /// parse for a specific register type.
2886 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2887 const AsmToken &RegTok = Parser.getTok();
2888 int RegNo = tryParseRegister();
2892 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2893 RegTok.getEndLoc()));
2895 const AsmToken &ExclaimTok = Parser.getTok();
2896 if (ExclaimTok.is(AsmToken::Exclaim)) {
2897 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2898 ExclaimTok.getLoc()));
2899 Parser.Lex(); // Eat exclaim token
2903 // Also check for an index operand. This is only legal for vector registers,
2904 // but that'll get caught OK in operand matching, so we don't need to
2905 // explicitly filter everything else out here.
2906 if (Parser.getTok().is(AsmToken::LBrac)) {
2907 SMLoc SIdx = Parser.getTok().getLoc();
2908 Parser.Lex(); // Eat left bracket token.
2910 const MCExpr *ImmVal;
2911 if (getParser().parseExpression(ImmVal))
2913 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2915 return TokError("immediate value expected for vector index");
2917 if (Parser.getTok().isNot(AsmToken::RBrac))
2918 return Error(Parser.getTok().getLoc(), "']' expected");
2920 SMLoc E = Parser.getTok().getEndLoc();
2921 Parser.Lex(); // Eat right bracket token.
2923 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2931 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2932 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2934 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2935 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2937 switch (Name.size()) {
2940 if (Name[0] != CoprocOp)
2956 if (Name[0] != CoprocOp || Name[1] != '1')
2960 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
2961 case '0': return CoprocOp == 'p'? -1: 10;
2962 case '1': return CoprocOp == 'p'? -1: 11;
2963 case '2': return 12;
2964 case '3': return 13;
2965 case '4': return 14;
2966 case '5': return 15;
2971 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2972 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2973 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2974 SMLoc S = Parser.getTok().getLoc();
2975 const AsmToken &Tok = Parser.getTok();
2976 if (!Tok.is(AsmToken::Identifier))
2977 return MatchOperand_NoMatch;
2978 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2979 .Case("eq", ARMCC::EQ)
2980 .Case("ne", ARMCC::NE)
2981 .Case("hs", ARMCC::HS)
2982 .Case("cs", ARMCC::HS)
2983 .Case("lo", ARMCC::LO)
2984 .Case("cc", ARMCC::LO)
2985 .Case("mi", ARMCC::MI)
2986 .Case("pl", ARMCC::PL)
2987 .Case("vs", ARMCC::VS)
2988 .Case("vc", ARMCC::VC)
2989 .Case("hi", ARMCC::HI)
2990 .Case("ls", ARMCC::LS)
2991 .Case("ge", ARMCC::GE)
2992 .Case("lt", ARMCC::LT)
2993 .Case("gt", ARMCC::GT)
2994 .Case("le", ARMCC::LE)
2995 .Case("al", ARMCC::AL)
2998 return MatchOperand_NoMatch;
2999 Parser.Lex(); // Eat the token.
3001 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3003 return MatchOperand_Success;
3006 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
3007 /// token must be an Identifier when called, and if it is a coprocessor
3008 /// number, the token is eaten and the operand is added to the operand list.
3009 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3010 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3011 SMLoc S = Parser.getTok().getLoc();
3012 const AsmToken &Tok = Parser.getTok();
3013 if (Tok.isNot(AsmToken::Identifier))
3014 return MatchOperand_NoMatch;
3016 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
3018 return MatchOperand_NoMatch;
3020 Parser.Lex(); // Eat identifier token.
3021 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
3022 return MatchOperand_Success;
3025 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
3026 /// token must be an Identifier when called, and if it is a coprocessor
3027 /// number, the token is eaten and the operand is added to the operand list.
3028 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3029 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3030 SMLoc S = Parser.getTok().getLoc();
3031 const AsmToken &Tok = Parser.getTok();
3032 if (Tok.isNot(AsmToken::Identifier))
3033 return MatchOperand_NoMatch;
3035 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3037 return MatchOperand_NoMatch;
3039 Parser.Lex(); // Eat identifier token.
3040 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
3041 return MatchOperand_Success;
3044 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3045 /// coproc_option : '{' imm0_255 '}'
3046 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3047 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3048 SMLoc S = Parser.getTok().getLoc();
3050 // If this isn't a '{', this isn't a coprocessor immediate operand.
3051 if (Parser.getTok().isNot(AsmToken::LCurly))
3052 return MatchOperand_NoMatch;
3053 Parser.Lex(); // Eat the '{'
3056 SMLoc Loc = Parser.getTok().getLoc();
3057 if (getParser().parseExpression(Expr)) {
3058 Error(Loc, "illegal expression");
3059 return MatchOperand_ParseFail;
3061 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3062 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3063 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3064 return MatchOperand_ParseFail;
3066 int Val = CE->getValue();
3068 // Check for and consume the closing '}'
3069 if (Parser.getTok().isNot(AsmToken::RCurly))
3070 return MatchOperand_ParseFail;
3071 SMLoc E = Parser.getTok().getEndLoc();
3072 Parser.Lex(); // Eat the '}'
3074 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3075 return MatchOperand_Success;
3078 // For register list parsing, we need to map from raw GPR register numbering
3079 // to the enumeration values. The enumeration values aren't sorted by
3080 // register number due to our using "sp", "lr" and "pc" as canonical names.
3081 static unsigned getNextRegister(unsigned Reg) {
3082 // If this is a GPR, we need to do it manually, otherwise we can rely
3083 // on the sort ordering of the enumeration since the other reg-classes
3085 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3088 default: llvm_unreachable("Invalid GPR number!");
3089 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3090 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3091 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3092 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3093 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3094 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3095 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3096 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3100 // Return the low-subreg of a given Q register.
3101 static unsigned getDRegFromQReg(unsigned QReg) {
3103 default: llvm_unreachable("expected a Q register!");
3104 case ARM::Q0: return ARM::D0;
3105 case ARM::Q1: return ARM::D2;
3106 case ARM::Q2: return ARM::D4;
3107 case ARM::Q3: return ARM::D6;
3108 case ARM::Q4: return ARM::D8;
3109 case ARM::Q5: return ARM::D10;
3110 case ARM::Q6: return ARM::D12;
3111 case ARM::Q7: return ARM::D14;
3112 case ARM::Q8: return ARM::D16;
3113 case ARM::Q9: return ARM::D18;
3114 case ARM::Q10: return ARM::D20;
3115 case ARM::Q11: return ARM::D22;
3116 case ARM::Q12: return ARM::D24;
3117 case ARM::Q13: return ARM::D26;
3118 case ARM::Q14: return ARM::D28;
3119 case ARM::Q15: return ARM::D30;
3123 /// Parse a register list.
3125 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3126 assert(Parser.getTok().is(AsmToken::LCurly) &&
3127 "Token is not a Left Curly Brace");
3128 SMLoc S = Parser.getTok().getLoc();
3129 Parser.Lex(); // Eat '{' token.
3130 SMLoc RegLoc = Parser.getTok().getLoc();
3132 // Check the first register in the list to see what register class
3133 // this is a list of.
3134 int Reg = tryParseRegister();
3136 return Error(RegLoc, "register expected");
3138 // The reglist instructions have at most 16 registers, so reserve
3139 // space for that many.
3141 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3143 // Allow Q regs and just interpret them as the two D sub-registers.
3144 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3145 Reg = getDRegFromQReg(Reg);
3146 EReg = MRI->getEncodingValue(Reg);
3147 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3150 const MCRegisterClass *RC;
3151 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3152 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3153 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3154 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3155 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3156 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3158 return Error(RegLoc, "invalid register in register list");
3160 // Store the register.
3161 EReg = MRI->getEncodingValue(Reg);
3162 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3164 // This starts immediately after the first register token in the list,
3165 // so we can see either a comma or a minus (range separator) as a legal
3167 while (Parser.getTok().is(AsmToken::Comma) ||
3168 Parser.getTok().is(AsmToken::Minus)) {
3169 if (Parser.getTok().is(AsmToken::Minus)) {
3170 Parser.Lex(); // Eat the minus.
3171 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3172 int EndReg = tryParseRegister();
3174 return Error(AfterMinusLoc, "register expected");
3175 // Allow Q regs and just interpret them as the two D sub-registers.
3176 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3177 EndReg = getDRegFromQReg(EndReg) + 1;
3178 // If the register is the same as the start reg, there's nothing
3182 // The register must be in the same register class as the first.
3183 if (!RC->contains(EndReg))
3184 return Error(AfterMinusLoc, "invalid register in register list");
3185 // Ranges must go from low to high.
3186 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3187 return Error(AfterMinusLoc, "bad range in register list");
3189 // Add all the registers in the range to the register list.
3190 while (Reg != EndReg) {
3191 Reg = getNextRegister(Reg);
3192 EReg = MRI->getEncodingValue(Reg);
3193 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3197 Parser.Lex(); // Eat the comma.
3198 RegLoc = Parser.getTok().getLoc();
3200 const AsmToken RegTok = Parser.getTok();
3201 Reg = tryParseRegister();
3203 return Error(RegLoc, "register expected");
3204 // Allow Q regs and just interpret them as the two D sub-registers.
3205 bool isQReg = false;
3206 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3207 Reg = getDRegFromQReg(Reg);
3210 // The register must be in the same register class as the first.
3211 if (!RC->contains(Reg))
3212 return Error(RegLoc, "invalid register in register list");
3213 // List must be monotonically increasing.
3214 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3215 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3216 Warning(RegLoc, "register list not in ascending order");
3218 return Error(RegLoc, "register list not in ascending order");
3220 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3221 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3222 ") in register list");
3225 // VFP register lists must also be contiguous.
3226 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3228 return Error(RegLoc, "non-contiguous register range");
3229 EReg = MRI->getEncodingValue(Reg);
3230 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3232 EReg = MRI->getEncodingValue(++Reg);
3233 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3237 if (Parser.getTok().isNot(AsmToken::RCurly))
3238 return Error(Parser.getTok().getLoc(), "'}' expected");
3239 SMLoc E = Parser.getTok().getEndLoc();
3240 Parser.Lex(); // Eat '}' token.
3242 // Push the register list operand.
3243 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3245 // The ARM system instruction variants for LDM/STM have a '^' token here.
3246 if (Parser.getTok().is(AsmToken::Caret)) {
3247 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3248 Parser.Lex(); // Eat '^' token.
3254 // Helper function to parse the lane index for vector lists.
3255 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3256 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3257 Index = 0; // Always return a defined index value.
3258 if (Parser.getTok().is(AsmToken::LBrac)) {
3259 Parser.Lex(); // Eat the '['.
3260 if (Parser.getTok().is(AsmToken::RBrac)) {
3261 // "Dn[]" is the 'all lanes' syntax.
3262 LaneKind = AllLanes;
3263 EndLoc = Parser.getTok().getEndLoc();
3264 Parser.Lex(); // Eat the ']'.
3265 return MatchOperand_Success;
3268 // There's an optional '#' token here. Normally there wouldn't be, but
3269 // inline assemble puts one in, and it's friendly to accept that.
3270 if (Parser.getTok().is(AsmToken::Hash))
3271 Parser.Lex(); // Eat '#' or '$'.
3273 const MCExpr *LaneIndex;
3274 SMLoc Loc = Parser.getTok().getLoc();
3275 if (getParser().parseExpression(LaneIndex)) {
3276 Error(Loc, "illegal expression");
3277 return MatchOperand_ParseFail;
3279 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3281 Error(Loc, "lane index must be empty or an integer");
3282 return MatchOperand_ParseFail;
3284 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3285 Error(Parser.getTok().getLoc(), "']' expected");
3286 return MatchOperand_ParseFail;
3288 EndLoc = Parser.getTok().getEndLoc();
3289 Parser.Lex(); // Eat the ']'.
3290 int64_t Val = CE->getValue();
3292 // FIXME: Make this range check context sensitive for .8, .16, .32.
3293 if (Val < 0 || Val > 7) {
3294 Error(Parser.getTok().getLoc(), "lane index out of range");
3295 return MatchOperand_ParseFail;
3298 LaneKind = IndexedLane;
3299 return MatchOperand_Success;
3302 return MatchOperand_Success;
3305 // parse a vector register list
3306 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3307 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3308 VectorLaneTy LaneKind;
3310 SMLoc S = Parser.getTok().getLoc();
3311 // As an extension (to match gas), support a plain D register or Q register
3312 // (without encosing curly braces) as a single or double entry list,
3314 if (Parser.getTok().is(AsmToken::Identifier)) {
3315 SMLoc E = Parser.getTok().getEndLoc();
3316 int Reg = tryParseRegister();
3318 return MatchOperand_NoMatch;
3319 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3320 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3321 if (Res != MatchOperand_Success)
3325 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3328 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3332 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3337 return MatchOperand_Success;
3339 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3340 Reg = getDRegFromQReg(Reg);
3341 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3342 if (Res != MatchOperand_Success)
3346 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3347 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3348 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3351 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3352 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3353 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3357 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3362 return MatchOperand_Success;
3364 Error(S, "vector register expected");
3365 return MatchOperand_ParseFail;
3368 if (Parser.getTok().isNot(AsmToken::LCurly))
3369 return MatchOperand_NoMatch;
3371 Parser.Lex(); // Eat '{' token.
3372 SMLoc RegLoc = Parser.getTok().getLoc();
3374 int Reg = tryParseRegister();
3376 Error(RegLoc, "register expected");
3377 return MatchOperand_ParseFail;
3381 unsigned FirstReg = Reg;
3382 // The list is of D registers, but we also allow Q regs and just interpret
3383 // them as the two D sub-registers.
3384 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3385 FirstReg = Reg = getDRegFromQReg(Reg);
3386 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3387 // it's ambiguous with four-register single spaced.
3393 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3394 return MatchOperand_ParseFail;
3396 while (Parser.getTok().is(AsmToken::Comma) ||
3397 Parser.getTok().is(AsmToken::Minus)) {
3398 if (Parser.getTok().is(AsmToken::Minus)) {
3400 Spacing = 1; // Register range implies a single spaced list.
3401 else if (Spacing == 2) {
3402 Error(Parser.getTok().getLoc(),
3403 "sequential registers in double spaced list");
3404 return MatchOperand_ParseFail;
3406 Parser.Lex(); // Eat the minus.
3407 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3408 int EndReg = tryParseRegister();
3410 Error(AfterMinusLoc, "register expected");
3411 return MatchOperand_ParseFail;
3413 // Allow Q regs and just interpret them as the two D sub-registers.
3414 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3415 EndReg = getDRegFromQReg(EndReg) + 1;
3416 // If the register is the same as the start reg, there's nothing
3420 // The register must be in the same register class as the first.
3421 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3422 Error(AfterMinusLoc, "invalid register in register list");
3423 return MatchOperand_ParseFail;
3425 // Ranges must go from low to high.
3427 Error(AfterMinusLoc, "bad range in register list");
3428 return MatchOperand_ParseFail;
3430 // Parse the lane specifier if present.
3431 VectorLaneTy NextLaneKind;
3432 unsigned NextLaneIndex;
3433 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3434 MatchOperand_Success)
3435 return MatchOperand_ParseFail;
3436 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3437 Error(AfterMinusLoc, "mismatched lane index in register list");
3438 return MatchOperand_ParseFail;
3441 // Add all the registers in the range to the register list.
3442 Count += EndReg - Reg;
3446 Parser.Lex(); // Eat the comma.
3447 RegLoc = Parser.getTok().getLoc();
3449 Reg = tryParseRegister();
3451 Error(RegLoc, "register expected");
3452 return MatchOperand_ParseFail;
3454 // vector register lists must be contiguous.
3455 // It's OK to use the enumeration values directly here rather, as the
3456 // VFP register classes have the enum sorted properly.
3458 // The list is of D registers, but we also allow Q regs and just interpret
3459 // them as the two D sub-registers.
3460 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3462 Spacing = 1; // Register range implies a single spaced list.
3463 else if (Spacing == 2) {
3465 "invalid register in double-spaced list (must be 'D' register')");
3466 return MatchOperand_ParseFail;
3468 Reg = getDRegFromQReg(Reg);
3469 if (Reg != OldReg + 1) {
3470 Error(RegLoc, "non-contiguous register range");
3471 return MatchOperand_ParseFail;
3475 // Parse the lane specifier if present.
3476 VectorLaneTy NextLaneKind;
3477 unsigned NextLaneIndex;
3478 SMLoc LaneLoc = Parser.getTok().getLoc();
3479 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3480 MatchOperand_Success)
3481 return MatchOperand_ParseFail;
3482 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3483 Error(LaneLoc, "mismatched lane index in register list");
3484 return MatchOperand_ParseFail;
3488 // Normal D register.
3489 // Figure out the register spacing (single or double) of the list if
3490 // we don't know it already.
3492 Spacing = 1 + (Reg == OldReg + 2);
3494 // Just check that it's contiguous and keep going.
3495 if (Reg != OldReg + Spacing) {
3496 Error(RegLoc, "non-contiguous register range");
3497 return MatchOperand_ParseFail;
3500 // Parse the lane specifier if present.
3501 VectorLaneTy NextLaneKind;
3502 unsigned NextLaneIndex;
3503 SMLoc EndLoc = Parser.getTok().getLoc();
3504 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3505 return MatchOperand_ParseFail;
3506 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3507 Error(EndLoc, "mismatched lane index in register list");
3508 return MatchOperand_ParseFail;
3512 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3513 Error(Parser.getTok().getLoc(), "'}' expected");
3514 return MatchOperand_ParseFail;
3516 E = Parser.getTok().getEndLoc();
3517 Parser.Lex(); // Eat '}' token.
3521 // Two-register operands have been converted to the
3522 // composite register classes.
3524 const MCRegisterClass *RC = (Spacing == 1) ?
3525 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3526 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3527 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3530 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3531 (Spacing == 2), S, E));
3534 // Two-register operands have been converted to the
3535 // composite register classes.
3537 const MCRegisterClass *RC = (Spacing == 1) ?
3538 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3539 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3540 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3542 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3547 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3553 return MatchOperand_Success;
3556 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3557 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3558 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3559 SMLoc S = Parser.getTok().getLoc();
3560 const AsmToken &Tok = Parser.getTok();
3563 if (Tok.is(AsmToken::Identifier)) {
3564 StringRef OptStr = Tok.getString();
3566 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3567 .Case("sy", ARM_MB::SY)
3568 .Case("st", ARM_MB::ST)
3569 .Case("ld", ARM_MB::LD)
3570 .Case("sh", ARM_MB::ISH)
3571 .Case("ish", ARM_MB::ISH)
3572 .Case("shst", ARM_MB::ISHST)
3573 .Case("ishst", ARM_MB::ISHST)
3574 .Case("ishld", ARM_MB::ISHLD)
3575 .Case("nsh", ARM_MB::NSH)
3576 .Case("un", ARM_MB::NSH)
3577 .Case("nshst", ARM_MB::NSHST)
3578 .Case("nshld", ARM_MB::NSHLD)
3579 .Case("unst", ARM_MB::NSHST)
3580 .Case("osh", ARM_MB::OSH)
3581 .Case("oshst", ARM_MB::OSHST)
3582 .Case("oshld", ARM_MB::OSHLD)
3585 // ishld, oshld, nshld and ld are only available from ARMv8.
3586 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3587 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3591 return MatchOperand_NoMatch;
3593 Parser.Lex(); // Eat identifier token.
3594 } else if (Tok.is(AsmToken::Hash) ||
3595 Tok.is(AsmToken::Dollar) ||
3596 Tok.is(AsmToken::Integer)) {
3597 if (Parser.getTok().isNot(AsmToken::Integer))
3598 Parser.Lex(); // Eat '#' or '$'.
3599 SMLoc Loc = Parser.getTok().getLoc();
3601 const MCExpr *MemBarrierID;
3602 if (getParser().parseExpression(MemBarrierID)) {
3603 Error(Loc, "illegal expression");
3604 return MatchOperand_ParseFail;
3607 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3609 Error(Loc, "constant expression expected");
3610 return MatchOperand_ParseFail;
3613 int Val = CE->getValue();
3615 Error(Loc, "immediate value out of range");
3616 return MatchOperand_ParseFail;
3619 Opt = ARM_MB::RESERVED_0 + Val;
3621 return MatchOperand_ParseFail;
3623 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3624 return MatchOperand_Success;
3627 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3628 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3629 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3630 SMLoc S = Parser.getTok().getLoc();
3631 const AsmToken &Tok = Parser.getTok();
3634 if (Tok.is(AsmToken::Identifier)) {
3635 StringRef OptStr = Tok.getString();
3637 if (OptStr.equals_lower("sy"))
3640 return MatchOperand_NoMatch;
3642 Parser.Lex(); // Eat identifier token.
3643 } else if (Tok.is(AsmToken::Hash) ||
3644 Tok.is(AsmToken::Dollar) ||
3645 Tok.is(AsmToken::Integer)) {
3646 if (Parser.getTok().isNot(AsmToken::Integer))
3647 Parser.Lex(); // Eat '#' or '$'.
3648 SMLoc Loc = Parser.getTok().getLoc();
3650 const MCExpr *ISBarrierID;
3651 if (getParser().parseExpression(ISBarrierID)) {
3652 Error(Loc, "illegal expression");
3653 return MatchOperand_ParseFail;
3656 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3658 Error(Loc, "constant expression expected");
3659 return MatchOperand_ParseFail;
3662 int Val = CE->getValue();
3664 Error(Loc, "immediate value out of range");
3665 return MatchOperand_ParseFail;
3668 Opt = ARM_ISB::RESERVED_0 + Val;
3670 return MatchOperand_ParseFail;
3672 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3673 (ARM_ISB::InstSyncBOpt)Opt, S));
3674 return MatchOperand_Success;
3678 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3679 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3680 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3681 SMLoc S = Parser.getTok().getLoc();
3682 const AsmToken &Tok = Parser.getTok();
3683 if (!Tok.is(AsmToken::Identifier))
3684 return MatchOperand_NoMatch;
3685 StringRef IFlagsStr = Tok.getString();
3687 // An iflags string of "none" is interpreted to mean that none of the AIF
3688 // bits are set. Not a terribly useful instruction, but a valid encoding.
3689 unsigned IFlags = 0;
3690 if (IFlagsStr != "none") {
3691 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3692 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3693 .Case("a", ARM_PROC::A)
3694 .Case("i", ARM_PROC::I)
3695 .Case("f", ARM_PROC::F)
3698 // If some specific iflag is already set, it means that some letter is
3699 // present more than once, this is not acceptable.
3700 if (Flag == ~0U || (IFlags & Flag))
3701 return MatchOperand_NoMatch;
3707 Parser.Lex(); // Eat identifier token.
3708 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3709 return MatchOperand_Success;
3712 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3713 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3714 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3715 SMLoc S = Parser.getTok().getLoc();
3716 const AsmToken &Tok = Parser.getTok();
3717 if (!Tok.is(AsmToken::Identifier))
3718 return MatchOperand_NoMatch;
3719 StringRef Mask = Tok.getString();
3722 // See ARMv6-M 10.1.1
3723 std::string Name = Mask.lower();
3724 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3725 // Note: in the documentation:
3726 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3727 // for MSR APSR_nzcvq.
3728 // but we do make it an alias here. This is so to get the "mask encoding"
3729 // bits correct on MSR APSR writes.
3731 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3732 // should really only be allowed when writing a special register. Note
3733 // they get dropped in the MRS instruction reading a special register as
3734 // the SYSm field is only 8 bits.
3736 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3737 // includes the DSP extension but that is not checked.
3738 .Case("apsr", 0x800)
3739 .Case("apsr_nzcvq", 0x800)
3740 .Case("apsr_g", 0x400)
3741 .Case("apsr_nzcvqg", 0xc00)
3742 .Case("iapsr", 0x801)
3743 .Case("iapsr_nzcvq", 0x801)
3744 .Case("iapsr_g", 0x401)
3745 .Case("iapsr_nzcvqg", 0xc01)
3746 .Case("eapsr", 0x802)
3747 .Case("eapsr_nzcvq", 0x802)
3748 .Case("eapsr_g", 0x402)
3749 .Case("eapsr_nzcvqg", 0xc02)
3750 .Case("xpsr", 0x803)
3751 .Case("xpsr_nzcvq", 0x803)
3752 .Case("xpsr_g", 0x403)
3753 .Case("xpsr_nzcvqg", 0xc03)
3754 .Case("ipsr", 0x805)
3755 .Case("epsr", 0x806)
3756 .Case("iepsr", 0x807)
3759 .Case("primask", 0x810)
3760 .Case("basepri", 0x811)
3761 .Case("basepri_max", 0x812)
3762 .Case("faultmask", 0x813)
3763 .Case("control", 0x814)
3766 if (FlagsVal == ~0U)
3767 return MatchOperand_NoMatch;
3769 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3770 // basepri, basepri_max and faultmask only valid for V7m.
3771 return MatchOperand_NoMatch;
3773 Parser.Lex(); // Eat identifier token.
3774 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3775 return MatchOperand_Success;
3778 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3779 size_t Start = 0, Next = Mask.find('_');
3780 StringRef Flags = "";
3781 std::string SpecReg = Mask.slice(Start, Next).lower();
3782 if (Next != StringRef::npos)
3783 Flags = Mask.slice(Next+1, Mask.size());
3785 // FlagsVal contains the complete mask:
3787 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3788 unsigned FlagsVal = 0;
3790 if (SpecReg == "apsr") {
3791 FlagsVal = StringSwitch<unsigned>(Flags)
3792 .Case("nzcvq", 0x8) // same as CPSR_f
3793 .Case("g", 0x4) // same as CPSR_s
3794 .Case("nzcvqg", 0xc) // same as CPSR_fs
3797 if (FlagsVal == ~0U) {
3799 return MatchOperand_NoMatch;
3801 FlagsVal = 8; // No flag
3803 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3804 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3805 if (Flags == "all" || Flags == "")
3807 for (int i = 0, e = Flags.size(); i != e; ++i) {
3808 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3815 // If some specific flag is already set, it means that some letter is
3816 // present more than once, this is not acceptable.
3817 if (FlagsVal == ~0U || (FlagsVal & Flag))
3818 return MatchOperand_NoMatch;
3821 } else // No match for special register.
3822 return MatchOperand_NoMatch;
3824 // Special register without flags is NOT equivalent to "fc" flags.
3825 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3826 // two lines would enable gas compatibility at the expense of breaking
3832 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3833 if (SpecReg == "spsr")
3836 Parser.Lex(); // Eat identifier token.
3837 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3838 return MatchOperand_Success;
3841 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3842 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3843 int Low, int High) {
3844 const AsmToken &Tok = Parser.getTok();
3845 if (Tok.isNot(AsmToken::Identifier)) {
3846 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3847 return MatchOperand_ParseFail;
3849 StringRef ShiftName = Tok.getString();
3850 std::string LowerOp = Op.lower();
3851 std::string UpperOp = Op.upper();
3852 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3853 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3854 return MatchOperand_ParseFail;
3856 Parser.Lex(); // Eat shift type token.
3858 // There must be a '#' and a shift amount.
3859 if (Parser.getTok().isNot(AsmToken::Hash) &&
3860 Parser.getTok().isNot(AsmToken::Dollar)) {
3861 Error(Parser.getTok().getLoc(), "'#' expected");
3862 return MatchOperand_ParseFail;
3864 Parser.Lex(); // Eat hash token.
3866 const MCExpr *ShiftAmount;
3867 SMLoc Loc = Parser.getTok().getLoc();
3869 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3870 Error(Loc, "illegal expression");
3871 return MatchOperand_ParseFail;
3873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3875 Error(Loc, "constant expression expected");
3876 return MatchOperand_ParseFail;
3878 int Val = CE->getValue();
3879 if (Val < Low || Val > High) {
3880 Error(Loc, "immediate value out of range");
3881 return MatchOperand_ParseFail;
3884 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3886 return MatchOperand_Success;
3889 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3890 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3891 const AsmToken &Tok = Parser.getTok();
3892 SMLoc S = Tok.getLoc();
3893 if (Tok.isNot(AsmToken::Identifier)) {
3894 Error(S, "'be' or 'le' operand expected");
3895 return MatchOperand_ParseFail;
3897 int Val = StringSwitch<int>(Tok.getString().lower())
3901 Parser.Lex(); // Eat the token.
3904 Error(S, "'be' or 'le' operand expected");
3905 return MatchOperand_ParseFail;
3907 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3909 S, Tok.getEndLoc()));
3910 return MatchOperand_Success;
3913 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3914 /// instructions. Legal values are:
3915 /// lsl #n 'n' in [0,31]
3916 /// asr #n 'n' in [1,32]
3917 /// n == 32 encoded as n == 0.
3918 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3919 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3920 const AsmToken &Tok = Parser.getTok();
3921 SMLoc S = Tok.getLoc();
3922 if (Tok.isNot(AsmToken::Identifier)) {
3923 Error(S, "shift operator 'asr' or 'lsl' expected");
3924 return MatchOperand_ParseFail;
3926 StringRef ShiftName = Tok.getString();
3928 if (ShiftName == "lsl" || ShiftName == "LSL")
3930 else if (ShiftName == "asr" || ShiftName == "ASR")
3933 Error(S, "shift operator 'asr' or 'lsl' expected");
3934 return MatchOperand_ParseFail;
3936 Parser.Lex(); // Eat the operator.
3938 // A '#' and a shift amount.
3939 if (Parser.getTok().isNot(AsmToken::Hash) &&
3940 Parser.getTok().isNot(AsmToken::Dollar)) {
3941 Error(Parser.getTok().getLoc(), "'#' expected");
3942 return MatchOperand_ParseFail;
3944 Parser.Lex(); // Eat hash token.
3945 SMLoc ExLoc = Parser.getTok().getLoc();
3947 const MCExpr *ShiftAmount;
3949 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3950 Error(ExLoc, "malformed shift expression");
3951 return MatchOperand_ParseFail;
3953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3955 Error(ExLoc, "shift amount must be an immediate");
3956 return MatchOperand_ParseFail;
3959 int64_t Val = CE->getValue();
3961 // Shift amount must be in [1,32]
3962 if (Val < 1 || Val > 32) {
3963 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3964 return MatchOperand_ParseFail;
3966 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3967 if (isThumb() && Val == 32) {
3968 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3969 return MatchOperand_ParseFail;
3971 if (Val == 32) Val = 0;
3973 // Shift amount must be in [1,32]
3974 if (Val < 0 || Val > 31) {
3975 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3976 return MatchOperand_ParseFail;
3980 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3982 return MatchOperand_Success;
3985 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3986 /// of instructions. Legal values are:
3987 /// ror #n 'n' in {0, 8, 16, 24}
3988 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3989 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3990 const AsmToken &Tok = Parser.getTok();
3991 SMLoc S = Tok.getLoc();
3992 if (Tok.isNot(AsmToken::Identifier))
3993 return MatchOperand_NoMatch;
3994 StringRef ShiftName = Tok.getString();
3995 if (ShiftName != "ror" && ShiftName != "ROR")
3996 return MatchOperand_NoMatch;
3997 Parser.Lex(); // Eat the operator.
3999 // A '#' and a rotate amount.
4000 if (Parser.getTok().isNot(AsmToken::Hash) &&
4001 Parser.getTok().isNot(AsmToken::Dollar)) {
4002 Error(Parser.getTok().getLoc(), "'#' expected");
4003 return MatchOperand_ParseFail;
4005 Parser.Lex(); // Eat hash token.
4006 SMLoc ExLoc = Parser.getTok().getLoc();
4008 const MCExpr *ShiftAmount;
4010 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
4011 Error(ExLoc, "malformed rotate expression");
4012 return MatchOperand_ParseFail;
4014 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4016 Error(ExLoc, "rotate amount must be an immediate");
4017 return MatchOperand_ParseFail;
4020 int64_t Val = CE->getValue();
4021 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4022 // normally, zero is represented in asm by omitting the rotate operand
4024 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
4025 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
4026 return MatchOperand_ParseFail;
4029 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
4031 return MatchOperand_Success;
4034 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4035 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4036 SMLoc S = Parser.getTok().getLoc();
4037 // The bitfield descriptor is really two operands, the LSB and the width.
4038 if (Parser.getTok().isNot(AsmToken::Hash) &&
4039 Parser.getTok().isNot(AsmToken::Dollar)) {
4040 Error(Parser.getTok().getLoc(), "'#' expected");
4041 return MatchOperand_ParseFail;
4043 Parser.Lex(); // Eat hash token.
4045 const MCExpr *LSBExpr;
4046 SMLoc E = Parser.getTok().getLoc();
4047 if (getParser().parseExpression(LSBExpr)) {
4048 Error(E, "malformed immediate expression");
4049 return MatchOperand_ParseFail;
4051 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4053 Error(E, "'lsb' operand must be an immediate");
4054 return MatchOperand_ParseFail;
4057 int64_t LSB = CE->getValue();
4058 // The LSB must be in the range [0,31]
4059 if (LSB < 0 || LSB > 31) {
4060 Error(E, "'lsb' operand must be in the range [0,31]");
4061 return MatchOperand_ParseFail;
4063 E = Parser.getTok().getLoc();
4065 // Expect another immediate operand.
4066 if (Parser.getTok().isNot(AsmToken::Comma)) {
4067 Error(Parser.getTok().getLoc(), "too few operands");
4068 return MatchOperand_ParseFail;
4070 Parser.Lex(); // Eat hash token.
4071 if (Parser.getTok().isNot(AsmToken::Hash) &&
4072 Parser.getTok().isNot(AsmToken::Dollar)) {
4073 Error(Parser.getTok().getLoc(), "'#' expected");
4074 return MatchOperand_ParseFail;
4076 Parser.Lex(); // Eat hash token.
4078 const MCExpr *WidthExpr;
4080 if (getParser().parseExpression(WidthExpr, EndLoc)) {
4081 Error(E, "malformed immediate expression");
4082 return MatchOperand_ParseFail;
4084 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4086 Error(E, "'width' operand must be an immediate");
4087 return MatchOperand_ParseFail;
4090 int64_t Width = CE->getValue();
4091 // The LSB must be in the range [1,32-lsb]
4092 if (Width < 1 || Width > 32 - LSB) {
4093 Error(E, "'width' operand must be in the range [1,32-lsb]");
4094 return MatchOperand_ParseFail;
4097 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
4099 return MatchOperand_Success;
4102 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4103 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4104 // Check for a post-index addressing register operand. Specifically:
4105 // postidx_reg := '+' register {, shift}
4106 // | '-' register {, shift}
4107 // | register {, shift}
4109 // This method must return MatchOperand_NoMatch without consuming any tokens
4110 // in the case where there is no match, as other alternatives take other
4112 AsmToken Tok = Parser.getTok();
4113 SMLoc S = Tok.getLoc();
4114 bool haveEaten = false;
4116 if (Tok.is(AsmToken::Plus)) {
4117 Parser.Lex(); // Eat the '+' token.
4119 } else if (Tok.is(AsmToken::Minus)) {
4120 Parser.Lex(); // Eat the '-' token.
4125 SMLoc E = Parser.getTok().getEndLoc();
4126 int Reg = tryParseRegister();
4129 return MatchOperand_NoMatch;
4130 Error(Parser.getTok().getLoc(), "register expected");
4131 return MatchOperand_ParseFail;
4134 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4135 unsigned ShiftImm = 0;
4136 if (Parser.getTok().is(AsmToken::Comma)) {
4137 Parser.Lex(); // Eat the ','.
4138 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4139 return MatchOperand_ParseFail;
4141 // FIXME: Only approximates end...may include intervening whitespace.
4142 E = Parser.getTok().getLoc();
4145 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4148 return MatchOperand_Success;
4151 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4152 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4153 // Check for a post-index addressing register operand. Specifically:
4154 // am3offset := '+' register
4161 // This method must return MatchOperand_NoMatch without consuming any tokens
4162 // in the case where there is no match, as other alternatives take other
4164 AsmToken Tok = Parser.getTok();
4165 SMLoc S = Tok.getLoc();
4167 // Do immediates first, as we always parse those if we have a '#'.
4168 if (Parser.getTok().is(AsmToken::Hash) ||
4169 Parser.getTok().is(AsmToken::Dollar)) {
4170 Parser.Lex(); // Eat '#' or '$'.
4171 // Explicitly look for a '-', as we need to encode negative zero
4173 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4174 const MCExpr *Offset;
4176 if (getParser().parseExpression(Offset, E))
4177 return MatchOperand_ParseFail;
4178 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4180 Error(S, "constant expression expected");
4181 return MatchOperand_ParseFail;
4183 // Negative zero is encoded as the flag value INT32_MIN.
4184 int32_t Val = CE->getValue();
4185 if (isNegative && Val == 0)
4189 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4191 return MatchOperand_Success;
4195 bool haveEaten = false;
4197 if (Tok.is(AsmToken::Plus)) {
4198 Parser.Lex(); // Eat the '+' token.
4200 } else if (Tok.is(AsmToken::Minus)) {
4201 Parser.Lex(); // Eat the '-' token.
4206 Tok = Parser.getTok();
4207 int Reg = tryParseRegister();
4210 return MatchOperand_NoMatch;
4211 Error(Tok.getLoc(), "register expected");
4212 return MatchOperand_ParseFail;
4215 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4216 0, S, Tok.getEndLoc()));
4218 return MatchOperand_Success;
4221 /// Convert parsed operands to MCInst. Needed here because this instruction
4222 /// only has two register operands, but multiplication is commutative so
4223 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4225 cvtThumbMultiply(MCInst &Inst,
4226 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4227 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4228 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4229 // If we have a three-operand form, make sure to set Rn to be the operand
4230 // that isn't the same as Rd.
4232 if (Operands.size() == 6 &&
4233 ((ARMOperand*)Operands[4])->getReg() ==
4234 ((ARMOperand*)Operands[3])->getReg())
4236 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4237 Inst.addOperand(Inst.getOperand(0));
4238 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4242 cvtThumbBranches(MCInst &Inst,
4243 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4244 int CondOp = -1, ImmOp = -1;
4245 switch(Inst.getOpcode()) {
4247 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4250 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4252 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4254 // first decide whether or not the branch should be conditional
4255 // by looking at it's location relative to an IT block
4257 // inside an IT block we cannot have any conditional branches. any
4258 // such instructions needs to be converted to unconditional form
4259 switch(Inst.getOpcode()) {
4260 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4261 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4264 // outside IT blocks we can only have unconditional branches with AL
4265 // condition code or conditional branches with non-AL condition code
4266 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4267 switch(Inst.getOpcode()) {
4270 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4274 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4279 // now decide on encoding size based on branch target range
4280 switch(Inst.getOpcode()) {
4281 // classify tB as either t2B or t1B based on range of immediate operand
4283 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4284 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4285 Inst.setOpcode(ARM::t2B);
4288 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4290 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4291 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4292 Inst.setOpcode(ARM::t2Bcc);
4296 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4297 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4300 /// Parse an ARM memory expression, return false if successful else return true
4301 /// or an error. The first token must be a '[' when called.
4303 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4305 assert(Parser.getTok().is(AsmToken::LBrac) &&
4306 "Token is not a Left Bracket");
4307 S = Parser.getTok().getLoc();
4308 Parser.Lex(); // Eat left bracket token.
4310 const AsmToken &BaseRegTok = Parser.getTok();
4311 int BaseRegNum = tryParseRegister();
4312 if (BaseRegNum == -1)
4313 return Error(BaseRegTok.getLoc(), "register expected");
4315 // The next token must either be a comma, a colon or a closing bracket.
4316 const AsmToken &Tok = Parser.getTok();
4317 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4318 !Tok.is(AsmToken::RBrac))
4319 return Error(Tok.getLoc(), "malformed memory operand");
4321 if (Tok.is(AsmToken::RBrac)) {
4322 E = Tok.getEndLoc();
4323 Parser.Lex(); // Eat right bracket token.
4325 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4326 0, 0, false, S, E));
4328 // If there's a pre-indexing writeback marker, '!', just add it as a token
4329 // operand. It's rather odd, but syntactically valid.
4330 if (Parser.getTok().is(AsmToken::Exclaim)) {
4331 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4332 Parser.Lex(); // Eat the '!'.
4338 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4339 "Lost colon or comma in memory operand?!");
4340 if (Tok.is(AsmToken::Comma)) {
4341 Parser.Lex(); // Eat the comma.
4344 // If we have a ':', it's an alignment specifier.
4345 if (Parser.getTok().is(AsmToken::Colon)) {
4346 Parser.Lex(); // Eat the ':'.
4347 E = Parser.getTok().getLoc();
4350 if (getParser().parseExpression(Expr))
4353 // The expression has to be a constant. Memory references with relocations
4354 // don't come through here, as they use the <label> forms of the relevant
4356 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4358 return Error (E, "constant expression expected");
4361 switch (CE->getValue()) {
4364 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4365 case 16: Align = 2; break;
4366 case 32: Align = 4; break;
4367 case 64: Align = 8; break;
4368 case 128: Align = 16; break;
4369 case 256: Align = 32; break;
4372 // Now we should have the closing ']'
4373 if (Parser.getTok().isNot(AsmToken::RBrac))
4374 return Error(Parser.getTok().getLoc(), "']' expected");
4375 E = Parser.getTok().getEndLoc();
4376 Parser.Lex(); // Eat right bracket token.
4378 // Don't worry about range checking the value here. That's handled by
4379 // the is*() predicates.
4380 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4381 ARM_AM::no_shift, 0, Align,
4384 // If there's a pre-indexing writeback marker, '!', just add it as a token
4386 if (Parser.getTok().is(AsmToken::Exclaim)) {
4387 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4388 Parser.Lex(); // Eat the '!'.
4394 // If we have a '#', it's an immediate offset, else assume it's a register
4395 // offset. Be friendly and also accept a plain integer (without a leading
4396 // hash) for gas compatibility.
4397 if (Parser.getTok().is(AsmToken::Hash) ||
4398 Parser.getTok().is(AsmToken::Dollar) ||
4399 Parser.getTok().is(AsmToken::Integer)) {
4400 if (Parser.getTok().isNot(AsmToken::Integer))
4401 Parser.Lex(); // Eat '#' or '$'.
4402 E = Parser.getTok().getLoc();
4404 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4405 const MCExpr *Offset;
4406 if (getParser().parseExpression(Offset))
4409 // The expression has to be a constant. Memory references with relocations
4410 // don't come through here, as they use the <label> forms of the relevant
4412 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4414 return Error (E, "constant expression expected");
4416 // If the constant was #-0, represent it as INT32_MIN.
4417 int32_t Val = CE->getValue();
4418 if (isNegative && Val == 0)
4419 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4421 // Now we should have the closing ']'
4422 if (Parser.getTok().isNot(AsmToken::RBrac))
4423 return Error(Parser.getTok().getLoc(), "']' expected");
4424 E = Parser.getTok().getEndLoc();
4425 Parser.Lex(); // Eat right bracket token.
4427 // Don't worry about range checking the value here. That's handled by
4428 // the is*() predicates.
4429 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4430 ARM_AM::no_shift, 0, 0,
4433 // If there's a pre-indexing writeback marker, '!', just add it as a token
4435 if (Parser.getTok().is(AsmToken::Exclaim)) {
4436 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4437 Parser.Lex(); // Eat the '!'.
4443 // The register offset is optionally preceded by a '+' or '-'
4444 bool isNegative = false;
4445 if (Parser.getTok().is(AsmToken::Minus)) {
4447 Parser.Lex(); // Eat the '-'.
4448 } else if (Parser.getTok().is(AsmToken::Plus)) {
4450 Parser.Lex(); // Eat the '+'.
4453 E = Parser.getTok().getLoc();
4454 int OffsetRegNum = tryParseRegister();
4455 if (OffsetRegNum == -1)
4456 return Error(E, "register expected");
4458 // If there's a shift operator, handle it.
4459 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4460 unsigned ShiftImm = 0;
4461 if (Parser.getTok().is(AsmToken::Comma)) {
4462 Parser.Lex(); // Eat the ','.
4463 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4467 // Now we should have the closing ']'
4468 if (Parser.getTok().isNot(AsmToken::RBrac))
4469 return Error(Parser.getTok().getLoc(), "']' expected");
4470 E = Parser.getTok().getEndLoc();
4471 Parser.Lex(); // Eat right bracket token.
4473 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4474 ShiftType, ShiftImm, 0, isNegative,
4477 // If there's a pre-indexing writeback marker, '!', just add it as a token
4479 if (Parser.getTok().is(AsmToken::Exclaim)) {
4480 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4481 Parser.Lex(); // Eat the '!'.
4487 /// parseMemRegOffsetShift - one of these two:
4488 /// ( lsl | lsr | asr | ror ) , # shift_amount
4490 /// return true if it parses a shift otherwise it returns false.
4491 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4493 SMLoc Loc = Parser.getTok().getLoc();
4494 const AsmToken &Tok = Parser.getTok();
4495 if (Tok.isNot(AsmToken::Identifier))
4497 StringRef ShiftName = Tok.getString();
4498 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4499 ShiftName == "asl" || ShiftName == "ASL")
4501 else if (ShiftName == "lsr" || ShiftName == "LSR")
4503 else if (ShiftName == "asr" || ShiftName == "ASR")
4505 else if (ShiftName == "ror" || ShiftName == "ROR")
4507 else if (ShiftName == "rrx" || ShiftName == "RRX")
4510 return Error(Loc, "illegal shift operator");
4511 Parser.Lex(); // Eat shift type token.
4513 // rrx stands alone.
4515 if (St != ARM_AM::rrx) {
4516 Loc = Parser.getTok().getLoc();
4517 // A '#' and a shift amount.
4518 const AsmToken &HashTok = Parser.getTok();
4519 if (HashTok.isNot(AsmToken::Hash) &&
4520 HashTok.isNot(AsmToken::Dollar))
4521 return Error(HashTok.getLoc(), "'#' expected");
4522 Parser.Lex(); // Eat hash token.
4525 if (getParser().parseExpression(Expr))
4527 // Range check the immediate.
4528 // lsl, ror: 0 <= imm <= 31
4529 // lsr, asr: 0 <= imm <= 32
4530 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4532 return Error(Loc, "shift amount must be an immediate");
4533 int64_t Imm = CE->getValue();
4535 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4536 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4537 return Error(Loc, "immediate shift value out of range");
4538 // If <ShiftTy> #0, turn it into a no_shift.
4541 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4550 /// parseFPImm - A floating point immediate expression operand.
4551 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4552 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4553 // Anything that can accept a floating point constant as an operand
4554 // needs to go through here, as the regular parseExpression is
4557 // This routine still creates a generic Immediate operand, containing
4558 // a bitcast of the 64-bit floating point value. The various operands
4559 // that accept floats can check whether the value is valid for them
4560 // via the standard is*() predicates.
4562 SMLoc S = Parser.getTok().getLoc();
4564 if (Parser.getTok().isNot(AsmToken::Hash) &&
4565 Parser.getTok().isNot(AsmToken::Dollar))
4566 return MatchOperand_NoMatch;
4568 // Disambiguate the VMOV forms that can accept an FP immediate.
4569 // vmov.f32 <sreg>, #imm
4570 // vmov.f64 <dreg>, #imm
4571 // vmov.f32 <dreg>, #imm @ vector f32x2
4572 // vmov.f32 <qreg>, #imm @ vector f32x4
4574 // There are also the NEON VMOV instructions which expect an
4575 // integer constant. Make sure we don't try to parse an FPImm
4577 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4578 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4579 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4580 TyOp->getToken() != ".f64"))
4581 return MatchOperand_NoMatch;
4583 Parser.Lex(); // Eat '#' or '$'.
4585 // Handle negation, as that still comes through as a separate token.
4586 bool isNegative = false;
4587 if (Parser.getTok().is(AsmToken::Minus)) {
4591 const AsmToken &Tok = Parser.getTok();
4592 SMLoc Loc = Tok.getLoc();
4593 if (Tok.is(AsmToken::Real)) {
4594 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4595 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4596 // If we had a '-' in front, toggle the sign bit.
4597 IntVal ^= (uint64_t)isNegative << 31;
4598 Parser.Lex(); // Eat the token.
4599 Operands.push_back(ARMOperand::CreateImm(
4600 MCConstantExpr::Create(IntVal, getContext()),
4601 S, Parser.getTok().getLoc()));
4602 return MatchOperand_Success;
4604 // Also handle plain integers. Instructions which allow floating point
4605 // immediates also allow a raw encoded 8-bit value.
4606 if (Tok.is(AsmToken::Integer)) {
4607 int64_t Val = Tok.getIntVal();
4608 Parser.Lex(); // Eat the token.
4609 if (Val > 255 || Val < 0) {
4610 Error(Loc, "encoded floating point value out of range");
4611 return MatchOperand_ParseFail;
4613 double RealVal = ARM_AM::getFPImmFloat(Val);
4614 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4615 Operands.push_back(ARMOperand::CreateImm(
4616 MCConstantExpr::Create(Val, getContext()), S,
4617 Parser.getTok().getLoc()));
4618 return MatchOperand_Success;
4621 Error(Loc, "invalid floating point immediate");
4622 return MatchOperand_ParseFail;
4625 /// Parse a arm instruction operand. For now this parses the operand regardless
4626 /// of the mnemonic.
4627 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4628 StringRef Mnemonic) {
4631 // Check if the current operand has a custom associated parser, if so, try to
4632 // custom parse the operand, or fallback to the general approach.
4633 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4634 if (ResTy == MatchOperand_Success)
4636 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4637 // there was a match, but an error occurred, in which case, just return that
4638 // the operand parsing failed.
4639 if (ResTy == MatchOperand_ParseFail)
4642 switch (getLexer().getKind()) {
4644 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4646 case AsmToken::Identifier: {
4647 // If we've seen a branch mnemonic, the next operand must be a label. This
4648 // is true even if the label is a register name. So "br r1" means branch to
4650 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4652 if (!tryParseRegisterWithWriteBack(Operands))
4654 int Res = tryParseShiftRegister(Operands);
4655 if (Res == 0) // success
4657 else if (Res == -1) // irrecoverable error
4659 // If this is VMRS, check for the apsr_nzcv operand.
4660 if (Mnemonic == "vmrs" &&
4661 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4662 S = Parser.getTok().getLoc();
4664 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4669 // Fall though for the Identifier case that is not a register or a
4672 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4673 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4674 case AsmToken::String: // quoted label names.
4675 case AsmToken::Dot: { // . as a branch target
4676 // This was not a register so parse other operands that start with an
4677 // identifier (like labels) as expressions and create them as immediates.
4678 const MCExpr *IdVal;
4679 S = Parser.getTok().getLoc();
4680 if (getParser().parseExpression(IdVal))
4682 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4683 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4686 case AsmToken::LBrac:
4687 return parseMemory(Operands);
4688 case AsmToken::LCurly:
4689 return parseRegisterList(Operands);
4690 case AsmToken::Dollar:
4691 case AsmToken::Hash: {
4692 // #42 -> immediate.
4693 S = Parser.getTok().getLoc();
4696 if (Parser.getTok().isNot(AsmToken::Colon)) {
4697 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4698 const MCExpr *ImmVal;
4699 if (getParser().parseExpression(ImmVal))
4701 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4703 int32_t Val = CE->getValue();
4704 if (isNegative && Val == 0)
4705 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4707 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4708 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4710 // There can be a trailing '!' on operands that we want as a separate
4711 // '!' Token operand. Handle that here. For example, the compatibility
4712 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4713 if (Parser.getTok().is(AsmToken::Exclaim)) {
4714 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4715 Parser.getTok().getLoc()));
4716 Parser.Lex(); // Eat exclaim token
4720 // w/ a ':' after the '#', it's just like a plain ':'.
4723 case AsmToken::Colon: {
4724 // ":lower16:" and ":upper16:" expression prefixes
4725 // FIXME: Check it's an expression prefix,
4726 // e.g. (FOO - :lower16:BAR) isn't legal.
4727 ARMMCExpr::VariantKind RefKind;
4728 if (parsePrefix(RefKind))
4731 const MCExpr *SubExprVal;
4732 if (getParser().parseExpression(SubExprVal))
4735 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4737 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4738 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4741 case AsmToken::Equal: {
4742 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4743 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4745 const MCSection *Section =
4746 getParser().getStreamer().getCurrentSection().first;
4748 Parser.Lex(); // Eat '='
4749 const MCExpr *SubExprVal;
4750 if (getParser().parseExpression(SubExprVal))
4752 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4754 const MCExpr *CPLoc =
4755 getOrCreateConstantPool(Section).addEntry(SubExprVal, getContext());
4756 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4762 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4763 // :lower16: and :upper16:.
4764 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4765 RefKind = ARMMCExpr::VK_ARM_None;
4767 // :lower16: and :upper16: modifiers
4768 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4769 Parser.Lex(); // Eat ':'
4771 if (getLexer().isNot(AsmToken::Identifier)) {
4772 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4776 StringRef IDVal = Parser.getTok().getIdentifier();
4777 if (IDVal == "lower16") {
4778 RefKind = ARMMCExpr::VK_ARM_LO16;
4779 } else if (IDVal == "upper16") {
4780 RefKind = ARMMCExpr::VK_ARM_HI16;
4782 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4787 if (getLexer().isNot(AsmToken::Colon)) {
4788 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4791 Parser.Lex(); // Eat the last ':'
4795 /// \brief Given a mnemonic, split out possible predication code and carry
4796 /// setting letters to form a canonical mnemonic and flags.
4798 // FIXME: Would be nice to autogen this.
4799 // FIXME: This is a bit of a maze of special cases.
4800 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4801 unsigned &PredicationCode,
4803 unsigned &ProcessorIMod,
4804 StringRef &ITMask) {
4805 PredicationCode = ARMCC::AL;
4806 CarrySetting = false;
4809 // Ignore some mnemonics we know aren't predicated forms.
4811 // FIXME: Would be nice to autogen this.
4812 if ((Mnemonic == "movs" && isThumb()) ||
4813 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4814 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4815 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4816 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4817 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
4818 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4819 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4820 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4821 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
4822 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4823 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4824 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
4827 // First, split out any predication code. Ignore mnemonics we know aren't
4828 // predicated but do have a carry-set and so weren't caught above.
4829 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4830 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4831 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4832 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4833 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4834 .Case("eq", ARMCC::EQ)
4835 .Case("ne", ARMCC::NE)
4836 .Case("hs", ARMCC::HS)
4837 .Case("cs", ARMCC::HS)
4838 .Case("lo", ARMCC::LO)
4839 .Case("cc", ARMCC::LO)
4840 .Case("mi", ARMCC::MI)
4841 .Case("pl", ARMCC::PL)
4842 .Case("vs", ARMCC::VS)
4843 .Case("vc", ARMCC::VC)
4844 .Case("hi", ARMCC::HI)
4845 .Case("ls", ARMCC::LS)
4846 .Case("ge", ARMCC::GE)
4847 .Case("lt", ARMCC::LT)
4848 .Case("gt", ARMCC::GT)
4849 .Case("le", ARMCC::LE)
4850 .Case("al", ARMCC::AL)
4853 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4854 PredicationCode = CC;
4858 // Next, determine if we have a carry setting bit. We explicitly ignore all
4859 // the instructions we know end in 's'.
4860 if (Mnemonic.endswith("s") &&
4861 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4862 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4863 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4864 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4865 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4866 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4867 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4868 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4869 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4870 (Mnemonic == "movs" && isThumb()))) {
4871 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4872 CarrySetting = true;
4875 // The "cps" instruction can have a interrupt mode operand which is glued into
4876 // the mnemonic. Check if this is the case, split it and parse the imod op
4877 if (Mnemonic.startswith("cps")) {
4878 // Split out any imod code.
4880 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4881 .Case("ie", ARM_PROC::IE)
4882 .Case("id", ARM_PROC::ID)
4885 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4886 ProcessorIMod = IMod;
4890 // The "it" instruction has the condition mask on the end of the mnemonic.
4891 if (Mnemonic.startswith("it")) {
4892 ITMask = Mnemonic.slice(2, Mnemonic.size());
4893 Mnemonic = Mnemonic.slice(0, 2);
4899 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4900 /// inclusion of carry set or predication code operands.
4902 // FIXME: It would be nice to autogen this.
4904 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4905 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
4906 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4907 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4908 Mnemonic == "add" || Mnemonic == "adc" ||
4909 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4910 Mnemonic == "orr" || Mnemonic == "mvn" ||
4911 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4912 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4913 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4914 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4915 Mnemonic == "mla" || Mnemonic == "smlal" ||
4916 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4917 CanAcceptCarrySet = true;
4919 CanAcceptCarrySet = false;
4921 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4922 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4923 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
4924 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4925 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
4926 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4927 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4928 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4929 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4930 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
4931 // These mnemonics are never predicable
4932 CanAcceptPredicationCode = false;
4933 } else if (!isThumb()) {
4934 // Some instructions are only predicable in Thumb mode
4935 CanAcceptPredicationCode
4936 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4937 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4938 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4939 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4940 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4941 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4942 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4943 } else if (isThumbOne()) {
4945 CanAcceptPredicationCode = Mnemonic != "movs";
4947 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4949 CanAcceptPredicationCode = true;
4952 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4953 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4954 // FIXME: This is all horribly hacky. We really need a better way to deal
4955 // with optional operands like this in the matcher table.
4957 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4958 // another does not. Specifically, the MOVW instruction does not. So we
4959 // special case it here and remove the defaulted (non-setting) cc_out
4960 // operand if that's the instruction we're trying to match.
4962 // We do this as post-processing of the explicit operands rather than just
4963 // conditionally adding the cc_out in the first place because we need
4964 // to check the type of the parsed immediate operand.
4965 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4966 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4967 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4968 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4971 // Register-register 'add' for thumb does not have a cc_out operand
4972 // when there are only two register operands.
4973 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4974 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4975 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4976 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4978 // Register-register 'add' for thumb does not have a cc_out operand
4979 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4980 // have to check the immediate range here since Thumb2 has a variant
4981 // that can handle a different range and has a cc_out operand.
4982 if (((isThumb() && Mnemonic == "add") ||
4983 (isThumbTwo() && Mnemonic == "sub")) &&
4984 Operands.size() == 6 &&
4985 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4986 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4987 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4988 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4989 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4990 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4992 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4993 // imm0_4095 variant. That's the least-preferred variant when
4994 // selecting via the generic "add" mnemonic, so to know that we
4995 // should remove the cc_out operand, we have to explicitly check that
4996 // it's not one of the other variants. Ugh.
4997 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4998 Operands.size() == 6 &&
4999 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5000 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5001 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5002 // Nest conditions rather than one big 'if' statement for readability.
5004 // If both registers are low, we're in an IT block, and the immediate is
5005 // in range, we should use encoding T1 instead, which has a cc_out.
5007 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5008 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5009 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5011 // Check against T3. If the second register is the PC, this is an
5012 // alternate form of ADR, which uses encoding T4, so check for that too.
5013 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5014 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5017 // Otherwise, we use encoding T4, which does not have a cc_out
5022 // The thumb2 multiply instruction doesn't have a CCOut register, so
5023 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5024 // use the 16-bit encoding or not.
5025 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5026 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5027 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5028 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5029 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5030 // If the registers aren't low regs, the destination reg isn't the
5031 // same as one of the source regs, or the cc_out operand is zero
5032 // outside of an IT block, we have to use the 32-bit encoding, so
5033 // remove the cc_out operand.
5034 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5035 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5036 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
5038 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5039 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5040 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5041 static_cast<ARMOperand*>(Operands[4])->getReg())))
5044 // Also check the 'mul' syntax variant that doesn't specify an explicit
5045 // destination register.
5046 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5047 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5048 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5049 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5050 // If the registers aren't low regs or the cc_out operand is zero
5051 // outside of an IT block, we have to use the 32-bit encoding, so
5052 // remove the cc_out operand.
5053 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5054 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5060 // Register-register 'add/sub' for thumb does not have a cc_out operand
5061 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5062 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5063 // right, this will result in better diagnostics (which operand is off)
5065 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5066 (Operands.size() == 5 || Operands.size() == 6) &&
5067 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5068 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
5069 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5070 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5071 (Operands.size() == 6 &&
5072 static_cast<ARMOperand*>(Operands[5])->isImm())))
5078 bool ARMAsmParser::shouldOmitPredicateOperand(
5079 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
5080 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5081 unsigned RegIdx = 3;
5082 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5083 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
5084 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
5085 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
5088 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
5089 (ARMMCRegisterClasses[ARM::DPRRegClassID]
5090 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
5091 ARMMCRegisterClasses[ARM::QPRRegClassID]
5092 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
5098 static bool isDataTypeToken(StringRef Tok) {
5099 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5100 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5101 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5102 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5103 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5104 Tok == ".f" || Tok == ".d";
5107 // FIXME: This bit should probably be handled via an explicit match class
5108 // in the .td files that matches the suffix instead of having it be
5109 // a literal string token the way it is now.
5110 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5111 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5113 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5114 unsigned VariantID);
5116 static bool RequiresVFPRegListValidation(StringRef Inst,
5117 bool &AcceptSinglePrecisionOnly,
5118 bool &AcceptDoublePrecisionOnly) {
5119 if (Inst.size() < 7)
5122 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5123 StringRef AddressingMode = Inst.substr(4, 2);
5124 if (AddressingMode == "ia" || AddressingMode == "db" ||
5125 AddressingMode == "ea" || AddressingMode == "fd") {
5126 AcceptSinglePrecisionOnly = Inst[6] == 's';
5127 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5135 /// Parse an arm instruction mnemonic followed by its operands.
5136 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5138 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5139 // FIXME: Can this be done via tablegen in some fashion?
5140 bool RequireVFPRegisterListCheck;
5141 bool AcceptSinglePrecisionOnly;
5142 bool AcceptDoublePrecisionOnly;
5143 RequireVFPRegisterListCheck =
5144 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5145 AcceptDoublePrecisionOnly);
5147 // Apply mnemonic aliases before doing anything else, as the destination
5148 // mnemonic may include suffices and we want to handle them normally.
5149 // The generic tblgen'erated code does this later, at the start of
5150 // MatchInstructionImpl(), but that's too late for aliases that include
5151 // any sort of suffix.
5152 unsigned AvailableFeatures = getAvailableFeatures();
5153 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5154 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5156 // First check for the ARM-specific .req directive.
5157 if (Parser.getTok().is(AsmToken::Identifier) &&
5158 Parser.getTok().getIdentifier() == ".req") {
5159 parseDirectiveReq(Name, NameLoc);
5160 // We always return 'error' for this, as we're done with this
5161 // statement and don't need to match the 'instruction."
5165 // Create the leading tokens for the mnemonic, split by '.' characters.
5166 size_t Start = 0, Next = Name.find('.');
5167 StringRef Mnemonic = Name.slice(Start, Next);
5169 // Split out the predication code and carry setting flag from the mnemonic.
5170 unsigned PredicationCode;
5171 unsigned ProcessorIMod;
5174 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5175 ProcessorIMod, ITMask);
5177 // In Thumb1, only the branch (B) instruction can be predicated.
5178 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5179 Parser.eatToEndOfStatement();
5180 return Error(NameLoc, "conditional execution not supported in Thumb1");
5183 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5185 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5186 // is the mask as it will be for the IT encoding if the conditional
5187 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5188 // where the conditional bit0 is zero, the instruction post-processing
5189 // will adjust the mask accordingly.
5190 if (Mnemonic == "it") {
5191 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5192 if (ITMask.size() > 3) {
5193 Parser.eatToEndOfStatement();
5194 return Error(Loc, "too many conditions on IT instruction");
5197 for (unsigned i = ITMask.size(); i != 0; --i) {
5198 char pos = ITMask[i - 1];
5199 if (pos != 't' && pos != 'e') {
5200 Parser.eatToEndOfStatement();
5201 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5204 if (ITMask[i - 1] == 't')
5207 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5210 // FIXME: This is all a pretty gross hack. We should automatically handle
5211 // optional operands like this via tblgen.
5213 // Next, add the CCOut and ConditionCode operands, if needed.
5215 // For mnemonics which can ever incorporate a carry setting bit or predication
5216 // code, our matching model involves us always generating CCOut and
5217 // ConditionCode operands to match the mnemonic "as written" and then we let
5218 // the matcher deal with finding the right instruction or generating an
5219 // appropriate error.
5220 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5221 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5223 // If we had a carry-set on an instruction that can't do that, issue an
5225 if (!CanAcceptCarrySet && CarrySetting) {
5226 Parser.eatToEndOfStatement();
5227 return Error(NameLoc, "instruction '" + Mnemonic +
5228 "' can not set flags, but 's' suffix specified");
5230 // If we had a predication code on an instruction that can't do that, issue an
5232 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5233 Parser.eatToEndOfStatement();
5234 return Error(NameLoc, "instruction '" + Mnemonic +
5235 "' is not predicable, but condition code specified");
5238 // Add the carry setting operand, if necessary.
5239 if (CanAcceptCarrySet) {
5240 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5241 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5245 // Add the predication code operand, if necessary.
5246 if (CanAcceptPredicationCode) {
5247 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5249 Operands.push_back(ARMOperand::CreateCondCode(
5250 ARMCC::CondCodes(PredicationCode), Loc));
5253 // Add the processor imod operand, if necessary.
5254 if (ProcessorIMod) {
5255 Operands.push_back(ARMOperand::CreateImm(
5256 MCConstantExpr::Create(ProcessorIMod, getContext()),
5260 // Add the remaining tokens in the mnemonic.
5261 while (Next != StringRef::npos) {
5263 Next = Name.find('.', Start + 1);
5264 StringRef ExtraToken = Name.slice(Start, Next);
5266 // Some NEON instructions have an optional datatype suffix that is
5267 // completely ignored. Check for that.
5268 if (isDataTypeToken(ExtraToken) &&
5269 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5272 // For for ARM mode generate an error if the .n qualifier is used.
5273 if (ExtraToken == ".n" && !isThumb()) {
5274 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5275 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5279 // The .n qualifier is always discarded as that is what the tables
5280 // and matcher expect. In ARM mode the .w qualifier has no effect,
5281 // so discard it to avoid errors that can be caused by the matcher.
5282 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5283 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5284 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5288 // Read the remaining operands.
5289 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5290 // Read the first operand.
5291 if (parseOperand(Operands, Mnemonic)) {
5292 Parser.eatToEndOfStatement();
5296 while (getLexer().is(AsmToken::Comma)) {
5297 Parser.Lex(); // Eat the comma.
5299 // Parse and remember the operand.
5300 if (parseOperand(Operands, Mnemonic)) {
5301 Parser.eatToEndOfStatement();
5307 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5308 SMLoc Loc = getLexer().getLoc();
5309 Parser.eatToEndOfStatement();
5310 return Error(Loc, "unexpected token in argument list");
5313 Parser.Lex(); // Consume the EndOfStatement
5315 if (RequireVFPRegisterListCheck) {
5316 ARMOperand *Op = static_cast<ARMOperand*>(Operands.back());
5317 if (AcceptSinglePrecisionOnly && !Op->isSPRRegList())
5318 return Error(Op->getStartLoc(),
5319 "VFP/Neon single precision register expected");
5320 if (AcceptDoublePrecisionOnly && !Op->isDPRRegList())
5321 return Error(Op->getStartLoc(),
5322 "VFP/Neon double precision register expected");
5325 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5326 // do and don't have a cc_out optional-def operand. With some spot-checks
5327 // of the operand list, we can figure out which variant we're trying to
5328 // parse and adjust accordingly before actually matching. We shouldn't ever
5329 // try to remove a cc_out operand that was explicitly set on the the
5330 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5331 // table driven matcher doesn't fit well with the ARM instruction set.
5332 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5333 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5334 Operands.erase(Operands.begin() + 1);
5338 // Some instructions have the same mnemonic, but don't always
5339 // have a predicate. Distinguish them here and delete the
5340 // predicate if needed.
5341 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5342 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5343 Operands.erase(Operands.begin() + 1);
5347 // ARM mode 'blx' need special handling, as the register operand version
5348 // is predicable, but the label operand version is not. So, we can't rely
5349 // on the Mnemonic based checking to correctly figure out when to put
5350 // a k_CondCode operand in the list. If we're trying to match the label
5351 // version, remove the k_CondCode operand here.
5352 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5353 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5354 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5355 Operands.erase(Operands.begin() + 1);
5359 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5360 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5361 // a single GPRPair reg operand is used in the .td file to replace the two
5362 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5363 // expressed as a GPRPair, so we have to manually merge them.
5364 // FIXME: We would really like to be able to tablegen'erate this.
5365 if (!isThumb() && Operands.size() > 4 &&
5366 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5367 Mnemonic == "stlexd")) {
5368 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5369 unsigned Idx = isLoad ? 2 : 3;
5370 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5371 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5373 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5374 // Adjust only if Op1 and Op2 are GPRs.
5375 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5376 MRC.contains(Op2->getReg())) {
5377 unsigned Reg1 = Op1->getReg();
5378 unsigned Reg2 = Op2->getReg();
5379 unsigned Rt = MRI->getEncodingValue(Reg1);
5380 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5382 // Rt2 must be Rt + 1 and Rt must be even.
5383 if (Rt + 1 != Rt2 || (Rt & 1)) {
5384 Error(Op2->getStartLoc(), isLoad ?
5385 "destination operands must be sequential" :
5386 "source operands must be sequential");
5389 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5390 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5391 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5392 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5393 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5399 // FIXME: As said above, this is all a pretty gross hack. This instruction
5400 // does not fit with other "subs" and tblgen.
5401 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5402 // so the Mnemonic is the original name "subs" and delete the predicate
5403 // operand so it will match the table entry.
5404 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5405 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5406 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5407 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5408 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5409 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5410 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5411 Operands.erase(Operands.begin());
5413 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5415 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5416 Operands.erase(Operands.begin() + 1);
5422 // Validate context-sensitive operand constraints.
5424 // return 'true' if register list contains non-low GPR registers,
5425 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5426 // 'containsReg' to true.
5427 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5428 unsigned HiReg, bool &containsReg) {
5429 containsReg = false;
5430 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5431 unsigned OpReg = Inst.getOperand(i).getReg();
5434 // Anything other than a low register isn't legal here.
5435 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5441 // Check if the specified regisgter is in the register list of the inst,
5442 // starting at the indicated operand number.
5443 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5444 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5445 unsigned OpReg = Inst.getOperand(i).getReg();
5452 // Return true if instruction has the interesting property of being
5453 // allowed in IT blocks, but not being predicable.
5454 static bool instIsBreakpoint(const MCInst &Inst) {
5455 return Inst.getOpcode() == ARM::tBKPT ||
5456 Inst.getOpcode() == ARM::BKPT ||
5457 Inst.getOpcode() == ARM::tHLT ||
5458 Inst.getOpcode() == ARM::HLT;
5462 // FIXME: We would really like to be able to tablegen'erate this.
5464 validateInstruction(MCInst &Inst,
5465 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5466 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
5467 SMLoc Loc = Operands[0]->getStartLoc();
5469 // Check the IT block state first.
5470 // NOTE: BKPT and HLT instructions have the interesting property of being
5471 // allowed in IT blocks, but not being predicable. They just always execute.
5472 if (inITBlock() && !instIsBreakpoint(Inst)) {
5474 if (ITState.FirstCond)
5475 ITState.FirstCond = false;
5477 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5478 // The instruction must be predicable.
5479 if (!MCID.isPredicable())
5480 return Error(Loc, "instructions in IT block must be predicable");
5481 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5482 unsigned ITCond = Bit ? ITState.Cond :
5483 ARMCC::getOppositeCondition(ITState.Cond);
5484 if (Cond != ITCond) {
5485 // Find the condition code Operand to get its SMLoc information.
5487 for (unsigned I = 1; I < Operands.size(); ++I)
5488 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5489 CondLoc = Operands[I]->getStartLoc();
5490 return Error(CondLoc, "incorrect condition in IT block; got '" +
5491 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5492 "', but expected '" +
5493 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5495 // Check for non-'al' condition codes outside of the IT block.
5496 } else if (isThumbTwo() && MCID.isPredicable() &&
5497 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5498 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5499 Inst.getOpcode() != ARM::t2Bcc)
5500 return Error(Loc, "predicated instructions must be in IT block");
5502 const unsigned Opcode = Inst.getOpcode();
5506 case ARM::LDRD_POST: {
5507 const unsigned RtReg = Inst.getOperand(0).getReg();
5510 if (RtReg == ARM::LR)
5511 return Error(Operands[3]->getStartLoc(),
5514 const unsigned Rt = MRI->getEncodingValue(RtReg);
5515 // Rt must be even-numbered.
5517 return Error(Operands[3]->getStartLoc(),
5518 "Rt must be even-numbered");
5520 // Rt2 must be Rt + 1.
5521 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5523 return Error(Operands[3]->getStartLoc(),
5524 "destination operands must be sequential");
5526 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5527 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5528 // For addressing modes with writeback, the base register needs to be
5529 // different from the destination registers.
5530 if (Rn == Rt || Rn == Rt2)
5531 return Error(Operands[3]->getStartLoc(),
5532 "base register needs to be different from destination "
5539 case ARM::t2LDRD_PRE:
5540 case ARM::t2LDRD_POST: {
5541 // Rt2 must be different from Rt.
5542 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5543 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5545 return Error(Operands[3]->getStartLoc(),
5546 "destination operands can't be identical");
5550 // Rt2 must be Rt + 1.
5551 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5552 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5554 return Error(Operands[3]->getStartLoc(),
5555 "source operands must be sequential");
5559 case ARM::STRD_POST: {
5560 // Rt2 must be Rt + 1.
5561 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5562 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5564 return Error(Operands[3]->getStartLoc(),
5565 "source operands must be sequential");
5570 // Width must be in range [1, 32-lsb].
5571 unsigned LSB = Inst.getOperand(2).getImm();
5572 unsigned Widthm1 = Inst.getOperand(3).getImm();
5573 if (Widthm1 >= 32 - LSB)
5574 return Error(Operands[5]->getStartLoc(),
5575 "bitfield width must be in range [1,32-lsb]");
5578 // Notionally handles ARM::tLDMIA_UPD too.
5580 // If we're parsing Thumb2, the .w variant is available and handles
5581 // most cases that are normally illegal for a Thumb1 LDM instruction.
5582 // We'll make the transformation in processInstruction() if necessary.
5584 // Thumb LDM instructions are writeback iff the base register is not
5585 // in the register list.
5586 unsigned Rn = Inst.getOperand(0).getReg();
5587 bool HasWritebackToken =
5588 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5589 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5590 bool ListContainsBase;
5591 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5592 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
5593 "registers must be in range r0-r7");
5594 // If we should have writeback, then there should be a '!' token.
5595 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
5596 return Error(Operands[2]->getStartLoc(),
5597 "writeback operator '!' expected");
5598 // If we should not have writeback, there must not be a '!'. This is
5599 // true even for the 32-bit wide encodings.
5600 if (ListContainsBase && HasWritebackToken)
5601 return Error(Operands[3]->getStartLoc(),
5602 "writeback operator '!' not allowed when base register "
5603 "in register list");
5607 case ARM::LDMIA_UPD:
5608 case ARM::LDMDB_UPD:
5609 case ARM::LDMIB_UPD:
5610 case ARM::LDMDA_UPD:
5611 // ARM variants loading and updating the same register are only officially
5612 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5616 case ARM::t2LDMIA_UPD:
5617 case ARM::t2LDMDB_UPD:
5618 case ARM::t2STMIA_UPD:
5619 case ARM::t2STMDB_UPD: {
5620 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5621 return Error(Operands.back()->getStartLoc(),
5622 "writeback register not allowed in register list");
5625 case ARM::sysLDMIA_UPD:
5626 case ARM::sysLDMDA_UPD:
5627 case ARM::sysLDMDB_UPD:
5628 case ARM::sysLDMIB_UPD:
5629 if (!listContainsReg(Inst, 3, ARM::PC))
5630 return Error(Operands[4]->getStartLoc(),
5631 "writeback register only allowed on system LDM "
5632 "if PC in register-list");
5634 case ARM::sysSTMIA_UPD:
5635 case ARM::sysSTMDA_UPD:
5636 case ARM::sysSTMDB_UPD:
5637 case ARM::sysSTMIB_UPD:
5638 return Error(Operands[2]->getStartLoc(),
5639 "system STM cannot have writeback register");
5642 // The second source operand must be the same register as the destination
5645 // In this case, we must directly check the parsed operands because the
5646 // cvtThumbMultiply() function is written in such a way that it guarantees
5647 // this first statement is always true for the new Inst. Essentially, the
5648 // destination is unconditionally copied into the second source operand
5649 // without checking to see if it matches what we actually parsed.
5650 if (Operands.size() == 6 &&
5651 (((ARMOperand*)Operands[3])->getReg() !=
5652 ((ARMOperand*)Operands[5])->getReg()) &&
5653 (((ARMOperand*)Operands[3])->getReg() !=
5654 ((ARMOperand*)Operands[4])->getReg())) {
5655 return Error(Operands[3]->getStartLoc(),
5656 "destination register must match source register");
5660 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5661 // so only issue a diagnostic for thumb1. The instructions will be
5662 // switched to the t2 encodings in processInstruction() if necessary.
5664 bool ListContainsBase;
5665 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
5667 return Error(Operands[2]->getStartLoc(),
5668 "registers must be in range r0-r7 or pc");
5672 bool ListContainsBase;
5673 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
5675 return Error(Operands[2]->getStartLoc(),
5676 "registers must be in range r0-r7 or lr");
5679 case ARM::tSTMIA_UPD: {
5680 bool ListContainsBase, InvalidLowList;
5681 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5682 0, ListContainsBase);
5683 if (InvalidLowList && !isThumbTwo())
5684 return Error(Operands[4]->getStartLoc(),
5685 "registers must be in range r0-r7");
5687 // This would be converted to a 32-bit stm, but that's not valid if the
5688 // writeback register is in the list.
5689 if (InvalidLowList && ListContainsBase)
5690 return Error(Operands[4]->getStartLoc(),
5691 "writeback operator '!' not allowed when base register "
5692 "in register list");
5695 case ARM::tADDrSP: {
5696 // If the non-SP source operand and the destination operand are not the
5697 // same, we need thumb2 (for the wide encoding), or we have an error.
5698 if (!isThumbTwo() &&
5699 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5700 return Error(Operands[4]->getStartLoc(),
5701 "source register must be the same as destination");
5705 // Final range checking for Thumb unconditional branch instructions.
5707 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5708 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5711 int op = (Operands[2]->isImm()) ? 2 : 3;
5712 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5713 return Error(Operands[op]->getStartLoc(), "branch target out of range");
5716 // Final range checking for Thumb conditional branch instructions.
5718 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5719 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5722 int Op = (Operands[2]->isImm()) ? 2 : 3;
5723 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5724 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
5732 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5734 default: llvm_unreachable("unexpected opcode!");
5736 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5737 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5738 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5739 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5740 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5741 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5742 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5743 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5744 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5747 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5748 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5749 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5750 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5751 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5753 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5754 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5755 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5756 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5757 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5759 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5760 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5761 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5762 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5763 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5766 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5767 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5768 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5769 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5770 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5771 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5772 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5773 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5774 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5775 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5776 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5777 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5778 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5779 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5780 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5783 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5784 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5785 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5786 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5787 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5788 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5789 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5790 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5791 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5792 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5793 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5794 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5795 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5796 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5797 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5798 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5799 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5800 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5803 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5804 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5805 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5806 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5807 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5808 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5809 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5810 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5811 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5812 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5813 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5814 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5815 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5816 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5817 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5820 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5821 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5822 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5823 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5824 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5825 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5826 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5827 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5828 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5829 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5830 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5831 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5832 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5833 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5834 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5835 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5836 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5837 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5841 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5843 default: llvm_unreachable("unexpected opcode!");
5845 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5846 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5847 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5848 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5849 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5850 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5851 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5852 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5853 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5856 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5857 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5858 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5859 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5860 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5861 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5862 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5863 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5864 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5865 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5866 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5867 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5868 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5869 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5870 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5873 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5874 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5875 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5876 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5877 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5878 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5879 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5880 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5881 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5882 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5883 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5884 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5885 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5886 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5887 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5888 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5889 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5890 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5893 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5894 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5895 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5896 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5897 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5898 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5899 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5900 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5901 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5902 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5903 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5904 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5905 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5906 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5907 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5910 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5911 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5912 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5913 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5914 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5915 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5916 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5917 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5918 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5919 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5920 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5921 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5922 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5923 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5924 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5925 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5926 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5927 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5930 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5931 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5932 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5933 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5934 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5935 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5936 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5937 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5938 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5939 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5940 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5941 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5942 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5943 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5944 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5947 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5948 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5949 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5950 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5951 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5952 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5953 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5954 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5955 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5956 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5957 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5958 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5959 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5960 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5961 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5962 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5963 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5964 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5967 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5968 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5969 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5970 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5971 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5972 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5973 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5974 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5975 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5976 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5977 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5978 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5979 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5980 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5981 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5982 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5983 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5984 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5989 processInstruction(MCInst &Inst,
5990 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5991 switch (Inst.getOpcode()) {
5992 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5994 if (Inst.getOperand(1).getReg() != ARM::PC ||
5995 Inst.getOperand(5).getReg() != 0)
5998 TmpInst.setOpcode(ARM::ADR);
5999 TmpInst.addOperand(Inst.getOperand(0));
6000 TmpInst.addOperand(Inst.getOperand(2));
6001 TmpInst.addOperand(Inst.getOperand(3));
6002 TmpInst.addOperand(Inst.getOperand(4));
6006 // Aliases for alternate PC+imm syntax of LDR instructions.
6007 case ARM::t2LDRpcrel:
6008 // Select the narrow version if the immediate will fit.
6009 if (Inst.getOperand(1).getImm() > 0 &&
6010 Inst.getOperand(1).getImm() <= 0xff &&
6011 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
6012 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
6013 Inst.setOpcode(ARM::tLDRpci);
6015 Inst.setOpcode(ARM::t2LDRpci);
6017 case ARM::t2LDRBpcrel:
6018 Inst.setOpcode(ARM::t2LDRBpci);
6020 case ARM::t2LDRHpcrel:
6021 Inst.setOpcode(ARM::t2LDRHpci);
6023 case ARM::t2LDRSBpcrel:
6024 Inst.setOpcode(ARM::t2LDRSBpci);
6026 case ARM::t2LDRSHpcrel:
6027 Inst.setOpcode(ARM::t2LDRSHpci);
6029 // Handle NEON VST complex aliases.
6030 case ARM::VST1LNdWB_register_Asm_8:
6031 case ARM::VST1LNdWB_register_Asm_16:
6032 case ARM::VST1LNdWB_register_Asm_32: {
6034 // Shuffle the operands around so the lane index operand is in the
6037 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6038 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6039 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6040 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6041 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6042 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6043 TmpInst.addOperand(Inst.getOperand(1)); // lane
6044 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6045 TmpInst.addOperand(Inst.getOperand(6));
6050 case ARM::VST2LNdWB_register_Asm_8:
6051 case ARM::VST2LNdWB_register_Asm_16:
6052 case ARM::VST2LNdWB_register_Asm_32:
6053 case ARM::VST2LNqWB_register_Asm_16:
6054 case ARM::VST2LNqWB_register_Asm_32: {
6056 // Shuffle the operands around so the lane index operand is in the
6059 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6060 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6061 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6062 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6063 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6064 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6065 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6067 TmpInst.addOperand(Inst.getOperand(1)); // lane
6068 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6069 TmpInst.addOperand(Inst.getOperand(6));
6074 case ARM::VST3LNdWB_register_Asm_8:
6075 case ARM::VST3LNdWB_register_Asm_16:
6076 case ARM::VST3LNdWB_register_Asm_32:
6077 case ARM::VST3LNqWB_register_Asm_16:
6078 case ARM::VST3LNqWB_register_Asm_32: {
6080 // Shuffle the operands around so the lane index operand is in the
6083 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6084 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6085 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6086 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6087 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6088 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6089 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6091 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6093 TmpInst.addOperand(Inst.getOperand(1)); // lane
6094 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6095 TmpInst.addOperand(Inst.getOperand(6));
6100 case ARM::VST4LNdWB_register_Asm_8:
6101 case ARM::VST4LNdWB_register_Asm_16:
6102 case ARM::VST4LNdWB_register_Asm_32:
6103 case ARM::VST4LNqWB_register_Asm_16:
6104 case ARM::VST4LNqWB_register_Asm_32: {
6106 // Shuffle the operands around so the lane index operand is in the
6109 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6110 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6111 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6112 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6113 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6114 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6115 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6117 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6119 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6121 TmpInst.addOperand(Inst.getOperand(1)); // lane
6122 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6123 TmpInst.addOperand(Inst.getOperand(6));
6128 case ARM::VST1LNdWB_fixed_Asm_8:
6129 case ARM::VST1LNdWB_fixed_Asm_16:
6130 case ARM::VST1LNdWB_fixed_Asm_32: {
6132 // Shuffle the operands around so the lane index operand is in the
6135 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6136 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6137 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6138 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6139 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6140 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6141 TmpInst.addOperand(Inst.getOperand(1)); // lane
6142 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6143 TmpInst.addOperand(Inst.getOperand(5));
6148 case ARM::VST2LNdWB_fixed_Asm_8:
6149 case ARM::VST2LNdWB_fixed_Asm_16:
6150 case ARM::VST2LNdWB_fixed_Asm_32:
6151 case ARM::VST2LNqWB_fixed_Asm_16:
6152 case ARM::VST2LNqWB_fixed_Asm_32: {
6154 // Shuffle the operands around so the lane index operand is in the
6157 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6158 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6159 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6160 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6161 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6162 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6163 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6165 TmpInst.addOperand(Inst.getOperand(1)); // lane
6166 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6167 TmpInst.addOperand(Inst.getOperand(5));
6172 case ARM::VST3LNdWB_fixed_Asm_8:
6173 case ARM::VST3LNdWB_fixed_Asm_16:
6174 case ARM::VST3LNdWB_fixed_Asm_32:
6175 case ARM::VST3LNqWB_fixed_Asm_16:
6176 case ARM::VST3LNqWB_fixed_Asm_32: {
6178 // Shuffle the operands around so the lane index operand is in the
6181 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6182 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6183 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6184 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6185 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6186 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6187 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6191 TmpInst.addOperand(Inst.getOperand(1)); // lane
6192 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6193 TmpInst.addOperand(Inst.getOperand(5));
6198 case ARM::VST4LNdWB_fixed_Asm_8:
6199 case ARM::VST4LNdWB_fixed_Asm_16:
6200 case ARM::VST4LNdWB_fixed_Asm_32:
6201 case ARM::VST4LNqWB_fixed_Asm_16:
6202 case ARM::VST4LNqWB_fixed_Asm_32: {
6204 // Shuffle the operands around so the lane index operand is in the
6207 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6208 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6209 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6210 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6211 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6212 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6213 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6215 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6217 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6219 TmpInst.addOperand(Inst.getOperand(1)); // lane
6220 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6221 TmpInst.addOperand(Inst.getOperand(5));
6226 case ARM::VST1LNdAsm_8:
6227 case ARM::VST1LNdAsm_16:
6228 case ARM::VST1LNdAsm_32: {
6230 // Shuffle the operands around so the lane index operand is in the
6233 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6234 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6235 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6236 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6237 TmpInst.addOperand(Inst.getOperand(1)); // lane
6238 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6239 TmpInst.addOperand(Inst.getOperand(5));
6244 case ARM::VST2LNdAsm_8:
6245 case ARM::VST2LNdAsm_16:
6246 case ARM::VST2LNdAsm_32:
6247 case ARM::VST2LNqAsm_16:
6248 case ARM::VST2LNqAsm_32: {
6250 // Shuffle the operands around so the lane index operand is in the
6253 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6254 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6255 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6256 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6257 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6259 TmpInst.addOperand(Inst.getOperand(1)); // lane
6260 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6261 TmpInst.addOperand(Inst.getOperand(5));
6266 case ARM::VST3LNdAsm_8:
6267 case ARM::VST3LNdAsm_16:
6268 case ARM::VST3LNdAsm_32:
6269 case ARM::VST3LNqAsm_16:
6270 case ARM::VST3LNqAsm_32: {
6272 // Shuffle the operands around so the lane index operand is in the
6275 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6276 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6277 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6278 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6279 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6281 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6283 TmpInst.addOperand(Inst.getOperand(1)); // lane
6284 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6285 TmpInst.addOperand(Inst.getOperand(5));
6290 case ARM::VST4LNdAsm_8:
6291 case ARM::VST4LNdAsm_16:
6292 case ARM::VST4LNdAsm_32:
6293 case ARM::VST4LNqAsm_16:
6294 case ARM::VST4LNqAsm_32: {
6296 // Shuffle the operands around so the lane index operand is in the
6299 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6300 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6301 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6302 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6303 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6305 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6307 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6309 TmpInst.addOperand(Inst.getOperand(1)); // lane
6310 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6311 TmpInst.addOperand(Inst.getOperand(5));
6316 // Handle NEON VLD complex aliases.
6317 case ARM::VLD1LNdWB_register_Asm_8:
6318 case ARM::VLD1LNdWB_register_Asm_16:
6319 case ARM::VLD1LNdWB_register_Asm_32: {
6321 // Shuffle the operands around so the lane index operand is in the
6324 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6325 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6326 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6327 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6328 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6329 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6330 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6331 TmpInst.addOperand(Inst.getOperand(1)); // lane
6332 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6333 TmpInst.addOperand(Inst.getOperand(6));
6338 case ARM::VLD2LNdWB_register_Asm_8:
6339 case ARM::VLD2LNdWB_register_Asm_16:
6340 case ARM::VLD2LNdWB_register_Asm_32:
6341 case ARM::VLD2LNqWB_register_Asm_16:
6342 case ARM::VLD2LNqWB_register_Asm_32: {
6344 // Shuffle the operands around so the lane index operand is in the
6347 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6348 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6349 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6351 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6352 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6353 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6354 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6355 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6356 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6358 TmpInst.addOperand(Inst.getOperand(1)); // lane
6359 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6360 TmpInst.addOperand(Inst.getOperand(6));
6365 case ARM::VLD3LNdWB_register_Asm_8:
6366 case ARM::VLD3LNdWB_register_Asm_16:
6367 case ARM::VLD3LNdWB_register_Asm_32:
6368 case ARM::VLD3LNqWB_register_Asm_16:
6369 case ARM::VLD3LNqWB_register_Asm_32: {
6371 // Shuffle the operands around so the lane index operand is in the
6374 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6375 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6376 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6378 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6380 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6381 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6382 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6383 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6384 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6385 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6387 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6389 TmpInst.addOperand(Inst.getOperand(1)); // lane
6390 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6391 TmpInst.addOperand(Inst.getOperand(6));
6396 case ARM::VLD4LNdWB_register_Asm_8:
6397 case ARM::VLD4LNdWB_register_Asm_16:
6398 case ARM::VLD4LNdWB_register_Asm_32:
6399 case ARM::VLD4LNqWB_register_Asm_16:
6400 case ARM::VLD4LNqWB_register_Asm_32: {
6402 // Shuffle the operands around so the lane index operand is in the
6405 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6406 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6407 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6409 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6411 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6413 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6414 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6415 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6416 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6417 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6418 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6420 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6422 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6424 TmpInst.addOperand(Inst.getOperand(1)); // lane
6425 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6426 TmpInst.addOperand(Inst.getOperand(6));
6431 case ARM::VLD1LNdWB_fixed_Asm_8:
6432 case ARM::VLD1LNdWB_fixed_Asm_16:
6433 case ARM::VLD1LNdWB_fixed_Asm_32: {
6435 // Shuffle the operands around so the lane index operand is in the
6438 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6439 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6440 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6441 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6442 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6443 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6444 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6445 TmpInst.addOperand(Inst.getOperand(1)); // lane
6446 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6447 TmpInst.addOperand(Inst.getOperand(5));
6452 case ARM::VLD2LNdWB_fixed_Asm_8:
6453 case ARM::VLD2LNdWB_fixed_Asm_16:
6454 case ARM::VLD2LNdWB_fixed_Asm_32:
6455 case ARM::VLD2LNqWB_fixed_Asm_16:
6456 case ARM::VLD2LNqWB_fixed_Asm_32: {
6458 // Shuffle the operands around so the lane index operand is in the
6461 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6462 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6463 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6465 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6466 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6467 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6468 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6469 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6470 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6472 TmpInst.addOperand(Inst.getOperand(1)); // lane
6473 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6474 TmpInst.addOperand(Inst.getOperand(5));
6479 case ARM::VLD3LNdWB_fixed_Asm_8:
6480 case ARM::VLD3LNdWB_fixed_Asm_16:
6481 case ARM::VLD3LNdWB_fixed_Asm_32:
6482 case ARM::VLD3LNqWB_fixed_Asm_16:
6483 case ARM::VLD3LNqWB_fixed_Asm_32: {
6485 // Shuffle the operands around so the lane index operand is in the
6488 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6489 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6490 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6492 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6494 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6495 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6496 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6497 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6498 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6501 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6503 TmpInst.addOperand(Inst.getOperand(1)); // lane
6504 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6505 TmpInst.addOperand(Inst.getOperand(5));
6510 case ARM::VLD4LNdWB_fixed_Asm_8:
6511 case ARM::VLD4LNdWB_fixed_Asm_16:
6512 case ARM::VLD4LNdWB_fixed_Asm_32:
6513 case ARM::VLD4LNqWB_fixed_Asm_16:
6514 case ARM::VLD4LNqWB_fixed_Asm_32: {
6516 // Shuffle the operands around so the lane index operand is in the
6519 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6520 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6521 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6523 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6525 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6527 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6528 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6529 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6530 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6531 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6532 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6534 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6536 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 TmpInst.addOperand(Inst.getOperand(1)); // lane
6539 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6540 TmpInst.addOperand(Inst.getOperand(5));
6545 case ARM::VLD1LNdAsm_8:
6546 case ARM::VLD1LNdAsm_16:
6547 case ARM::VLD1LNdAsm_32: {
6549 // Shuffle the operands around so the lane index operand is in the
6552 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6553 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6554 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6555 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6556 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6557 TmpInst.addOperand(Inst.getOperand(1)); // lane
6558 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6559 TmpInst.addOperand(Inst.getOperand(5));
6564 case ARM::VLD2LNdAsm_8:
6565 case ARM::VLD2LNdAsm_16:
6566 case ARM::VLD2LNdAsm_32:
6567 case ARM::VLD2LNqAsm_16:
6568 case ARM::VLD2LNqAsm_32: {
6570 // Shuffle the operands around so the lane index operand is in the
6573 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6574 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6575 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6577 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6578 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6579 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6582 TmpInst.addOperand(Inst.getOperand(1)); // lane
6583 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6584 TmpInst.addOperand(Inst.getOperand(5));
6589 case ARM::VLD3LNdAsm_8:
6590 case ARM::VLD3LNdAsm_16:
6591 case ARM::VLD3LNdAsm_32:
6592 case ARM::VLD3LNqAsm_16:
6593 case ARM::VLD3LNqAsm_32: {
6595 // Shuffle the operands around so the lane index operand is in the
6598 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6599 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6600 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6602 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6604 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6605 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6606 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6607 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6609 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6611 TmpInst.addOperand(Inst.getOperand(1)); // lane
6612 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6613 TmpInst.addOperand(Inst.getOperand(5));
6618 case ARM::VLD4LNdAsm_8:
6619 case ARM::VLD4LNdAsm_16:
6620 case ARM::VLD4LNdAsm_32:
6621 case ARM::VLD4LNqAsm_16:
6622 case ARM::VLD4LNqAsm_32: {
6624 // Shuffle the operands around so the lane index operand is in the
6627 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6628 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6629 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6631 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6633 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6635 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6636 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6637 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6638 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6640 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6642 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6644 TmpInst.addOperand(Inst.getOperand(1)); // lane
6645 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6646 TmpInst.addOperand(Inst.getOperand(5));
6651 // VLD3DUP single 3-element structure to all lanes instructions.
6652 case ARM::VLD3DUPdAsm_8:
6653 case ARM::VLD3DUPdAsm_16:
6654 case ARM::VLD3DUPdAsm_32:
6655 case ARM::VLD3DUPqAsm_8:
6656 case ARM::VLD3DUPqAsm_16:
6657 case ARM::VLD3DUPqAsm_32: {
6660 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
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(Inst.getOperand(1)); // Rn
6667 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6668 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6669 TmpInst.addOperand(Inst.getOperand(4));
6674 case ARM::VLD3DUPdWB_fixed_Asm_8:
6675 case ARM::VLD3DUPdWB_fixed_Asm_16:
6676 case ARM::VLD3DUPdWB_fixed_Asm_32:
6677 case ARM::VLD3DUPqWB_fixed_Asm_8:
6678 case ARM::VLD3DUPqWB_fixed_Asm_16:
6679 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6682 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6683 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6684 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6686 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6688 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6689 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6690 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6691 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6692 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6693 TmpInst.addOperand(Inst.getOperand(4));
6698 case ARM::VLD3DUPdWB_register_Asm_8:
6699 case ARM::VLD3DUPdWB_register_Asm_16:
6700 case ARM::VLD3DUPdWB_register_Asm_32:
6701 case ARM::VLD3DUPqWB_register_Asm_8:
6702 case ARM::VLD3DUPqWB_register_Asm_16:
6703 case ARM::VLD3DUPqWB_register_Asm_32: {
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(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6712 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6713 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6714 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6715 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6716 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6717 TmpInst.addOperand(Inst.getOperand(5));
6722 // VLD3 multiple 3-element structure instructions.
6723 case ARM::VLD3dAsm_8:
6724 case ARM::VLD3dAsm_16:
6725 case ARM::VLD3dAsm_32:
6726 case ARM::VLD3qAsm_8:
6727 case ARM::VLD3qAsm_16:
6728 case ARM::VLD3qAsm_32: {
6731 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6732 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6733 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6735 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6737 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6738 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6739 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6740 TmpInst.addOperand(Inst.getOperand(4));
6745 case ARM::VLD3dWB_fixed_Asm_8:
6746 case ARM::VLD3dWB_fixed_Asm_16:
6747 case ARM::VLD3dWB_fixed_Asm_32:
6748 case ARM::VLD3qWB_fixed_Asm_8:
6749 case ARM::VLD3qWB_fixed_Asm_16:
6750 case ARM::VLD3qWB_fixed_Asm_32: {
6753 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6754 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6755 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6759 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6760 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6761 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6762 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6763 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6764 TmpInst.addOperand(Inst.getOperand(4));
6769 case ARM::VLD3dWB_register_Asm_8:
6770 case ARM::VLD3dWB_register_Asm_16:
6771 case ARM::VLD3dWB_register_Asm_32:
6772 case ARM::VLD3qWB_register_Asm_8:
6773 case ARM::VLD3qWB_register_Asm_16:
6774 case ARM::VLD3qWB_register_Asm_32: {
6777 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6778 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6783 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6784 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6785 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6786 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6787 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6788 TmpInst.addOperand(Inst.getOperand(5));
6793 // VLD4DUP single 3-element structure to all lanes instructions.
6794 case ARM::VLD4DUPdAsm_8:
6795 case ARM::VLD4DUPdAsm_16:
6796 case ARM::VLD4DUPdAsm_32:
6797 case ARM::VLD4DUPqAsm_8:
6798 case ARM::VLD4DUPqAsm_16:
6799 case ARM::VLD4DUPqAsm_32: {
6802 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6803 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6804 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6806 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6808 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6810 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6811 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6812 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6813 TmpInst.addOperand(Inst.getOperand(4));
6818 case ARM::VLD4DUPdWB_fixed_Asm_8:
6819 case ARM::VLD4DUPdWB_fixed_Asm_16:
6820 case ARM::VLD4DUPdWB_fixed_Asm_32:
6821 case ARM::VLD4DUPqWB_fixed_Asm_8:
6822 case ARM::VLD4DUPqWB_fixed_Asm_16:
6823 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6826 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6827 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6828 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6830 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6832 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6834 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6835 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6836 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6837 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6838 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6839 TmpInst.addOperand(Inst.getOperand(4));
6844 case ARM::VLD4DUPdWB_register_Asm_8:
6845 case ARM::VLD4DUPdWB_register_Asm_16:
6846 case ARM::VLD4DUPdWB_register_Asm_32:
6847 case ARM::VLD4DUPqWB_register_Asm_8:
6848 case ARM::VLD4DUPqWB_register_Asm_16:
6849 case ARM::VLD4DUPqWB_register_Asm_32: {
6852 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6853 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6854 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6856 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6858 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6860 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6861 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6862 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6863 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6864 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6865 TmpInst.addOperand(Inst.getOperand(5));
6870 // VLD4 multiple 4-element structure instructions.
6871 case ARM::VLD4dAsm_8:
6872 case ARM::VLD4dAsm_16:
6873 case ARM::VLD4dAsm_32:
6874 case ARM::VLD4qAsm_8:
6875 case ARM::VLD4qAsm_16:
6876 case ARM::VLD4qAsm_32: {
6879 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6880 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6881 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6883 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6885 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6887 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6888 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6889 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6890 TmpInst.addOperand(Inst.getOperand(4));
6895 case ARM::VLD4dWB_fixed_Asm_8:
6896 case ARM::VLD4dWB_fixed_Asm_16:
6897 case ARM::VLD4dWB_fixed_Asm_32:
6898 case ARM::VLD4qWB_fixed_Asm_8:
6899 case ARM::VLD4qWB_fixed_Asm_16:
6900 case ARM::VLD4qWB_fixed_Asm_32: {
6903 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6904 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6905 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6907 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6909 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6911 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6912 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6913 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6914 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6915 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6916 TmpInst.addOperand(Inst.getOperand(4));
6921 case ARM::VLD4dWB_register_Asm_8:
6922 case ARM::VLD4dWB_register_Asm_16:
6923 case ARM::VLD4dWB_register_Asm_32:
6924 case ARM::VLD4qWB_register_Asm_8:
6925 case ARM::VLD4qWB_register_Asm_16:
6926 case ARM::VLD4qWB_register_Asm_32: {
6929 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6930 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6931 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6933 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6935 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6937 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6938 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6939 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6940 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6941 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6942 TmpInst.addOperand(Inst.getOperand(5));
6947 // VST3 multiple 3-element structure instructions.
6948 case ARM::VST3dAsm_8:
6949 case ARM::VST3dAsm_16:
6950 case ARM::VST3dAsm_32:
6951 case ARM::VST3qAsm_8:
6952 case ARM::VST3qAsm_16:
6953 case ARM::VST3qAsm_32: {
6956 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6957 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6958 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6959 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6960 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6962 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6964 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6965 TmpInst.addOperand(Inst.getOperand(4));
6970 case ARM::VST3dWB_fixed_Asm_8:
6971 case ARM::VST3dWB_fixed_Asm_16:
6972 case ARM::VST3dWB_fixed_Asm_32:
6973 case ARM::VST3qWB_fixed_Asm_8:
6974 case ARM::VST3qWB_fixed_Asm_16:
6975 case ARM::VST3qWB_fixed_Asm_32: {
6978 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6979 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6980 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6981 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6982 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6983 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6984 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6986 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6988 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6989 TmpInst.addOperand(Inst.getOperand(4));
6994 case ARM::VST3dWB_register_Asm_8:
6995 case ARM::VST3dWB_register_Asm_16:
6996 case ARM::VST3dWB_register_Asm_32:
6997 case ARM::VST3qWB_register_Asm_8:
6998 case ARM::VST3qWB_register_Asm_16:
6999 case ARM::VST3qWB_register_Asm_32: {
7002 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7003 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7004 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7005 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7006 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7007 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7008 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7010 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7012 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7013 TmpInst.addOperand(Inst.getOperand(5));
7018 // VST4 multiple 3-element structure instructions.
7019 case ARM::VST4dAsm_8:
7020 case ARM::VST4dAsm_16:
7021 case ARM::VST4dAsm_32:
7022 case ARM::VST4qAsm_8:
7023 case ARM::VST4qAsm_16:
7024 case ARM::VST4qAsm_32: {
7027 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7028 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7029 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7030 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7031 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7033 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7035 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7037 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7038 TmpInst.addOperand(Inst.getOperand(4));
7043 case ARM::VST4dWB_fixed_Asm_8:
7044 case ARM::VST4dWB_fixed_Asm_16:
7045 case ARM::VST4dWB_fixed_Asm_32:
7046 case ARM::VST4qWB_fixed_Asm_8:
7047 case ARM::VST4qWB_fixed_Asm_16:
7048 case ARM::VST4qWB_fixed_Asm_32: {
7051 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7052 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7053 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7054 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7055 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7056 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7057 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7059 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7061 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7063 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7064 TmpInst.addOperand(Inst.getOperand(4));
7069 case ARM::VST4dWB_register_Asm_8:
7070 case ARM::VST4dWB_register_Asm_16:
7071 case ARM::VST4dWB_register_Asm_32:
7072 case ARM::VST4qWB_register_Asm_8:
7073 case ARM::VST4qWB_register_Asm_16:
7074 case ARM::VST4qWB_register_Asm_32: {
7077 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7078 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7079 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7080 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7081 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7082 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7083 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7085 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7087 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7089 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7090 TmpInst.addOperand(Inst.getOperand(5));
7095 // Handle encoding choice for the shift-immediate instructions.
7098 case ARM::t2ASRri: {
7099 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7100 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7101 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7102 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7103 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7105 switch (Inst.getOpcode()) {
7106 default: llvm_unreachable("unexpected opcode");
7107 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7108 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7109 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7111 // The Thumb1 operands aren't in the same order. Awesome, eh?
7113 TmpInst.setOpcode(NewOpc);
7114 TmpInst.addOperand(Inst.getOperand(0));
7115 TmpInst.addOperand(Inst.getOperand(5));
7116 TmpInst.addOperand(Inst.getOperand(1));
7117 TmpInst.addOperand(Inst.getOperand(2));
7118 TmpInst.addOperand(Inst.getOperand(3));
7119 TmpInst.addOperand(Inst.getOperand(4));
7126 // Handle the Thumb2 mode MOV complex aliases.
7128 case ARM::t2MOVSsr: {
7129 // Which instruction to expand to depends on the CCOut operand and
7130 // whether we're in an IT block if the register operands are low
7132 bool isNarrow = false;
7133 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7134 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7135 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7136 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7137 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7141 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7142 default: llvm_unreachable("unexpected opcode!");
7143 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7144 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7145 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7146 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7148 TmpInst.setOpcode(newOpc);
7149 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7151 TmpInst.addOperand(MCOperand::CreateReg(
7152 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7153 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7154 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7155 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7156 TmpInst.addOperand(Inst.getOperand(5));
7158 TmpInst.addOperand(MCOperand::CreateReg(
7159 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7164 case ARM::t2MOVSsi: {
7165 // Which instruction to expand to depends on the CCOut operand and
7166 // whether we're in an IT block if the register operands are low
7168 bool isNarrow = false;
7169 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7170 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7171 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7175 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7176 default: llvm_unreachable("unexpected opcode!");
7177 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7178 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7179 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7180 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7181 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7183 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7184 if (Amount == 32) Amount = 0;
7185 TmpInst.setOpcode(newOpc);
7186 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7188 TmpInst.addOperand(MCOperand::CreateReg(
7189 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7190 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7191 if (newOpc != ARM::t2RRX)
7192 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7193 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7194 TmpInst.addOperand(Inst.getOperand(4));
7196 TmpInst.addOperand(MCOperand::CreateReg(
7197 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7201 // Handle the ARM mode MOV complex aliases.
7206 ARM_AM::ShiftOpc ShiftTy;
7207 switch(Inst.getOpcode()) {
7208 default: llvm_unreachable("unexpected opcode!");
7209 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7210 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7211 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7212 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7214 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7216 TmpInst.setOpcode(ARM::MOVsr);
7217 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7218 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7219 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7220 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7221 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7222 TmpInst.addOperand(Inst.getOperand(4));
7223 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7231 ARM_AM::ShiftOpc ShiftTy;
7232 switch(Inst.getOpcode()) {
7233 default: llvm_unreachable("unexpected opcode!");
7234 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7235 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7236 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7237 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7239 // A shift by zero is a plain MOVr, not a MOVsi.
7240 unsigned Amt = Inst.getOperand(2).getImm();
7241 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7242 // A shift by 32 should be encoded as 0 when permitted
7243 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7245 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7247 TmpInst.setOpcode(Opc);
7248 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7249 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7250 if (Opc == ARM::MOVsi)
7251 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7252 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7253 TmpInst.addOperand(Inst.getOperand(4));
7254 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7259 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7261 TmpInst.setOpcode(ARM::MOVsi);
7262 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7263 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7264 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7265 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7266 TmpInst.addOperand(Inst.getOperand(3));
7267 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7271 case ARM::t2LDMIA_UPD: {
7272 // If this is a load of a single register, then we should use
7273 // a post-indexed LDR instruction instead, per the ARM ARM.
7274 if (Inst.getNumOperands() != 5)
7277 TmpInst.setOpcode(ARM::t2LDR_POST);
7278 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7279 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7280 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7281 TmpInst.addOperand(MCOperand::CreateImm(4));
7282 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7283 TmpInst.addOperand(Inst.getOperand(3));
7287 case ARM::t2STMDB_UPD: {
7288 // If this is a store of a single register, then we should use
7289 // a pre-indexed STR instruction instead, per the ARM ARM.
7290 if (Inst.getNumOperands() != 5)
7293 TmpInst.setOpcode(ARM::t2STR_PRE);
7294 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7295 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7296 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7297 TmpInst.addOperand(MCOperand::CreateImm(-4));
7298 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7299 TmpInst.addOperand(Inst.getOperand(3));
7303 case ARM::LDMIA_UPD:
7304 // If this is a load of a single register via a 'pop', then we should use
7305 // a post-indexed LDR instruction instead, per the ARM ARM.
7306 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7307 Inst.getNumOperands() == 5) {
7309 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7310 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7311 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7312 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7313 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7314 TmpInst.addOperand(MCOperand::CreateImm(4));
7315 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7316 TmpInst.addOperand(Inst.getOperand(3));
7321 case ARM::STMDB_UPD:
7322 // If this is a store of a single register via a 'push', then we should use
7323 // a pre-indexed STR instruction instead, per the ARM ARM.
7324 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7325 Inst.getNumOperands() == 5) {
7327 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7328 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7329 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7330 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7331 TmpInst.addOperand(MCOperand::CreateImm(-4));
7332 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7333 TmpInst.addOperand(Inst.getOperand(3));
7337 case ARM::t2ADDri12:
7338 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7339 // mnemonic was used (not "addw"), encoding T3 is preferred.
7340 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7341 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7343 Inst.setOpcode(ARM::t2ADDri);
7344 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7346 case ARM::t2SUBri12:
7347 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7348 // mnemonic was used (not "subw"), encoding T3 is preferred.
7349 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7350 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7352 Inst.setOpcode(ARM::t2SUBri);
7353 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7356 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7357 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7358 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7359 // to encoding T1 if <Rd> is omitted."
7360 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7361 Inst.setOpcode(ARM::tADDi3);
7366 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7367 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7368 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7369 // to encoding T1 if <Rd> is omitted."
7370 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7371 Inst.setOpcode(ARM::tSUBi3);
7376 case ARM::t2SUBri: {
7377 // If the destination and first source operand are the same, and
7378 // the flags are compatible with the current IT status, use encoding T2
7379 // instead of T3. For compatibility with the system 'as'. Make sure the
7380 // wide encoding wasn't explicit.
7381 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7382 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7383 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7384 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7385 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7386 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7387 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7390 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7391 ARM::tADDi8 : ARM::tSUBi8);
7392 TmpInst.addOperand(Inst.getOperand(0));
7393 TmpInst.addOperand(Inst.getOperand(5));
7394 TmpInst.addOperand(Inst.getOperand(0));
7395 TmpInst.addOperand(Inst.getOperand(2));
7396 TmpInst.addOperand(Inst.getOperand(3));
7397 TmpInst.addOperand(Inst.getOperand(4));
7401 case ARM::t2ADDrr: {
7402 // If the destination and first source operand are the same, and
7403 // there's no setting of the flags, use encoding T2 instead of T3.
7404 // Note that this is only for ADD, not SUB. This mirrors the system
7405 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7406 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7407 Inst.getOperand(5).getReg() != 0 ||
7408 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7409 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7412 TmpInst.setOpcode(ARM::tADDhirr);
7413 TmpInst.addOperand(Inst.getOperand(0));
7414 TmpInst.addOperand(Inst.getOperand(0));
7415 TmpInst.addOperand(Inst.getOperand(2));
7416 TmpInst.addOperand(Inst.getOperand(3));
7417 TmpInst.addOperand(Inst.getOperand(4));
7421 case ARM::tADDrSP: {
7422 // If the non-SP source operand and the destination operand are not the
7423 // same, we need to use the 32-bit encoding if it's available.
7424 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7425 Inst.setOpcode(ARM::t2ADDrr);
7426 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7432 // A Thumb conditional branch outside of an IT block is a tBcc.
7433 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7434 Inst.setOpcode(ARM::tBcc);
7439 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7440 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7441 Inst.setOpcode(ARM::t2Bcc);
7446 // If the conditional is AL or we're in an IT block, we really want t2B.
7447 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7448 Inst.setOpcode(ARM::t2B);
7453 // If the conditional is AL, we really want tB.
7454 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7455 Inst.setOpcode(ARM::tB);
7460 // If the register list contains any high registers, or if the writeback
7461 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7462 // instead if we're in Thumb2. Otherwise, this should have generated
7463 // an error in validateInstruction().
7464 unsigned Rn = Inst.getOperand(0).getReg();
7465 bool hasWritebackToken =
7466 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7467 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7468 bool listContainsBase;
7469 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7470 (!listContainsBase && !hasWritebackToken) ||
7471 (listContainsBase && hasWritebackToken)) {
7472 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7473 assert (isThumbTwo());
7474 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7475 // If we're switching to the updating version, we need to insert
7476 // the writeback tied operand.
7477 if (hasWritebackToken)
7478 Inst.insert(Inst.begin(),
7479 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7484 case ARM::tSTMIA_UPD: {
7485 // If the register list contains any high registers, we need to use
7486 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7487 // should have generated an error in validateInstruction().
7488 unsigned Rn = Inst.getOperand(0).getReg();
7489 bool listContainsBase;
7490 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7491 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7492 assert (isThumbTwo());
7493 Inst.setOpcode(ARM::t2STMIA_UPD);
7499 bool listContainsBase;
7500 // If the register list contains any high registers, we need to use
7501 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7502 // should have generated an error in validateInstruction().
7503 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7505 assert (isThumbTwo());
7506 Inst.setOpcode(ARM::t2LDMIA_UPD);
7507 // Add the base register and writeback operands.
7508 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7509 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7513 bool listContainsBase;
7514 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7516 assert (isThumbTwo());
7517 Inst.setOpcode(ARM::t2STMDB_UPD);
7518 // Add the base register and writeback operands.
7519 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7520 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7524 // If we can use the 16-bit encoding and the user didn't explicitly
7525 // request the 32-bit variant, transform it here.
7526 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7527 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7528 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7529 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7530 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7531 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7532 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7533 // The operands aren't in the same order for tMOVi8...
7535 TmpInst.setOpcode(ARM::tMOVi8);
7536 TmpInst.addOperand(Inst.getOperand(0));
7537 TmpInst.addOperand(Inst.getOperand(4));
7538 TmpInst.addOperand(Inst.getOperand(1));
7539 TmpInst.addOperand(Inst.getOperand(2));
7540 TmpInst.addOperand(Inst.getOperand(3));
7547 // If we can use the 16-bit encoding and the user didn't explicitly
7548 // request the 32-bit variant, transform it here.
7549 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7550 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7551 Inst.getOperand(2).getImm() == ARMCC::AL &&
7552 Inst.getOperand(4).getReg() == ARM::CPSR &&
7553 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7554 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7555 // The operands aren't the same for tMOV[S]r... (no cc_out)
7557 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7558 TmpInst.addOperand(Inst.getOperand(0));
7559 TmpInst.addOperand(Inst.getOperand(1));
7560 TmpInst.addOperand(Inst.getOperand(2));
7561 TmpInst.addOperand(Inst.getOperand(3));
7571 // If we can use the 16-bit encoding and the user didn't explicitly
7572 // request the 32-bit variant, transform it here.
7573 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7574 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7575 Inst.getOperand(2).getImm() == 0 &&
7576 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7577 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7579 switch (Inst.getOpcode()) {
7580 default: llvm_unreachable("Illegal opcode!");
7581 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7582 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7583 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7584 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7586 // The operands aren't the same for thumb1 (no rotate operand).
7588 TmpInst.setOpcode(NewOpc);
7589 TmpInst.addOperand(Inst.getOperand(0));
7590 TmpInst.addOperand(Inst.getOperand(1));
7591 TmpInst.addOperand(Inst.getOperand(3));
7592 TmpInst.addOperand(Inst.getOperand(4));
7599 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7600 // rrx shifts and asr/lsr of #32 is encoded as 0
7601 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7603 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7604 // Shifting by zero is accepted as a vanilla 'MOVr'
7606 TmpInst.setOpcode(ARM::MOVr);
7607 TmpInst.addOperand(Inst.getOperand(0));
7608 TmpInst.addOperand(Inst.getOperand(1));
7609 TmpInst.addOperand(Inst.getOperand(3));
7610 TmpInst.addOperand(Inst.getOperand(4));
7611 TmpInst.addOperand(Inst.getOperand(5));
7624 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7625 if (SOpc == ARM_AM::rrx) return false;
7626 switch (Inst.getOpcode()) {
7627 default: llvm_unreachable("unexpected opcode!");
7628 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7629 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7630 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7631 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7632 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7633 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7635 // If the shift is by zero, use the non-shifted instruction definition.
7636 // The exception is for right shifts, where 0 == 32
7637 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7638 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7640 TmpInst.setOpcode(newOpc);
7641 TmpInst.addOperand(Inst.getOperand(0));
7642 TmpInst.addOperand(Inst.getOperand(1));
7643 TmpInst.addOperand(Inst.getOperand(2));
7644 TmpInst.addOperand(Inst.getOperand(4));
7645 TmpInst.addOperand(Inst.getOperand(5));
7646 TmpInst.addOperand(Inst.getOperand(6));
7654 // The mask bits for all but the first condition are represented as
7655 // the low bit of the condition code value implies 't'. We currently
7656 // always have 1 implies 't', so XOR toggle the bits if the low bit
7657 // of the condition code is zero.
7658 MCOperand &MO = Inst.getOperand(1);
7659 unsigned Mask = MO.getImm();
7660 unsigned OrigMask = Mask;
7661 unsigned TZ = countTrailingZeros(Mask);
7662 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7663 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7664 Mask ^= (0xE << TZ) & 0xF;
7668 // Set up the IT block state according to the IT instruction we just
7670 assert(!inITBlock() && "nested IT blocks?!");
7671 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7672 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7673 ITState.CurPosition = 0;
7674 ITState.FirstCond = true;
7684 // Assemblers should use the narrow encodings of these instructions when permissible.
7685 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7686 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7687 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7688 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7689 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7690 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7691 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7693 switch (Inst.getOpcode()) {
7694 default: llvm_unreachable("unexpected opcode");
7695 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7696 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7697 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7698 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7699 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7700 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7703 TmpInst.setOpcode(NewOpc);
7704 TmpInst.addOperand(Inst.getOperand(0));
7705 TmpInst.addOperand(Inst.getOperand(5));
7706 TmpInst.addOperand(Inst.getOperand(1));
7707 TmpInst.addOperand(Inst.getOperand(2));
7708 TmpInst.addOperand(Inst.getOperand(3));
7709 TmpInst.addOperand(Inst.getOperand(4));
7720 // Assemblers should use the narrow encodings of these instructions when permissible.
7721 // These instructions are special in that they are commutable, so shorter encodings
7722 // are available more often.
7723 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7724 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7725 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7726 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7727 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7728 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7729 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7730 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7732 switch (Inst.getOpcode()) {
7733 default: llvm_unreachable("unexpected opcode");
7734 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7735 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7736 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7737 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7740 TmpInst.setOpcode(NewOpc);
7741 TmpInst.addOperand(Inst.getOperand(0));
7742 TmpInst.addOperand(Inst.getOperand(5));
7743 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7744 TmpInst.addOperand(Inst.getOperand(1));
7745 TmpInst.addOperand(Inst.getOperand(2));
7747 TmpInst.addOperand(Inst.getOperand(2));
7748 TmpInst.addOperand(Inst.getOperand(1));
7750 TmpInst.addOperand(Inst.getOperand(3));
7751 TmpInst.addOperand(Inst.getOperand(4));
7761 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7762 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7763 // suffix depending on whether they're in an IT block or not.
7764 unsigned Opc = Inst.getOpcode();
7765 const MCInstrDesc &MCID = MII.get(Opc);
7766 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7767 assert(MCID.hasOptionalDef() &&
7768 "optionally flag setting instruction missing optional def operand");
7769 assert(MCID.NumOperands == Inst.getNumOperands() &&
7770 "operand count mismatch!");
7771 // Find the optional-def operand (cc_out).
7774 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7777 // If we're parsing Thumb1, reject it completely.
7778 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7779 return Match_MnemonicFail;
7780 // If we're parsing Thumb2, which form is legal depends on whether we're
7782 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7784 return Match_RequiresITBlock;
7785 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7787 return Match_RequiresNotITBlock;
7789 // Some high-register supporting Thumb1 encodings only allow both registers
7790 // to be from r0-r7 when in Thumb2.
7791 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7792 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7793 isARMLowRegister(Inst.getOperand(2).getReg()))
7794 return Match_RequiresThumb2;
7795 // Others only require ARMv6 or later.
7796 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7797 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7798 isARMLowRegister(Inst.getOperand(1).getReg()))
7799 return Match_RequiresV6;
7800 return Match_Success;
7803 static const char *getSubtargetFeatureName(unsigned Val);
7805 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7806 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7807 MCStreamer &Out, unsigned &ErrorInfo,
7808 bool MatchingInlineAsm) {
7810 unsigned MatchResult;
7812 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7814 switch (MatchResult) {
7817 // Context sensitive operand constraints aren't handled by the matcher,
7818 // so check them here.
7819 if (validateInstruction(Inst, Operands)) {
7820 // Still progress the IT block, otherwise one wrong condition causes
7821 // nasty cascading errors.
7822 forwardITPosition();
7826 { // processInstruction() updates inITBlock state, we need to save it away
7827 bool wasInITBlock = inITBlock();
7829 // Some instructions need post-processing to, for example, tweak which
7830 // encoding is selected. Loop on it while changes happen so the
7831 // individual transformations can chain off each other. E.g.,
7832 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7833 while (processInstruction(Inst, Operands))
7836 // Only after the instruction is fully processed, we can validate it
7837 if (wasInITBlock && hasV8Ops() && isThumb() &&
7838 !isV8EligibleForIT(&Inst, 2)) {
7839 Warning(IDLoc, "deprecated instruction in IT block");
7843 // Only move forward at the very end so that everything in validate
7844 // and process gets a consistent answer about whether we're in an IT
7846 forwardITPosition();
7848 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7849 // doesn't actually encode.
7850 if (Inst.getOpcode() == ARM::ITasm)
7854 Out.EmitInstruction(Inst);
7856 case Match_MissingFeature: {
7857 assert(ErrorInfo && "Unknown missing feature!");
7858 // Special case the error message for the very common case where only
7859 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7860 std::string Msg = "instruction requires:";
7862 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7863 if (ErrorInfo & Mask) {
7865 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7869 return Error(IDLoc, Msg);
7871 case Match_InvalidOperand: {
7872 SMLoc ErrorLoc = IDLoc;
7873 if (ErrorInfo != ~0U) {
7874 if (ErrorInfo >= Operands.size())
7875 return Error(IDLoc, "too few operands for instruction");
7877 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7878 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7881 return Error(ErrorLoc, "invalid operand for instruction");
7883 case Match_MnemonicFail:
7884 return Error(IDLoc, "invalid instruction",
7885 ((ARMOperand*)Operands[0])->getLocRange());
7886 case Match_RequiresNotITBlock:
7887 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7888 case Match_RequiresITBlock:
7889 return Error(IDLoc, "instruction only valid inside IT block");
7890 case Match_RequiresV6:
7891 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7892 case Match_RequiresThumb2:
7893 return Error(IDLoc, "instruction variant requires Thumb2");
7894 case Match_ImmRange0_15: {
7895 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7896 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7897 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7899 case Match_ImmRange0_239: {
7900 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7901 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7902 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7906 llvm_unreachable("Implement any new match types added!");
7909 /// parseDirective parses the arm specific directives
7910 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7911 StringRef IDVal = DirectiveID.getIdentifier();
7912 if (IDVal == ".word")
7913 return parseDirectiveWord(4, DirectiveID.getLoc());
7914 else if (IDVal == ".thumb")
7915 return parseDirectiveThumb(DirectiveID.getLoc());
7916 else if (IDVal == ".arm")
7917 return parseDirectiveARM(DirectiveID.getLoc());
7918 else if (IDVal == ".thumb_func")
7919 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7920 else if (IDVal == ".code")
7921 return parseDirectiveCode(DirectiveID.getLoc());
7922 else if (IDVal == ".syntax")
7923 return parseDirectiveSyntax(DirectiveID.getLoc());
7924 else if (IDVal == ".unreq")
7925 return parseDirectiveUnreq(DirectiveID.getLoc());
7926 else if (IDVal == ".arch")
7927 return parseDirectiveArch(DirectiveID.getLoc());
7928 else if (IDVal == ".eabi_attribute")
7929 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7930 else if (IDVal == ".cpu")
7931 return parseDirectiveCPU(DirectiveID.getLoc());
7932 else if (IDVal == ".fpu")
7933 return parseDirectiveFPU(DirectiveID.getLoc());
7934 else if (IDVal == ".fnstart")
7935 return parseDirectiveFnStart(DirectiveID.getLoc());
7936 else if (IDVal == ".fnend")
7937 return parseDirectiveFnEnd(DirectiveID.getLoc());
7938 else if (IDVal == ".cantunwind")
7939 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7940 else if (IDVal == ".personality")
7941 return parseDirectivePersonality(DirectiveID.getLoc());
7942 else if (IDVal == ".handlerdata")
7943 return parseDirectiveHandlerData(DirectiveID.getLoc());
7944 else if (IDVal == ".setfp")
7945 return parseDirectiveSetFP(DirectiveID.getLoc());
7946 else if (IDVal == ".pad")
7947 return parseDirectivePad(DirectiveID.getLoc());
7948 else if (IDVal == ".save")
7949 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7950 else if (IDVal == ".vsave")
7951 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7952 else if (IDVal == ".inst")
7953 return parseDirectiveInst(DirectiveID.getLoc());
7954 else if (IDVal == ".inst.n")
7955 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
7956 else if (IDVal == ".inst.w")
7957 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
7958 else if (IDVal == ".ltorg" || IDVal == ".pool")
7959 return parseDirectiveLtorg(DirectiveID.getLoc());
7960 else if (IDVal == ".even")
7961 return parseDirectiveEven(DirectiveID.getLoc());
7965 /// parseDirectiveWord
7966 /// ::= .word [ expression (, expression)* ]
7967 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7968 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7970 const MCExpr *Value;
7971 if (getParser().parseExpression(Value))
7974 getParser().getStreamer().EmitValue(Value, Size);
7976 if (getLexer().is(AsmToken::EndOfStatement))
7979 // FIXME: Improve diagnostic.
7980 if (getLexer().isNot(AsmToken::Comma))
7981 return Error(L, "unexpected token in directive");
7990 /// parseDirectiveThumb
7992 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7993 if (getLexer().isNot(AsmToken::EndOfStatement))
7994 return Error(L, "unexpected token in directive");
7998 return Error(L, "target does not support Thumb mode");
8002 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8006 /// parseDirectiveARM
8008 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
8009 if (getLexer().isNot(AsmToken::EndOfStatement))
8010 return Error(L, "unexpected token in directive");
8014 return Error(L, "target does not support ARM mode");
8018 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8022 void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8023 if (NextSymbolIsThumb) {
8024 getParser().getStreamer().EmitThumbFunc(Symbol);
8025 NextSymbolIsThumb = false;
8029 /// parseDirectiveThumbFunc
8030 /// ::= .thumbfunc symbol_name
8031 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
8032 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8033 bool isMachO = MAI->hasSubsectionsViaSymbols();
8035 // Darwin asm has (optionally) function name after .thumb_func direction
8038 const AsmToken &Tok = Parser.getTok();
8039 if (Tok.isNot(AsmToken::EndOfStatement)) {
8040 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
8041 return Error(L, "unexpected token in .thumb_func directive");
8043 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8044 getParser().getStreamer().EmitThumbFunc(Func);
8045 Parser.Lex(); // Consume the identifier token.
8050 if (getLexer().isNot(AsmToken::EndOfStatement))
8051 return Error(L, "unexpected token in directive");
8053 NextSymbolIsThumb = true;
8058 /// parseDirectiveSyntax
8059 /// ::= .syntax unified | divided
8060 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
8061 const AsmToken &Tok = Parser.getTok();
8062 if (Tok.isNot(AsmToken::Identifier))
8063 return Error(L, "unexpected token in .syntax directive");
8064 StringRef Mode = Tok.getString();
8065 if (Mode == "unified" || Mode == "UNIFIED")
8067 else if (Mode == "divided" || Mode == "DIVIDED")
8068 return Error(L, "'.syntax divided' arm asssembly not supported");
8070 return Error(L, "unrecognized syntax mode in .syntax directive");
8072 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8073 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8078 // TODO tell the MC streamer the mode
8079 // getParser().getStreamer().Emit???();
8083 /// parseDirectiveCode
8084 /// ::= .code 16 | 32
8085 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
8086 const AsmToken &Tok = Parser.getTok();
8087 if (Tok.isNot(AsmToken::Integer)) {
8088 Error(L, "unexpected token in .code directive");
8091 int64_t Val = Parser.getTok().getIntVal();
8092 if (Val != 16 && Val != 32) {
8093 Error(L, "invalid operand to .code directive");
8098 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8099 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8106 Error(L, "target does not support Thumb mode");
8112 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8115 Error(L, "target does not support ARM mode");
8121 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8127 /// parseDirectiveReq
8128 /// ::= name .req registername
8129 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8130 Parser.Lex(); // Eat the '.req' token.
8132 SMLoc SRegLoc, ERegLoc;
8133 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
8134 Parser.eatToEndOfStatement();
8135 Error(SRegLoc, "register name expected");
8139 // Shouldn't be anything else.
8140 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
8141 Parser.eatToEndOfStatement();
8142 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8146 Parser.Lex(); // Consume the EndOfStatement
8148 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) {
8149 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8156 /// parseDirectiveUneq
8157 /// ::= .unreq registername
8158 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8159 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8160 Parser.eatToEndOfStatement();
8161 Error(L, "unexpected input in .unreq directive.");
8164 RegisterReqs.erase(Parser.getTok().getIdentifier());
8165 Parser.Lex(); // Eat the identifier.
8169 /// parseDirectiveArch
8171 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8172 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8174 unsigned ID = StringSwitch<unsigned>(Arch)
8175 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8176 .Case(NAME, ARM::ID)
8177 #define ARM_ARCH_ALIAS(NAME, ID) \
8178 .Case(NAME, ARM::ID)
8179 #include "MCTargetDesc/ARMArchName.def"
8180 .Default(ARM::INVALID_ARCH);
8182 if (ID == ARM::INVALID_ARCH) {
8183 Error(L, "Unknown arch name");
8187 getTargetStreamer().emitArch(ID);
8191 /// parseDirectiveEabiAttr
8192 /// ::= .eabi_attribute int, int [, "str"]
8193 /// ::= .eabi_attribute Tag_name, int [, "str"]
8194 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8198 TagLoc = Parser.getTok().getLoc();
8199 if (Parser.getTok().is(AsmToken::Identifier)) {
8200 StringRef Name = Parser.getTok().getIdentifier();
8201 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
8203 Error(TagLoc, "attribute name not recognised: " + Name);
8204 Parser.eatToEndOfStatement();
8209 const MCExpr *AttrExpr;
8211 TagLoc = Parser.getTok().getLoc();
8212 if (Parser.parseExpression(AttrExpr)) {
8213 Parser.eatToEndOfStatement();
8217 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
8219 Error(TagLoc, "expected numeric constant");
8220 Parser.eatToEndOfStatement();
8224 Tag = CE->getValue();
8227 if (Parser.getTok().isNot(AsmToken::Comma)) {
8228 Error(Parser.getTok().getLoc(), "comma expected");
8229 Parser.eatToEndOfStatement();
8232 Parser.Lex(); // skip comma
8234 StringRef StringValue = "";
8235 bool IsStringValue = false;
8237 int64_t IntegerValue = 0;
8238 bool IsIntegerValue = false;
8240 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
8241 IsStringValue = true;
8242 else if (Tag == ARMBuildAttrs::compatibility) {
8243 IsStringValue = true;
8244 IsIntegerValue = true;
8245 } else if (Tag == ARMBuildAttrs::nodefaults || Tag < 32 || Tag % 2 == 0)
8246 IsIntegerValue = true;
8247 else if (Tag % 2 == 1)
8248 IsStringValue = true;
8250 llvm_unreachable("invalid tag type");
8252 if (IsIntegerValue) {
8253 const MCExpr *ValueExpr;
8254 SMLoc ValueExprLoc = Parser.getTok().getLoc();
8255 if (Parser.parseExpression(ValueExpr)) {
8256 Parser.eatToEndOfStatement();
8260 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
8262 Error(ValueExprLoc, "expected numeric constant");
8263 Parser.eatToEndOfStatement();
8267 IntegerValue = CE->getValue();
8270 if (Tag == ARMBuildAttrs::compatibility) {
8271 if (Parser.getTok().isNot(AsmToken::Comma))
8272 IsStringValue = false;
8277 if (IsStringValue) {
8278 if (Parser.getTok().isNot(AsmToken::String)) {
8279 Error(Parser.getTok().getLoc(), "bad string constant");
8280 Parser.eatToEndOfStatement();
8284 StringValue = Parser.getTok().getStringContents();
8288 if (IsIntegerValue && IsStringValue) {
8289 assert(Tag == ARMBuildAttrs::compatibility);
8290 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
8291 } else if (IsIntegerValue)
8292 getTargetStreamer().emitAttribute(Tag, IntegerValue);
8293 else if (IsStringValue)
8294 getTargetStreamer().emitTextAttribute(Tag, StringValue);
8298 /// parseDirectiveCPU
8300 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8301 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8302 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8306 /// parseDirectiveFPU
8308 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8309 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8311 unsigned ID = StringSwitch<unsigned>(FPU)
8312 #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8313 #include "ARMFPUName.def"
8314 .Default(ARM::INVALID_FPU);
8316 if (ID == ARM::INVALID_FPU) {
8317 Error(L, "Unknown FPU name");
8321 getTargetStreamer().emitFPU(ID);
8325 /// parseDirectiveFnStart
8327 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8328 if (FnStartLoc.isValid()) {
8329 Error(L, ".fnstart starts before the end of previous one");
8330 Note(FnStartLoc, "previous .fnstart starts here");
8335 getTargetStreamer().emitFnStart();
8339 /// parseDirectiveFnEnd
8341 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8342 // Check the ordering of unwind directives
8343 if (!FnStartLoc.isValid()) {
8344 Error(L, ".fnstart must precede .fnend directive");
8348 // Reset the unwind directives parser state
8349 resetUnwindDirectiveParserState();
8350 getTargetStreamer().emitFnEnd();
8354 /// parseDirectiveCantUnwind
8356 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8357 // Check the ordering of unwind directives
8359 if (!FnStartLoc.isValid()) {
8360 Error(L, ".fnstart must precede .cantunwind directive");
8363 if (HandlerDataLoc.isValid()) {
8364 Error(L, ".cantunwind can't be used with .handlerdata directive");
8365 Note(HandlerDataLoc, ".handlerdata was specified here");
8368 if (PersonalityLoc.isValid()) {
8369 Error(L, ".cantunwind can't be used with .personality directive");
8370 Note(PersonalityLoc, ".personality was specified here");
8374 getTargetStreamer().emitCantUnwind();
8378 /// parseDirectivePersonality
8379 /// ::= .personality name
8380 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8381 // Check the ordering of unwind directives
8383 if (!FnStartLoc.isValid()) {
8384 Error(L, ".fnstart must precede .personality directive");
8387 if (CantUnwindLoc.isValid()) {
8388 Error(L, ".personality can't be used with .cantunwind directive");
8389 Note(CantUnwindLoc, ".cantunwind was specified here");
8392 if (HandlerDataLoc.isValid()) {
8393 Error(L, ".personality must precede .handlerdata directive");
8394 Note(HandlerDataLoc, ".handlerdata was specified here");
8398 // Parse the name of the personality routine
8399 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8400 Parser.eatToEndOfStatement();
8401 Error(L, "unexpected input in .personality directive.");
8404 StringRef Name(Parser.getTok().getIdentifier());
8407 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8408 getTargetStreamer().emitPersonality(PR);
8412 /// parseDirectiveHandlerData
8413 /// ::= .handlerdata
8414 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8415 // Check the ordering of unwind directives
8417 if (!FnStartLoc.isValid()) {
8418 Error(L, ".fnstart must precede .personality directive");
8421 if (CantUnwindLoc.isValid()) {
8422 Error(L, ".handlerdata can't be used with .cantunwind directive");
8423 Note(CantUnwindLoc, ".cantunwind was specified here");
8427 getTargetStreamer().emitHandlerData();
8431 /// parseDirectiveSetFP
8432 /// ::= .setfp fpreg, spreg [, offset]
8433 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8434 // Check the ordering of unwind directives
8435 if (!FnStartLoc.isValid()) {
8436 Error(L, ".fnstart must precede .setfp directive");
8439 if (HandlerDataLoc.isValid()) {
8440 Error(L, ".setfp must precede .handlerdata directive");
8445 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8446 int NewFPReg = tryParseRegister();
8447 if (NewFPReg == -1) {
8448 Error(NewFPRegLoc, "frame pointer register expected");
8453 if (!Parser.getTok().is(AsmToken::Comma)) {
8454 Error(Parser.getTok().getLoc(), "comma expected");
8457 Parser.Lex(); // skip comma
8460 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8461 int NewSPReg = tryParseRegister();
8462 if (NewSPReg == -1) {
8463 Error(NewSPRegLoc, "stack pointer register expected");
8467 if (NewSPReg != ARM::SP && NewSPReg != FPReg) {
8469 "register should be either $sp or the latest fp register");
8473 // Update the frame pointer register
8478 if (Parser.getTok().is(AsmToken::Comma)) {
8479 Parser.Lex(); // skip comma
8481 if (Parser.getTok().isNot(AsmToken::Hash) &&
8482 Parser.getTok().isNot(AsmToken::Dollar)) {
8483 Error(Parser.getTok().getLoc(), "'#' expected");
8486 Parser.Lex(); // skip hash token.
8488 const MCExpr *OffsetExpr;
8489 SMLoc ExLoc = Parser.getTok().getLoc();
8491 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8492 Error(ExLoc, "malformed setfp offset");
8495 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8497 Error(ExLoc, "setfp offset must be an immediate");
8501 Offset = CE->getValue();
8504 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8505 static_cast<unsigned>(NewSPReg), Offset);
8511 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8512 // Check the ordering of unwind directives
8513 if (!FnStartLoc.isValid()) {
8514 Error(L, ".fnstart must precede .pad directive");
8517 if (HandlerDataLoc.isValid()) {
8518 Error(L, ".pad must precede .handlerdata directive");
8523 if (Parser.getTok().isNot(AsmToken::Hash) &&
8524 Parser.getTok().isNot(AsmToken::Dollar)) {
8525 Error(Parser.getTok().getLoc(), "'#' expected");
8528 Parser.Lex(); // skip hash token.
8530 const MCExpr *OffsetExpr;
8531 SMLoc ExLoc = Parser.getTok().getLoc();
8533 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8534 Error(ExLoc, "malformed pad offset");
8537 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8539 Error(ExLoc, "pad offset must be an immediate");
8543 getTargetStreamer().emitPad(CE->getValue());
8547 /// parseDirectiveRegSave
8548 /// ::= .save { registers }
8549 /// ::= .vsave { registers }
8550 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8551 // Check the ordering of unwind directives
8552 if (!FnStartLoc.isValid()) {
8553 Error(L, ".fnstart must precede .save or .vsave directives");
8556 if (HandlerDataLoc.isValid()) {
8557 Error(L, ".save or .vsave must precede .handlerdata directive");
8561 // RAII object to make sure parsed operands are deleted.
8562 struct CleanupObject {
8563 SmallVector<MCParsedAsmOperand *, 1> Operands;
8565 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8570 // Parse the register list
8571 if (parseRegisterList(CO.Operands))
8573 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
8574 if (!IsVector && !Op->isRegList()) {
8575 Error(L, ".save expects GPR registers");
8578 if (IsVector && !Op->isDPRRegList()) {
8579 Error(L, ".vsave expects DPR registers");
8583 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
8587 /// parseDirectiveInst
8588 /// ::= .inst opcode [, ...]
8589 /// ::= .inst.n opcode [, ...]
8590 /// ::= .inst.w opcode [, ...]
8591 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8603 Parser.eatToEndOfStatement();
8604 Error(Loc, "cannot determine Thumb instruction size, "
8605 "use inst.n/inst.w instead");
8610 Parser.eatToEndOfStatement();
8611 Error(Loc, "width suffixes are invalid in ARM mode");
8617 if (getLexer().is(AsmToken::EndOfStatement)) {
8618 Parser.eatToEndOfStatement();
8619 Error(Loc, "expected expression following directive");
8626 if (getParser().parseExpression(Expr)) {
8627 Error(Loc, "expected expression");
8631 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
8633 Error(Loc, "expected constant expression");
8639 if (Value->getValue() > 0xffff) {
8640 Error(Loc, "inst.n operand is too big, use inst.w instead");
8645 if (Value->getValue() > 0xffffffff) {
8647 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8652 llvm_unreachable("only supported widths are 2 and 4");
8655 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8657 if (getLexer().is(AsmToken::EndOfStatement))
8660 if (getLexer().isNot(AsmToken::Comma)) {
8661 Error(Loc, "unexpected token in directive");
8672 /// parseDirectiveLtorg
8673 /// ::= .ltorg | .pool
8674 bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
8675 MCStreamer &Streamer = getParser().getStreamer();
8676 const MCSection *Section = Streamer.getCurrentSection().first;
8678 if (ConstantPool *CP = getConstantPool(Section)) {
8680 CP->emitEntries(Streamer);
8685 bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
8686 const MCSection *Section = getStreamer().getCurrentSection().first;
8688 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8689 TokError("unexpected token in directive");
8694 getStreamer().InitToTextSection();
8695 Section = getStreamer().getCurrentSection().first;
8698 if (Section->UseCodeAlign())
8699 getStreamer().EmitCodeAlignment(2, 0);
8701 getStreamer().EmitValueToAlignment(2, 0, 1, 0);
8706 /// Force static initialization.
8707 extern "C" void LLVMInitializeARMAsmParser() {
8708 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8709 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8712 #define GET_REGISTER_MATCHER
8713 #define GET_SUBTARGET_FEATURE_NAME
8714 #define GET_MATCHER_IMPLEMENTATION
8715 #include "ARMGenAsmMatcher.inc"
8717 // Define this matcher function after the auto-generated include so we
8718 // have the match class enum definitions.
8719 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8721 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8722 // If the kind is a token for a literal immediate, check if our asm
8723 // operand matches. This is for InstAliases which have a fixed-value
8724 // immediate in the syntax.
8725 if (Kind == MCK__35_0 && Op->isImm()) {
8726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8728 return Match_InvalidOperand;
8729 if (CE->getValue() == 0)
8730 return Match_Success;
8732 return Match_InvalidOperand;
8735 void ARMAsmParser::finishParse() {
8736 // Dump contents of assembler constant pools.
8737 MCStreamer &Streamer = getParser().getStreamer();
8738 for (ConstantPoolMapTy::iterator CPI = ConstantPools.begin(),
8739 CPE = ConstantPools.end();
8740 CPI != CPE; ++CPI) {
8741 const MCSection *Section = CPI->first;
8742 ConstantPool &CP = CPI->second;
8744 // Dump non-empty assembler constant pools at the end of the section.
8746 Streamer.SwitchSection(Section);
8747 CP.emitEntries(Streamer);