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 "ARMBuildAttrs.h"
11 #include "ARMFPUName.h"
12 #include "ARMFeatures.h"
13 #include "llvm/MC/MCTargetAsmParser.h"
14 #include "MCTargetDesc/ARMAddressingModes.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/MCELFStreamer.h"
30 #include "llvm/MC/MCExpr.h"
31 #include "llvm/MC/MCInst.h"
32 #include "llvm/MC/MCInstrDesc.h"
33 #include "llvm/MC/MCInstrInfo.h"
34 #include "llvm/MC/MCParser/MCAsmLexer.h"
35 #include "llvm/MC/MCParser/MCAsmParser.h"
36 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
37 #include "llvm/MC/MCRegisterInfo.h"
38 #include "llvm/MC/MCStreamer.h"
39 #include "llvm/MC/MCSubtargetInfo.h"
40 #include "llvm/MC/MCSymbol.h"
41 #include "llvm/Support/ELF.h"
42 #include "llvm/Support/MathExtras.h"
43 #include "llvm/Support/SourceMgr.h"
44 #include "llvm/Support/TargetRegistry.h"
45 #include "llvm/Support/raw_ostream.h"
53 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
55 // A class to keep track of assembler-generated constant pools that are use to
56 // implement the ldr-pseudo.
58 typedef SmallVector<std::pair<MCSymbol *, const MCExpr *>, 4> EntryVecTy;
62 // Initialize a new empty constant pool
65 // Add a new entry to the constant pool in the next slot.
66 // \param Value is the new entry to put in the constant pool.
68 // \returns a MCExpr that references the newly inserted value
69 const MCExpr *addEntry(const MCExpr *Value, MCContext &Context) {
70 MCSymbol *CPEntryLabel = Context.CreateTempSymbol();
72 Entries.push_back(std::make_pair(CPEntryLabel, Value));
73 return MCSymbolRefExpr::Create(CPEntryLabel, Context);
76 // Emit the contents of the constant pool using the provided streamer.
77 void emitEntries(MCStreamer &Streamer) {
80 Streamer.EmitCodeAlignment(4); // align to 4-byte address
81 Streamer.EmitDataRegion(MCDR_DataRegion);
82 for (EntryVecTy::const_iterator I = Entries.begin(), E = Entries.end();
84 Streamer.EmitLabel(I->first);
85 Streamer.EmitValue(I->second, 4);
87 Streamer.EmitDataRegion(MCDR_DataRegionEnd);
91 // Return true if the constant pool is empty
93 return Entries.empty();
97 // Map type used to keep track of per-Section constant pools used by the
98 // ldr-pseudo opcode. The map associates a section to its constant pool. The
99 // constant pool is a vector of (label, value) pairs. When the ldr
100 // pseudo is parsed we insert a new (label, value) pair into the constant pool
101 // for the current section and add MCSymbolRefExpr to the new label as
102 // an opcode to the ldr. After we have parsed all the user input we
103 // output the (label, value) pairs in each constant pool at the end of the
106 // We use the MapVector for the map type to ensure stable iteration of
107 // the sections at the end of the parse. We need to iterate over the
108 // sections in a stable order to ensure that we have print the
109 // constant pools in a deterministic order when printing an assembly
111 typedef MapVector<const MCSection *, ConstantPool> ConstantPoolMapTy;
113 class ARMAsmParser : public MCTargetAsmParser {
114 MCSubtargetInfo &STI;
116 const MCInstrInfo &MII;
117 const MCRegisterInfo *MRI;
118 ConstantPoolMapTy ConstantPools;
120 // Assembler created constant pools for ldr pseudo
121 ConstantPool *getConstantPool(const MCSection *Section) {
122 ConstantPoolMapTy::iterator CP = ConstantPools.find(Section);
123 if (CP == ConstantPools.end())
129 ConstantPool &getOrCreateConstantPool(const MCSection *Section) {
130 return ConstantPools[Section];
133 ARMTargetStreamer &getTargetStreamer() {
134 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
135 return static_cast<ARMTargetStreamer &>(TS);
138 // Unwind directives state
141 SMLoc PersonalityLoc;
142 SMLoc HandlerDataLoc;
144 void resetUnwindDirectiveParserState() {
145 FnStartLoc = SMLoc();
146 CantUnwindLoc = SMLoc();
147 PersonalityLoc = SMLoc();
148 HandlerDataLoc = SMLoc();
152 // Map of register aliases registers via the .req directive.
153 StringMap<unsigned> RegisterReqs;
155 bool NextSymbolIsThumb;
158 ARMCC::CondCodes Cond; // Condition for IT block.
159 unsigned Mask:4; // Condition mask for instructions.
160 // Starting at first 1 (from lsb).
161 // '1' condition as indicated in IT.
162 // '0' inverse of condition (else).
163 // Count of instructions in IT block is
164 // 4 - trailingzeroes(mask)
166 bool FirstCond; // Explicit flag for when we're parsing the
167 // First instruction in the IT block. It's
168 // implied in the mask, so needs special
171 unsigned CurPosition; // Current position in parsing of IT
172 // block. In range [0,3]. Initialized
173 // according to count of instructions in block.
174 // ~0U if no active IT block.
176 bool inITBlock() { return ITState.CurPosition != ~0U;}
177 void forwardITPosition() {
178 if (!inITBlock()) return;
179 // Move to the next instruction in the IT block, if there is one. If not,
180 // mark the block as done.
181 unsigned TZ = countTrailingZeros(ITState.Mask);
182 if (++ITState.CurPosition == 5 - TZ)
183 ITState.CurPosition = ~0U; // Done with the IT block after this.
187 MCAsmParser &getParser() const { return Parser; }
188 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
190 bool Warning(SMLoc L, const Twine &Msg,
191 ArrayRef<SMRange> Ranges = None) {
192 return Parser.Warning(L, Msg, Ranges);
194 bool Error(SMLoc L, const Twine &Msg,
195 ArrayRef<SMRange> Ranges = None) {
196 return Parser.Error(L, Msg, Ranges);
199 int tryParseRegister();
200 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
201 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
202 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
203 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
204 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
205 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
206 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
207 unsigned &ShiftAmount);
208 bool parseDirectiveWord(unsigned Size, SMLoc L);
209 bool parseDirectiveThumb(SMLoc L);
210 bool parseDirectiveARM(SMLoc L);
211 bool parseDirectiveThumbFunc(SMLoc L);
212 bool parseDirectiveCode(SMLoc L);
213 bool parseDirectiveSyntax(SMLoc L);
214 bool parseDirectiveReq(StringRef Name, SMLoc L);
215 bool parseDirectiveUnreq(SMLoc L);
216 bool parseDirectiveArch(SMLoc L);
217 bool parseDirectiveEabiAttr(SMLoc L);
218 bool parseDirectiveCPU(SMLoc L);
219 bool parseDirectiveFPU(SMLoc L);
220 bool parseDirectiveFnStart(SMLoc L);
221 bool parseDirectiveFnEnd(SMLoc L);
222 bool parseDirectiveCantUnwind(SMLoc L);
223 bool parseDirectivePersonality(SMLoc L);
224 bool parseDirectiveHandlerData(SMLoc L);
225 bool parseDirectiveSetFP(SMLoc L);
226 bool parseDirectivePad(SMLoc L);
227 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
228 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
229 bool parseDirectiveLtorg(SMLoc L);
231 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
232 bool &CarrySetting, unsigned &ProcessorIMod,
234 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
235 bool &CanAcceptCarrySet,
236 bool &CanAcceptPredicationCode);
238 bool isThumb() const {
239 // FIXME: Can tablegen auto-generate this?
240 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
242 bool isThumbOne() const {
243 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
245 bool isThumbTwo() const {
246 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
248 bool hasThumb() const {
249 return STI.getFeatureBits() & ARM::HasV4TOps;
251 bool hasV6Ops() const {
252 return STI.getFeatureBits() & ARM::HasV6Ops;
254 bool hasV6MOps() const {
255 return STI.getFeatureBits() & ARM::HasV6MOps;
257 bool hasV7Ops() const {
258 return STI.getFeatureBits() & ARM::HasV7Ops;
260 bool hasV8Ops() const {
261 return STI.getFeatureBits() & ARM::HasV8Ops;
263 bool hasARM() const {
264 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
268 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
269 setAvailableFeatures(FB);
271 bool isMClass() const {
272 return STI.getFeatureBits() & ARM::FeatureMClass;
275 /// @name Auto-generated Match Functions
278 #define GET_ASSEMBLER_HEADER
279 #include "ARMGenAsmMatcher.inc"
283 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
284 OperandMatchResultTy parseCoprocNumOperand(
285 SmallVectorImpl<MCParsedAsmOperand*>&);
286 OperandMatchResultTy parseCoprocRegOperand(
287 SmallVectorImpl<MCParsedAsmOperand*>&);
288 OperandMatchResultTy parseCoprocOptionOperand(
289 SmallVectorImpl<MCParsedAsmOperand*>&);
290 OperandMatchResultTy parseMemBarrierOptOperand(
291 SmallVectorImpl<MCParsedAsmOperand*>&);
292 OperandMatchResultTy parseInstSyncBarrierOptOperand(
293 SmallVectorImpl<MCParsedAsmOperand*>&);
294 OperandMatchResultTy parseProcIFlagsOperand(
295 SmallVectorImpl<MCParsedAsmOperand*>&);
296 OperandMatchResultTy parseMSRMaskOperand(
297 SmallVectorImpl<MCParsedAsmOperand*>&);
298 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
299 StringRef Op, int Low, int High);
300 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
301 return parsePKHImm(O, "lsl", 0, 31);
303 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
304 return parsePKHImm(O, "asr", 1, 32);
306 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
307 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
308 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
309 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
310 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
311 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
312 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
313 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
314 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
317 // Asm Match Converter Methods
318 void cvtThumbMultiply(MCInst &Inst,
319 const SmallVectorImpl<MCParsedAsmOperand*> &);
320 void cvtThumbBranches(MCInst &Inst,
321 const SmallVectorImpl<MCParsedAsmOperand*> &);
323 bool validateInstruction(MCInst &Inst,
324 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
325 bool processInstruction(MCInst &Inst,
326 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
327 bool shouldOmitCCOutOperand(StringRef Mnemonic,
328 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
329 bool shouldOmitPredicateOperand(StringRef Mnemonic,
330 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
332 enum ARMMatchResultTy {
333 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
334 Match_RequiresNotITBlock,
336 Match_RequiresThumb2,
337 #define GET_OPERAND_DIAGNOSTIC_TYPES
338 #include "ARMGenAsmMatcher.inc"
342 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
343 const MCInstrInfo &MII)
344 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
345 MCAsmParserExtension::Initialize(_Parser);
347 // Cache the MCRegisterInfo.
348 MRI = getContext().getRegisterInfo();
350 // Initialize the set of available features.
351 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
353 // Not in an ITBlock to start with.
354 ITState.CurPosition = ~0U;
356 NextSymbolIsThumb = false;
359 // Implementation of the MCTargetAsmParser interface:
360 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
361 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
363 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
364 bool ParseDirective(AsmToken DirectiveID);
366 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
367 unsigned checkTargetMatchPredicate(MCInst &Inst);
369 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
370 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
371 MCStreamer &Out, unsigned &ErrorInfo,
372 bool MatchingInlineAsm);
373 void onLabelParsed(MCSymbol *Symbol);
376 } // end anonymous namespace
380 /// ARMOperand - Instances of this class represent a parsed ARM machine
382 class ARMOperand : public MCParsedAsmOperand {
392 k_InstSyncBarrierOpt,
403 k_VectorListAllLanes,
409 k_BitfieldDescriptor,
413 SMLoc StartLoc, EndLoc;
414 SmallVector<unsigned, 8> Registers;
417 ARMCC::CondCodes Val;
424 struct CoprocOptionOp {
437 ARM_ISB::InstSyncBOpt Val;
441 ARM_PROC::IFlags Val;
457 // A vector register list is a sequential list of 1 to 4 registers.
458 struct VectorListOp {
465 struct VectorIndexOp {
473 /// Combined record for all forms of ARM address expressions.
476 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
478 const MCConstantExpr *OffsetImm; // Offset immediate value
479 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
480 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
481 unsigned ShiftImm; // shift for OffsetReg.
482 unsigned Alignment; // 0 = no alignment specified
483 // n = alignment in bytes (2, 4, 8, 16, or 32)
484 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
487 struct PostIdxRegOp {
490 ARM_AM::ShiftOpc ShiftTy;
494 struct ShifterImmOp {
499 struct RegShiftedRegOp {
500 ARM_AM::ShiftOpc ShiftTy;
506 struct RegShiftedImmOp {
507 ARM_AM::ShiftOpc ShiftTy;
524 struct CoprocOptionOp CoprocOption;
525 struct MBOptOp MBOpt;
526 struct ISBOptOp ISBOpt;
527 struct ITMaskOp ITMask;
528 struct IFlagsOp IFlags;
529 struct MMaskOp MMask;
532 struct VectorListOp VectorList;
533 struct VectorIndexOp VectorIndex;
535 struct MemoryOp Memory;
536 struct PostIdxRegOp PostIdxReg;
537 struct ShifterImmOp ShifterImm;
538 struct RegShiftedRegOp RegShiftedReg;
539 struct RegShiftedImmOp RegShiftedImm;
540 struct RotImmOp RotImm;
541 struct BitfieldOp Bitfield;
544 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
546 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
548 StartLoc = o.StartLoc;
565 case k_DPRRegisterList:
566 case k_SPRRegisterList:
567 Registers = o.Registers;
570 case k_VectorListAllLanes:
571 case k_VectorListIndexed:
572 VectorList = o.VectorList;
579 CoprocOption = o.CoprocOption;
584 case k_MemBarrierOpt:
587 case k_InstSyncBarrierOpt:
592 case k_PostIndexRegister:
593 PostIdxReg = o.PostIdxReg;
601 case k_ShifterImmediate:
602 ShifterImm = o.ShifterImm;
604 case k_ShiftedRegister:
605 RegShiftedReg = o.RegShiftedReg;
607 case k_ShiftedImmediate:
608 RegShiftedImm = o.RegShiftedImm;
610 case k_RotateImmediate:
613 case k_BitfieldDescriptor:
614 Bitfield = o.Bitfield;
617 VectorIndex = o.VectorIndex;
622 /// getStartLoc - Get the location of the first token of this operand.
623 SMLoc getStartLoc() const { return StartLoc; }
624 /// getEndLoc - Get the location of the last token of this operand.
625 SMLoc getEndLoc() const { return EndLoc; }
626 /// getLocRange - Get the range between the first and last token of this
628 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
630 ARMCC::CondCodes getCondCode() const {
631 assert(Kind == k_CondCode && "Invalid access!");
635 unsigned getCoproc() const {
636 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
640 StringRef getToken() const {
641 assert(Kind == k_Token && "Invalid access!");
642 return StringRef(Tok.Data, Tok.Length);
645 unsigned getReg() const {
646 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
650 const SmallVectorImpl<unsigned> &getRegList() const {
651 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
652 Kind == k_SPRRegisterList) && "Invalid access!");
656 const MCExpr *getImm() const {
657 assert(isImm() && "Invalid access!");
661 unsigned getVectorIndex() const {
662 assert(Kind == k_VectorIndex && "Invalid access!");
663 return VectorIndex.Val;
666 ARM_MB::MemBOpt getMemBarrierOpt() const {
667 assert(Kind == k_MemBarrierOpt && "Invalid access!");
671 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
672 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
676 ARM_PROC::IFlags getProcIFlags() const {
677 assert(Kind == k_ProcIFlags && "Invalid access!");
681 unsigned getMSRMask() const {
682 assert(Kind == k_MSRMask && "Invalid access!");
686 bool isCoprocNum() const { return Kind == k_CoprocNum; }
687 bool isCoprocReg() const { return Kind == k_CoprocReg; }
688 bool isCoprocOption() const { return Kind == k_CoprocOption; }
689 bool isCondCode() const { return Kind == k_CondCode; }
690 bool isCCOut() const { return Kind == k_CCOut; }
691 bool isITMask() const { return Kind == k_ITCondMask; }
692 bool isITCondCode() const { return Kind == k_CondCode; }
693 bool isImm() const { return Kind == k_Immediate; }
694 // checks whether this operand is an unsigned offset which fits is a field
695 // of specified width and scaled by a specific number of bits
696 template<unsigned width, unsigned scale>
697 bool isUnsignedOffset() const {
698 if (!isImm()) return false;
699 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
700 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
701 int64_t Val = CE->getValue();
702 int64_t Align = 1LL << scale;
703 int64_t Max = Align * ((1LL << width) - 1);
704 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
708 // checks whether this operand is an signed offset which fits is a field
709 // of specified width and scaled by a specific number of bits
710 template<unsigned width, unsigned scale>
711 bool isSignedOffset() const {
712 if (!isImm()) return false;
713 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
714 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
715 int64_t Val = CE->getValue();
716 int64_t Align = 1LL << scale;
717 int64_t Max = Align * ((1LL << (width-1)) - 1);
718 int64_t Min = -Align * (1LL << (width-1));
719 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
724 // checks whether this operand is a memory operand computed as an offset
725 // applied to PC. the offset may have 8 bits of magnitude and is represented
726 // with two bits of shift. textually it may be either [pc, #imm], #imm or
727 // relocable expression...
728 bool isThumbMemPC() const {
731 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
733 if (!CE) return false;
734 Val = CE->getValue();
737 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
738 if(Memory.BaseRegNum != ARM::PC) return false;
739 Val = Memory.OffsetImm->getValue();
742 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
744 bool isFPImm() const {
745 if (!isImm()) return false;
746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
747 if (!CE) return false;
748 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
751 bool isFBits16() const {
752 if (!isImm()) return false;
753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
754 if (!CE) return false;
755 int64_t Value = CE->getValue();
756 return Value >= 0 && Value <= 16;
758 bool isFBits32() 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 >= 1 && Value <= 32;
765 bool isImm8s4() 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 & 3) == 0) && Value >= -1020 && Value <= 1020;
772 bool isImm0_1020s4() 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 >= 0 && Value <= 1020;
779 bool isImm0_508s4() 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 <= 508;
786 bool isImm0_508s4Neg() 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 // explicitly exclude zero. we want that to use the normal 0_508 version.
792 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
794 bool isImm0_239() const {
795 if (!isImm()) return false;
796 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
797 if (!CE) return false;
798 int64_t Value = CE->getValue();
799 return Value >= 0 && Value < 240;
801 bool isImm0_255() 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 < 256;
808 bool isImm0_4095() 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 < 4096;
815 bool isImm0_4095Neg() 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_1() 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 < 2;
829 bool isImm0_3() 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 < 4;
836 bool isImm0_7() 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 < 8;
843 bool isImm0_15() 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 < 16;
850 bool isImm0_31() 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 < 32;
857 bool isImm0_63() 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 < 64;
864 bool isImm8() 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();
871 bool isImm16() 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 isImm32() 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 isShrImm8() 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();
890 return Value > 0 && Value <= 8;
892 bool isShrImm16() 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 <= 16;
899 bool isShrImm32() 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 <= 32;
906 bool isShrImm64() 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 <= 64;
913 bool isImm1_7() 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 < 8;
920 bool isImm1_15() 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 < 16;
927 bool isImm1_31() 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 < 32;
934 bool isImm1_16() 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 < 17;
941 bool isImm1_32() 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 < 33;
948 bool isImm0_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_65535() 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 < 65536;
962 bool isImm256_65535Expr() const {
963 if (!isImm()) return false;
964 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
965 // If it's not a constant expression, it'll generate a fixup and be
967 if (!CE) return true;
968 int64_t Value = CE->getValue();
969 return Value >= 256 && Value < 65536;
971 bool isImm0_65535Expr() const {
972 if (!isImm()) return false;
973 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
974 // If it's not a constant expression, it'll generate a fixup and be
976 if (!CE) return true;
977 int64_t Value = CE->getValue();
978 return Value >= 0 && Value < 65536;
980 bool isImm24bit() const {
981 if (!isImm()) return false;
982 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
983 if (!CE) return false;
984 int64_t Value = CE->getValue();
985 return Value >= 0 && Value <= 0xffffff;
987 bool isImmThumbSR() 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 < 33;
994 bool isPKHLSLImm() 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 < 32;
1001 bool isPKHASRImm() 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 isAdrLabel() const {
1009 // If we have an immediate that's not a constant, treat it as a label
1010 // reference needing a fixup. If it is a constant, but it can't fit
1011 // into shift immediate encoding, we reject it.
1012 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1013 else return (isARMSOImm() || isARMSOImmNeg());
1015 bool isARMSOImm() const {
1016 if (!isImm()) return false;
1017 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1018 if (!CE) return false;
1019 int64_t Value = CE->getValue();
1020 return ARM_AM::getSOImmVal(Value) != -1;
1022 bool isARMSOImmNot() 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 isARMSOImmNeg() 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 // Only use this when not representable as a plain so_imm.
1035 return ARM_AM::getSOImmVal(Value) == -1 &&
1036 ARM_AM::getSOImmVal(-Value) != -1;
1038 bool isT2SOImm() const {
1039 if (!isImm()) return false;
1040 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1041 if (!CE) return false;
1042 int64_t Value = CE->getValue();
1043 return ARM_AM::getT2SOImmVal(Value) != -1;
1045 bool isT2SOImmNot() 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 &&
1051 ARM_AM::getT2SOImmVal(~Value) != -1;
1053 bool isT2SOImmNeg() const {
1054 if (!isImm()) return false;
1055 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1056 if (!CE) return false;
1057 int64_t Value = CE->getValue();
1058 // Only use this when not representable as a plain so_imm.
1059 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1060 ARM_AM::getT2SOImmVal(-Value) != -1;
1062 bool isSetEndImm() const {
1063 if (!isImm()) return false;
1064 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1065 if (!CE) return false;
1066 int64_t Value = CE->getValue();
1067 return Value == 1 || Value == 0;
1069 bool isReg() const { return Kind == k_Register; }
1070 bool isRegList() const { return Kind == k_RegisterList; }
1071 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1072 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
1073 bool isToken() const { return Kind == k_Token; }
1074 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
1075 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
1076 bool isMem() const { return Kind == k_Memory; }
1077 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1078 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1079 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1080 bool isRotImm() const { return Kind == k_RotateImmediate; }
1081 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1082 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
1083 bool isPostIdxReg() const {
1084 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
1086 bool isMemNoOffset(bool alignOK = false) const {
1089 // No offset of any kind.
1090 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1091 (alignOK || Memory.Alignment == 0);
1093 bool isMemPCRelImm12() const {
1094 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1096 // Base register must be PC.
1097 if (Memory.BaseRegNum != ARM::PC)
1099 // Immediate offset in range [-4095, 4095].
1100 if (!Memory.OffsetImm) return true;
1101 int64_t Val = Memory.OffsetImm->getValue();
1102 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1104 bool isAlignedMemory() const {
1105 return isMemNoOffset(true);
1107 bool isAddrMode2() const {
1108 if (!isMem() || Memory.Alignment != 0) return false;
1109 // Check for register offset.
1110 if (Memory.OffsetRegNum) return true;
1111 // Immediate offset in range [-4095, 4095].
1112 if (!Memory.OffsetImm) return true;
1113 int64_t Val = Memory.OffsetImm->getValue();
1114 return Val > -4096 && Val < 4096;
1116 bool isAM2OffsetImm() const {
1117 if (!isImm()) return false;
1118 // Immediate offset in range [-4095, 4095].
1119 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1120 if (!CE) return false;
1121 int64_t Val = CE->getValue();
1122 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1124 bool isAddrMode3() const {
1125 // If we have an immediate that's not a constant, treat it as a label
1126 // reference needing a fixup. If it is a constant, it's something else
1127 // and we reject it.
1128 if (isImm() && !isa<MCConstantExpr>(getImm()))
1130 if (!isMem() || Memory.Alignment != 0) return false;
1131 // No shifts are legal for AM3.
1132 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1133 // Check for register offset.
1134 if (Memory.OffsetRegNum) return true;
1135 // Immediate offset in range [-255, 255].
1136 if (!Memory.OffsetImm) return true;
1137 int64_t Val = Memory.OffsetImm->getValue();
1138 // The #-0 offset is encoded as INT32_MIN, and we have to check
1140 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1142 bool isAM3Offset() const {
1143 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1145 if (Kind == k_PostIndexRegister)
1146 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1147 // Immediate offset in range [-255, 255].
1148 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1149 if (!CE) return false;
1150 int64_t Val = CE->getValue();
1151 // Special case, #-0 is INT32_MIN.
1152 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1154 bool isAddrMode5() const {
1155 // If we have an immediate that's not a constant, treat it as a label
1156 // reference needing a fixup. If it is a constant, it's something else
1157 // and we reject it.
1158 if (isImm() && !isa<MCConstantExpr>(getImm()))
1160 if (!isMem() || Memory.Alignment != 0) return false;
1161 // Check for register offset.
1162 if (Memory.OffsetRegNum) return false;
1163 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1164 if (!Memory.OffsetImm) return true;
1165 int64_t Val = Memory.OffsetImm->getValue();
1166 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1169 bool isMemTBB() const {
1170 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1171 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1175 bool isMemTBH() const {
1176 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1177 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1178 Memory.Alignment != 0 )
1182 bool isMemRegOffset() const {
1183 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1187 bool isT2MemRegOffset() const {
1188 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1189 Memory.Alignment != 0)
1191 // Only lsl #{0, 1, 2, 3} allowed.
1192 if (Memory.ShiftType == ARM_AM::no_shift)
1194 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1198 bool isMemThumbRR() const {
1199 // Thumb reg+reg addressing is simple. Just two registers, a base and
1200 // an offset. No shifts, negations or any other complicating factors.
1201 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1202 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1204 return isARMLowRegister(Memory.BaseRegNum) &&
1205 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1207 bool isMemThumbRIs4() const {
1208 if (!isMem() || Memory.OffsetRegNum != 0 ||
1209 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1211 // Immediate offset, multiple of 4 in range [0, 124].
1212 if (!Memory.OffsetImm) return true;
1213 int64_t Val = Memory.OffsetImm->getValue();
1214 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1216 bool isMemThumbRIs2() const {
1217 if (!isMem() || Memory.OffsetRegNum != 0 ||
1218 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1220 // Immediate offset, multiple of 4 in range [0, 62].
1221 if (!Memory.OffsetImm) return true;
1222 int64_t Val = Memory.OffsetImm->getValue();
1223 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1225 bool isMemThumbRIs1() const {
1226 if (!isMem() || Memory.OffsetRegNum != 0 ||
1227 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1229 // Immediate offset in range [0, 31].
1230 if (!Memory.OffsetImm) return true;
1231 int64_t Val = Memory.OffsetImm->getValue();
1232 return Val >= 0 && Val <= 31;
1234 bool isMemThumbSPI() const {
1235 if (!isMem() || Memory.OffsetRegNum != 0 ||
1236 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1238 // Immediate offset, multiple of 4 in range [0, 1020].
1239 if (!Memory.OffsetImm) return true;
1240 int64_t Val = Memory.OffsetImm->getValue();
1241 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1243 bool isMemImm8s4Offset() const {
1244 // If we have an immediate that's not a constant, treat it as a label
1245 // reference needing a fixup. If it is a constant, it's something else
1246 // and we reject it.
1247 if (isImm() && !isa<MCConstantExpr>(getImm()))
1249 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1251 // Immediate offset a multiple of 4 in range [-1020, 1020].
1252 if (!Memory.OffsetImm) return true;
1253 int64_t Val = Memory.OffsetImm->getValue();
1254 // Special case, #-0 is INT32_MIN.
1255 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1257 bool isMemImm0_1020s4Offset() const {
1258 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1260 // Immediate offset a multiple of 4 in range [0, 1020].
1261 if (!Memory.OffsetImm) return true;
1262 int64_t Val = Memory.OffsetImm->getValue();
1263 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1265 bool isMemImm8Offset() const {
1266 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1268 // Base reg of PC isn't allowed for these encodings.
1269 if (Memory.BaseRegNum == ARM::PC) return false;
1270 // Immediate offset in range [-255, 255].
1271 if (!Memory.OffsetImm) return true;
1272 int64_t Val = Memory.OffsetImm->getValue();
1273 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1275 bool isMemPosImm8Offset() const {
1276 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1278 // Immediate offset in range [0, 255].
1279 if (!Memory.OffsetImm) return true;
1280 int64_t Val = Memory.OffsetImm->getValue();
1281 return Val >= 0 && Val < 256;
1283 bool isMemNegImm8Offset() const {
1284 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1286 // Base reg of PC isn't allowed for these encodings.
1287 if (Memory.BaseRegNum == ARM::PC) return false;
1288 // Immediate offset in range [-255, -1].
1289 if (!Memory.OffsetImm) return false;
1290 int64_t Val = Memory.OffsetImm->getValue();
1291 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1293 bool isMemUImm12Offset() const {
1294 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1296 // Immediate offset in range [0, 4095].
1297 if (!Memory.OffsetImm) return true;
1298 int64_t Val = Memory.OffsetImm->getValue();
1299 return (Val >= 0 && Val < 4096);
1301 bool isMemImm12Offset() const {
1302 // If we have an immediate that's not a constant, treat it as a label
1303 // reference needing a fixup. If it is a constant, it's something else
1304 // and we reject it.
1305 if (isImm() && !isa<MCConstantExpr>(getImm()))
1308 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1310 // Immediate offset in range [-4095, 4095].
1311 if (!Memory.OffsetImm) return true;
1312 int64_t Val = Memory.OffsetImm->getValue();
1313 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1315 bool isPostIdxImm8() const {
1316 if (!isImm()) return false;
1317 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1318 if (!CE) return false;
1319 int64_t Val = CE->getValue();
1320 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1322 bool isPostIdxImm8s4() 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 & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1331 bool isMSRMask() const { return Kind == k_MSRMask; }
1332 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1335 bool isSingleSpacedVectorList() const {
1336 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1338 bool isDoubleSpacedVectorList() const {
1339 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1341 bool isVecListOneD() const {
1342 if (!isSingleSpacedVectorList()) return false;
1343 return VectorList.Count == 1;
1346 bool isVecListDPair() const {
1347 if (!isSingleSpacedVectorList()) return false;
1348 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1349 .contains(VectorList.RegNum));
1352 bool isVecListThreeD() const {
1353 if (!isSingleSpacedVectorList()) return false;
1354 return VectorList.Count == 3;
1357 bool isVecListFourD() const {
1358 if (!isSingleSpacedVectorList()) return false;
1359 return VectorList.Count == 4;
1362 bool isVecListDPairSpaced() const {
1363 if (isSingleSpacedVectorList()) return false;
1364 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1365 .contains(VectorList.RegNum));
1368 bool isVecListThreeQ() const {
1369 if (!isDoubleSpacedVectorList()) return false;
1370 return VectorList.Count == 3;
1373 bool isVecListFourQ() const {
1374 if (!isDoubleSpacedVectorList()) return false;
1375 return VectorList.Count == 4;
1378 bool isSingleSpacedVectorAllLanes() const {
1379 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1381 bool isDoubleSpacedVectorAllLanes() const {
1382 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1384 bool isVecListOneDAllLanes() const {
1385 if (!isSingleSpacedVectorAllLanes()) return false;
1386 return VectorList.Count == 1;
1389 bool isVecListDPairAllLanes() const {
1390 if (!isSingleSpacedVectorAllLanes()) return false;
1391 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1392 .contains(VectorList.RegNum));
1395 bool isVecListDPairSpacedAllLanes() const {
1396 if (!isDoubleSpacedVectorAllLanes()) return false;
1397 return VectorList.Count == 2;
1400 bool isVecListThreeDAllLanes() const {
1401 if (!isSingleSpacedVectorAllLanes()) return false;
1402 return VectorList.Count == 3;
1405 bool isVecListThreeQAllLanes() const {
1406 if (!isDoubleSpacedVectorAllLanes()) return false;
1407 return VectorList.Count == 3;
1410 bool isVecListFourDAllLanes() const {
1411 if (!isSingleSpacedVectorAllLanes()) return false;
1412 return VectorList.Count == 4;
1415 bool isVecListFourQAllLanes() const {
1416 if (!isDoubleSpacedVectorAllLanes()) return false;
1417 return VectorList.Count == 4;
1420 bool isSingleSpacedVectorIndexed() const {
1421 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1423 bool isDoubleSpacedVectorIndexed() const {
1424 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1426 bool isVecListOneDByteIndexed() const {
1427 if (!isSingleSpacedVectorIndexed()) return false;
1428 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1431 bool isVecListOneDHWordIndexed() const {
1432 if (!isSingleSpacedVectorIndexed()) return false;
1433 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1436 bool isVecListOneDWordIndexed() const {
1437 if (!isSingleSpacedVectorIndexed()) return false;
1438 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1441 bool isVecListTwoDByteIndexed() const {
1442 if (!isSingleSpacedVectorIndexed()) return false;
1443 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1446 bool isVecListTwoDHWordIndexed() const {
1447 if (!isSingleSpacedVectorIndexed()) return false;
1448 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1451 bool isVecListTwoQWordIndexed() const {
1452 if (!isDoubleSpacedVectorIndexed()) return false;
1453 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1456 bool isVecListTwoQHWordIndexed() const {
1457 if (!isDoubleSpacedVectorIndexed()) return false;
1458 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1461 bool isVecListTwoDWordIndexed() const {
1462 if (!isSingleSpacedVectorIndexed()) return false;
1463 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1466 bool isVecListThreeDByteIndexed() const {
1467 if (!isSingleSpacedVectorIndexed()) return false;
1468 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1471 bool isVecListThreeDHWordIndexed() const {
1472 if (!isSingleSpacedVectorIndexed()) return false;
1473 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1476 bool isVecListThreeQWordIndexed() const {
1477 if (!isDoubleSpacedVectorIndexed()) return false;
1478 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1481 bool isVecListThreeQHWordIndexed() const {
1482 if (!isDoubleSpacedVectorIndexed()) return false;
1483 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1486 bool isVecListThreeDWordIndexed() const {
1487 if (!isSingleSpacedVectorIndexed()) return false;
1488 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1491 bool isVecListFourDByteIndexed() const {
1492 if (!isSingleSpacedVectorIndexed()) return false;
1493 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1496 bool isVecListFourDHWordIndexed() const {
1497 if (!isSingleSpacedVectorIndexed()) return false;
1498 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1501 bool isVecListFourQWordIndexed() const {
1502 if (!isDoubleSpacedVectorIndexed()) return false;
1503 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1506 bool isVecListFourQHWordIndexed() const {
1507 if (!isDoubleSpacedVectorIndexed()) return false;
1508 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1511 bool isVecListFourDWordIndexed() const {
1512 if (!isSingleSpacedVectorIndexed()) return false;
1513 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1516 bool isVectorIndex8() const {
1517 if (Kind != k_VectorIndex) return false;
1518 return VectorIndex.Val < 8;
1520 bool isVectorIndex16() const {
1521 if (Kind != k_VectorIndex) return false;
1522 return VectorIndex.Val < 4;
1524 bool isVectorIndex32() const {
1525 if (Kind != k_VectorIndex) return false;
1526 return VectorIndex.Val < 2;
1529 bool isNEONi8splat() const {
1530 if (!isImm()) return false;
1531 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1532 // Must be a constant.
1533 if (!CE) return false;
1534 int64_t Value = CE->getValue();
1535 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1537 return Value >= 0 && Value < 256;
1540 bool isNEONi16splat() const {
1541 if (!isImm()) return false;
1542 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1543 // Must be a constant.
1544 if (!CE) return false;
1545 int64_t Value = CE->getValue();
1546 // i16 value in the range [0,255] or [0x0100, 0xff00]
1547 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1550 bool isNEONi32splat() const {
1551 if (!isImm()) return false;
1552 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1553 // Must be a constant.
1554 if (!CE) return false;
1555 int64_t Value = CE->getValue();
1556 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1557 return (Value >= 0 && Value < 256) ||
1558 (Value >= 0x0100 && Value <= 0xff00) ||
1559 (Value >= 0x010000 && Value <= 0xff0000) ||
1560 (Value >= 0x01000000 && Value <= 0xff000000);
1563 bool isNEONi32vmov() const {
1564 if (!isImm()) return false;
1565 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1566 // Must be a constant.
1567 if (!CE) return false;
1568 int64_t Value = CE->getValue();
1569 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1570 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1571 return (Value >= 0 && Value < 256) ||
1572 (Value >= 0x0100 && Value <= 0xff00) ||
1573 (Value >= 0x010000 && Value <= 0xff0000) ||
1574 (Value >= 0x01000000 && Value <= 0xff000000) ||
1575 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1576 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1578 bool isNEONi32vmovNeg() const {
1579 if (!isImm()) return false;
1580 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1581 // Must be a constant.
1582 if (!CE) return false;
1583 int64_t Value = ~CE->getValue();
1584 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1585 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1586 return (Value >= 0 && Value < 256) ||
1587 (Value >= 0x0100 && Value <= 0xff00) ||
1588 (Value >= 0x010000 && Value <= 0xff0000) ||
1589 (Value >= 0x01000000 && Value <= 0xff000000) ||
1590 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1591 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1594 bool isNEONi64splat() const {
1595 if (!isImm()) return false;
1596 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1597 // Must be a constant.
1598 if (!CE) return false;
1599 uint64_t Value = CE->getValue();
1600 // i64 value with each byte being either 0 or 0xff.
1601 for (unsigned i = 0; i < 8; ++i)
1602 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1606 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1607 // Add as immediates when possible. Null MCExpr = 0.
1609 Inst.addOperand(MCOperand::CreateImm(0));
1610 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1611 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1613 Inst.addOperand(MCOperand::CreateExpr(Expr));
1616 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1617 assert(N == 2 && "Invalid number of operands!");
1618 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1619 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1620 Inst.addOperand(MCOperand::CreateReg(RegNum));
1623 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1624 assert(N == 1 && "Invalid number of operands!");
1625 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1628 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1629 assert(N == 1 && "Invalid number of operands!");
1630 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1633 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1634 assert(N == 1 && "Invalid number of operands!");
1635 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1638 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1639 assert(N == 1 && "Invalid number of operands!");
1640 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1643 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1644 assert(N == 1 && "Invalid number of operands!");
1645 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1648 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1649 assert(N == 1 && "Invalid number of operands!");
1650 Inst.addOperand(MCOperand::CreateReg(getReg()));
1653 void addRegOperands(MCInst &Inst, unsigned N) const {
1654 assert(N == 1 && "Invalid number of operands!");
1655 Inst.addOperand(MCOperand::CreateReg(getReg()));
1658 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1659 assert(N == 3 && "Invalid number of operands!");
1660 assert(isRegShiftedReg() &&
1661 "addRegShiftedRegOperands() on non-RegShiftedReg!");
1662 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1663 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1664 Inst.addOperand(MCOperand::CreateImm(
1665 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1668 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1669 assert(N == 2 && "Invalid number of operands!");
1670 assert(isRegShiftedImm() &&
1671 "addRegShiftedImmOperands() on non-RegShiftedImm!");
1672 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1673 // Shift of #32 is encoded as 0 where permitted
1674 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1675 Inst.addOperand(MCOperand::CreateImm(
1676 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1679 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1680 assert(N == 1 && "Invalid number of operands!");
1681 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1685 void addRegListOperands(MCInst &Inst, unsigned N) const {
1686 assert(N == 1 && "Invalid number of operands!");
1687 const SmallVectorImpl<unsigned> &RegList = getRegList();
1688 for (SmallVectorImpl<unsigned>::const_iterator
1689 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1690 Inst.addOperand(MCOperand::CreateReg(*I));
1693 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1694 addRegListOperands(Inst, N);
1697 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1698 addRegListOperands(Inst, N);
1701 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1702 assert(N == 1 && "Invalid number of operands!");
1703 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1704 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1707 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1708 assert(N == 1 && "Invalid number of operands!");
1709 // Munge the lsb/width into a bitfield mask.
1710 unsigned lsb = Bitfield.LSB;
1711 unsigned width = Bitfield.Width;
1712 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1713 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1714 (32 - (lsb + width)));
1715 Inst.addOperand(MCOperand::CreateImm(Mask));
1718 void addImmOperands(MCInst &Inst, unsigned N) const {
1719 assert(N == 1 && "Invalid number of operands!");
1720 addExpr(Inst, getImm());
1723 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1724 assert(N == 1 && "Invalid number of operands!");
1725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1726 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1729 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1730 assert(N == 1 && "Invalid number of operands!");
1731 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1732 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1735 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1736 assert(N == 1 && "Invalid number of operands!");
1737 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1738 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1739 Inst.addOperand(MCOperand::CreateImm(Val));
1742 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1743 assert(N == 1 && "Invalid number of operands!");
1744 // FIXME: We really want to scale the value here, but the LDRD/STRD
1745 // instruction don't encode operands that way yet.
1746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1747 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1750 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1751 assert(N == 1 && "Invalid number of operands!");
1752 // The immediate is scaled by four in the encoding and is stored
1753 // in the MCInst as such. Lop off the low two bits here.
1754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1755 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1758 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1759 assert(N == 1 && "Invalid number of operands!");
1760 // The immediate is scaled by four in the encoding and is stored
1761 // in the MCInst as such. Lop off the low two bits here.
1762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1763 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1766 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1767 assert(N == 1 && "Invalid number of operands!");
1768 // The immediate is scaled by four in the encoding and is stored
1769 // in the MCInst as such. Lop off the low two bits here.
1770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1771 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1774 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1775 assert(N == 1 && "Invalid number of operands!");
1776 // The constant encodes as the immediate-1, and we store in the instruction
1777 // the bits as encoded, so subtract off one here.
1778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1779 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1782 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1783 assert(N == 1 && "Invalid number of operands!");
1784 // The constant encodes as the immediate-1, and we store in the instruction
1785 // the bits as encoded, so subtract off one here.
1786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1787 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1790 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1791 assert(N == 1 && "Invalid number of operands!");
1792 // The constant encodes as the immediate, except for 32, which encodes as
1794 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1795 unsigned Imm = CE->getValue();
1796 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1799 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1800 assert(N == 1 && "Invalid number of operands!");
1801 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1802 // the instruction as well.
1803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1804 int Val = CE->getValue();
1805 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1808 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1809 assert(N == 1 && "Invalid number of operands!");
1810 // The operand is actually a t2_so_imm, but we have its bitwise
1811 // negation in the assembly source, so twiddle it here.
1812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1813 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1816 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1817 assert(N == 1 && "Invalid number of operands!");
1818 // The operand is actually a t2_so_imm, but we have its
1819 // negation in the assembly source, so twiddle it here.
1820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1821 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1824 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1825 assert(N == 1 && "Invalid number of operands!");
1826 // The operand is actually an imm0_4095, but we have its
1827 // negation in the assembly source, so twiddle it here.
1828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1829 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1832 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1833 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1834 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1838 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1839 assert(SR && "Unknown value type!");
1840 Inst.addOperand(MCOperand::CreateExpr(SR));
1843 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1844 assert(N == 1 && "Invalid number of operands!");
1846 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1848 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1852 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1853 assert(SR && "Unknown value type!");
1854 Inst.addOperand(MCOperand::CreateExpr(SR));
1858 assert(isMem() && "Unknown value type!");
1859 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1860 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1863 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1864 assert(N == 1 && "Invalid number of operands!");
1865 // The operand is actually a so_imm, but we have its bitwise
1866 // negation in the assembly source, so twiddle it here.
1867 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1868 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1871 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1872 assert(N == 1 && "Invalid number of operands!");
1873 // The operand is actually a so_imm, but we have its
1874 // negation in the assembly source, so twiddle it here.
1875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1876 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1879 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1880 assert(N == 1 && "Invalid number of operands!");
1881 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1884 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1885 assert(N == 1 && "Invalid number of operands!");
1886 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1889 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1890 assert(N == 1 && "Invalid number of operands!");
1891 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1894 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1895 assert(N == 1 && "Invalid number of operands!");
1896 int32_t Imm = Memory.OffsetImm->getValue();
1897 Inst.addOperand(MCOperand::CreateImm(Imm));
1900 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1901 assert(N == 1 && "Invalid number of operands!");
1902 assert(isImm() && "Not an immediate!");
1904 // If we have an immediate that's not a constant, treat it as a label
1905 // reference needing a fixup.
1906 if (!isa<MCConstantExpr>(getImm())) {
1907 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1911 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1912 int Val = CE->getValue();
1913 Inst.addOperand(MCOperand::CreateImm(Val));
1916 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1917 assert(N == 2 && "Invalid number of operands!");
1918 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1919 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1922 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1923 assert(N == 3 && "Invalid number of operands!");
1924 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1925 if (!Memory.OffsetRegNum) {
1926 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1927 // Special case for #-0
1928 if (Val == INT32_MIN) Val = 0;
1929 if (Val < 0) Val = -Val;
1930 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1932 // For register offset, we encode the shift type and negation flag
1934 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1935 Memory.ShiftImm, Memory.ShiftType);
1937 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1938 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1939 Inst.addOperand(MCOperand::CreateImm(Val));
1942 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1943 assert(N == 2 && "Invalid number of operands!");
1944 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1945 assert(CE && "non-constant AM2OffsetImm operand!");
1946 int32_t Val = CE->getValue();
1947 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1948 // Special case for #-0
1949 if (Val == INT32_MIN) Val = 0;
1950 if (Val < 0) Val = -Val;
1951 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1952 Inst.addOperand(MCOperand::CreateReg(0));
1953 Inst.addOperand(MCOperand::CreateImm(Val));
1956 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1957 assert(N == 3 && "Invalid number of operands!");
1958 // If we have an immediate that's not a constant, treat it as a label
1959 // reference needing a fixup. If it is a constant, it's something else
1960 // and we reject it.
1962 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1963 Inst.addOperand(MCOperand::CreateReg(0));
1964 Inst.addOperand(MCOperand::CreateImm(0));
1968 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1969 if (!Memory.OffsetRegNum) {
1970 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1971 // Special case for #-0
1972 if (Val == INT32_MIN) Val = 0;
1973 if (Val < 0) Val = -Val;
1974 Val = ARM_AM::getAM3Opc(AddSub, Val);
1976 // For register offset, we encode the shift type and negation flag
1978 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1980 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1981 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1982 Inst.addOperand(MCOperand::CreateImm(Val));
1985 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1986 assert(N == 2 && "Invalid number of operands!");
1987 if (Kind == k_PostIndexRegister) {
1989 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1990 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1991 Inst.addOperand(MCOperand::CreateImm(Val));
1996 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1997 int32_t Val = CE->getValue();
1998 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1999 // Special case for #-0
2000 if (Val == INT32_MIN) Val = 0;
2001 if (Val < 0) Val = -Val;
2002 Val = ARM_AM::getAM3Opc(AddSub, Val);
2003 Inst.addOperand(MCOperand::CreateReg(0));
2004 Inst.addOperand(MCOperand::CreateImm(Val));
2007 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2008 assert(N == 2 && "Invalid number of operands!");
2009 // If we have an immediate that's not a constant, treat it as a label
2010 // reference needing a fixup. If it is a constant, it's something else
2011 // and we reject it.
2013 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2014 Inst.addOperand(MCOperand::CreateImm(0));
2018 // The lower two bits are always zero and as such are not encoded.
2019 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2020 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2021 // Special case for #-0
2022 if (Val == INT32_MIN) Val = 0;
2023 if (Val < 0) Val = -Val;
2024 Val = ARM_AM::getAM5Opc(AddSub, Val);
2025 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2026 Inst.addOperand(MCOperand::CreateImm(Val));
2029 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2030 assert(N == 2 && "Invalid number of operands!");
2031 // If we have an immediate that's not a constant, treat it as a label
2032 // reference needing a fixup. If it is a constant, it's something else
2033 // and we reject it.
2035 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2036 Inst.addOperand(MCOperand::CreateImm(0));
2040 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2041 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2042 Inst.addOperand(MCOperand::CreateImm(Val));
2045 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2046 assert(N == 2 && "Invalid number of operands!");
2047 // The lower two bits are always zero and as such are not encoded.
2048 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2049 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2050 Inst.addOperand(MCOperand::CreateImm(Val));
2053 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2054 assert(N == 2 && "Invalid number of operands!");
2055 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2056 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2057 Inst.addOperand(MCOperand::CreateImm(Val));
2060 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2061 addMemImm8OffsetOperands(Inst, N);
2064 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2065 addMemImm8OffsetOperands(Inst, N);
2068 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2069 assert(N == 2 && "Invalid number of operands!");
2070 // If this is an immediate, it's a label reference.
2072 addExpr(Inst, getImm());
2073 Inst.addOperand(MCOperand::CreateImm(0));
2077 // Otherwise, it's a normal memory reg+offset.
2078 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2079 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2080 Inst.addOperand(MCOperand::CreateImm(Val));
2083 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2084 assert(N == 2 && "Invalid number of operands!");
2085 // If this is an immediate, it's a label reference.
2087 addExpr(Inst, getImm());
2088 Inst.addOperand(MCOperand::CreateImm(0));
2092 // Otherwise, it's a normal memory reg+offset.
2093 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2094 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2095 Inst.addOperand(MCOperand::CreateImm(Val));
2098 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2099 assert(N == 2 && "Invalid number of operands!");
2100 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2101 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2104 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2105 assert(N == 2 && "Invalid number of operands!");
2106 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2107 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2110 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2111 assert(N == 3 && "Invalid number of operands!");
2113 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2114 Memory.ShiftImm, Memory.ShiftType);
2115 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2116 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2117 Inst.addOperand(MCOperand::CreateImm(Val));
2120 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2121 assert(N == 3 && "Invalid number of operands!");
2122 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2123 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2124 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2127 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2128 assert(N == 2 && "Invalid number of operands!");
2129 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2130 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2133 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2134 assert(N == 2 && "Invalid number of operands!");
2135 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2136 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2137 Inst.addOperand(MCOperand::CreateImm(Val));
2140 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2141 assert(N == 2 && "Invalid number of operands!");
2142 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2143 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2144 Inst.addOperand(MCOperand::CreateImm(Val));
2147 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2148 assert(N == 2 && "Invalid number of operands!");
2149 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2150 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2151 Inst.addOperand(MCOperand::CreateImm(Val));
2154 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2155 assert(N == 2 && "Invalid number of operands!");
2156 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2157 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2158 Inst.addOperand(MCOperand::CreateImm(Val));
2161 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2162 assert(N == 1 && "Invalid number of operands!");
2163 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2164 assert(CE && "non-constant post-idx-imm8 operand!");
2165 int Imm = CE->getValue();
2166 bool isAdd = Imm >= 0;
2167 if (Imm == INT32_MIN) Imm = 0;
2168 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2169 Inst.addOperand(MCOperand::CreateImm(Imm));
2172 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2173 assert(N == 1 && "Invalid number of operands!");
2174 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2175 assert(CE && "non-constant post-idx-imm8s4 operand!");
2176 int Imm = CE->getValue();
2177 bool isAdd = Imm >= 0;
2178 if (Imm == INT32_MIN) Imm = 0;
2179 // Immediate is scaled by 4.
2180 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2181 Inst.addOperand(MCOperand::CreateImm(Imm));
2184 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2185 assert(N == 2 && "Invalid number of operands!");
2186 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2187 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2190 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2191 assert(N == 2 && "Invalid number of operands!");
2192 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2193 // The sign, shift type, and shift amount are encoded in a single operand
2194 // using the AM2 encoding helpers.
2195 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2196 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2197 PostIdxReg.ShiftTy);
2198 Inst.addOperand(MCOperand::CreateImm(Imm));
2201 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2202 assert(N == 1 && "Invalid number of operands!");
2203 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2206 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2207 assert(N == 1 && "Invalid number of operands!");
2208 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2211 void addVecListOperands(MCInst &Inst, unsigned N) const {
2212 assert(N == 1 && "Invalid number of operands!");
2213 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2216 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2217 assert(N == 2 && "Invalid number of operands!");
2218 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2219 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2222 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2223 assert(N == 1 && "Invalid number of operands!");
2224 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2227 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2228 assert(N == 1 && "Invalid number of operands!");
2229 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2232 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2233 assert(N == 1 && "Invalid number of operands!");
2234 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2237 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2238 assert(N == 1 && "Invalid number of operands!");
2239 // The immediate encodes the type of constant as well as the value.
2240 // Mask in that this is an i8 splat.
2241 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2242 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2245 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2246 assert(N == 1 && "Invalid number of operands!");
2247 // The immediate encodes the type of constant as well as the value.
2248 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2249 unsigned Value = CE->getValue();
2251 Value = (Value >> 8) | 0xa00;
2254 Inst.addOperand(MCOperand::CreateImm(Value));
2257 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2258 assert(N == 1 && "Invalid number of operands!");
2259 // The immediate encodes the type of constant as well as the value.
2260 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2261 unsigned Value = CE->getValue();
2262 if (Value >= 256 && Value <= 0xff00)
2263 Value = (Value >> 8) | 0x200;
2264 else if (Value > 0xffff && Value <= 0xff0000)
2265 Value = (Value >> 16) | 0x400;
2266 else if (Value > 0xffffff)
2267 Value = (Value >> 24) | 0x600;
2268 Inst.addOperand(MCOperand::CreateImm(Value));
2271 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2272 assert(N == 1 && "Invalid number of operands!");
2273 // The immediate encodes the type of constant as well as the value.
2274 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2275 unsigned Value = CE->getValue();
2276 if (Value >= 256 && Value <= 0xffff)
2277 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2278 else if (Value > 0xffff && Value <= 0xffffff)
2279 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2280 else if (Value > 0xffffff)
2281 Value = (Value >> 24) | 0x600;
2282 Inst.addOperand(MCOperand::CreateImm(Value));
2285 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2286 assert(N == 1 && "Invalid number of operands!");
2287 // The immediate encodes the type of constant as well as the value.
2288 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2289 unsigned Value = ~CE->getValue();
2290 if (Value >= 256 && Value <= 0xffff)
2291 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2292 else if (Value > 0xffff && Value <= 0xffffff)
2293 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2294 else if (Value > 0xffffff)
2295 Value = (Value >> 24) | 0x600;
2296 Inst.addOperand(MCOperand::CreateImm(Value));
2299 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2300 assert(N == 1 && "Invalid number of operands!");
2301 // The immediate encodes the type of constant as well as the value.
2302 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2303 uint64_t Value = CE->getValue();
2305 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2306 Imm |= (Value & 1) << i;
2308 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2311 virtual void print(raw_ostream &OS) const;
2313 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2314 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2315 Op->ITMask.Mask = Mask;
2321 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2322 ARMOperand *Op = new ARMOperand(k_CondCode);
2329 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2330 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2331 Op->Cop.Val = CopVal;
2337 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2338 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2339 Op->Cop.Val = CopVal;
2345 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2346 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2353 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2354 ARMOperand *Op = new ARMOperand(k_CCOut);
2355 Op->Reg.RegNum = RegNum;
2361 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2362 ARMOperand *Op = new ARMOperand(k_Token);
2363 Op->Tok.Data = Str.data();
2364 Op->Tok.Length = Str.size();
2370 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2371 ARMOperand *Op = new ARMOperand(k_Register);
2372 Op->Reg.RegNum = RegNum;
2378 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2383 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2384 Op->RegShiftedReg.ShiftTy = ShTy;
2385 Op->RegShiftedReg.SrcReg = SrcReg;
2386 Op->RegShiftedReg.ShiftReg = ShiftReg;
2387 Op->RegShiftedReg.ShiftImm = ShiftImm;
2393 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2397 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2398 Op->RegShiftedImm.ShiftTy = ShTy;
2399 Op->RegShiftedImm.SrcReg = SrcReg;
2400 Op->RegShiftedImm.ShiftImm = ShiftImm;
2406 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2408 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2409 Op->ShifterImm.isASR = isASR;
2410 Op->ShifterImm.Imm = Imm;
2416 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2417 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2418 Op->RotImm.Imm = Imm;
2424 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2426 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2427 Op->Bitfield.LSB = LSB;
2428 Op->Bitfield.Width = Width;
2435 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2436 SMLoc StartLoc, SMLoc EndLoc) {
2437 assert (Regs.size() > 0 && "RegList contains no registers?");
2438 KindTy Kind = k_RegisterList;
2440 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2441 Kind = k_DPRRegisterList;
2442 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2443 contains(Regs.front().second))
2444 Kind = k_SPRRegisterList;
2446 // Sort based on the register encoding values.
2447 array_pod_sort(Regs.begin(), Regs.end());
2449 ARMOperand *Op = new ARMOperand(Kind);
2450 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2451 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2452 Op->Registers.push_back(I->second);
2453 Op->StartLoc = StartLoc;
2454 Op->EndLoc = EndLoc;
2458 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2459 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2460 ARMOperand *Op = new ARMOperand(k_VectorList);
2461 Op->VectorList.RegNum = RegNum;
2462 Op->VectorList.Count = Count;
2463 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2469 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2470 bool isDoubleSpaced,
2472 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2473 Op->VectorList.RegNum = RegNum;
2474 Op->VectorList.Count = Count;
2475 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2481 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2483 bool isDoubleSpaced,
2485 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2486 Op->VectorList.RegNum = RegNum;
2487 Op->VectorList.Count = Count;
2488 Op->VectorList.LaneIndex = Index;
2489 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2495 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2497 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2498 Op->VectorIndex.Val = Idx;
2504 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2505 ARMOperand *Op = new ARMOperand(k_Immediate);
2512 static ARMOperand *CreateMem(unsigned BaseRegNum,
2513 const MCConstantExpr *OffsetImm,
2514 unsigned OffsetRegNum,
2515 ARM_AM::ShiftOpc ShiftType,
2520 ARMOperand *Op = new ARMOperand(k_Memory);
2521 Op->Memory.BaseRegNum = BaseRegNum;
2522 Op->Memory.OffsetImm = OffsetImm;
2523 Op->Memory.OffsetRegNum = OffsetRegNum;
2524 Op->Memory.ShiftType = ShiftType;
2525 Op->Memory.ShiftImm = ShiftImm;
2526 Op->Memory.Alignment = Alignment;
2527 Op->Memory.isNegative = isNegative;
2533 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2534 ARM_AM::ShiftOpc ShiftTy,
2537 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2538 Op->PostIdxReg.RegNum = RegNum;
2539 Op->PostIdxReg.isAdd = isAdd;
2540 Op->PostIdxReg.ShiftTy = ShiftTy;
2541 Op->PostIdxReg.ShiftImm = ShiftImm;
2547 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2548 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2549 Op->MBOpt.Val = Opt;
2555 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2557 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2558 Op->ISBOpt.Val = Opt;
2564 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2565 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2566 Op->IFlags.Val = IFlags;
2572 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2573 ARMOperand *Op = new ARMOperand(k_MSRMask);
2574 Op->MMask.Val = MMask;
2581 } // end anonymous namespace.
2583 void ARMOperand::print(raw_ostream &OS) const {
2586 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2589 OS << "<ccout " << getReg() << ">";
2591 case k_ITCondMask: {
2592 static const char *const MaskStr[] = {
2593 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2594 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2596 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2597 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2601 OS << "<coprocessor number: " << getCoproc() << ">";
2604 OS << "<coprocessor register: " << getCoproc() << ">";
2606 case k_CoprocOption:
2607 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2610 OS << "<mask: " << getMSRMask() << ">";
2613 getImm()->print(OS);
2615 case k_MemBarrierOpt:
2616 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2618 case k_InstSyncBarrierOpt:
2619 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2623 << " base:" << Memory.BaseRegNum;
2626 case k_PostIndexRegister:
2627 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2628 << PostIdxReg.RegNum;
2629 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2630 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2631 << PostIdxReg.ShiftImm;
2634 case k_ProcIFlags: {
2635 OS << "<ARM_PROC::";
2636 unsigned IFlags = getProcIFlags();
2637 for (int i=2; i >= 0; --i)
2638 if (IFlags & (1 << i))
2639 OS << ARM_PROC::IFlagsToString(1 << i);
2644 OS << "<register " << getReg() << ">";
2646 case k_ShifterImmediate:
2647 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2648 << " #" << ShifterImm.Imm << ">";
2650 case k_ShiftedRegister:
2651 OS << "<so_reg_reg "
2652 << RegShiftedReg.SrcReg << " "
2653 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2654 << " " << RegShiftedReg.ShiftReg << ">";
2656 case k_ShiftedImmediate:
2657 OS << "<so_reg_imm "
2658 << RegShiftedImm.SrcReg << " "
2659 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2660 << " #" << RegShiftedImm.ShiftImm << ">";
2662 case k_RotateImmediate:
2663 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2665 case k_BitfieldDescriptor:
2666 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2667 << ", width: " << Bitfield.Width << ">";
2669 case k_RegisterList:
2670 case k_DPRRegisterList:
2671 case k_SPRRegisterList: {
2672 OS << "<register_list ";
2674 const SmallVectorImpl<unsigned> &RegList = getRegList();
2675 for (SmallVectorImpl<unsigned>::const_iterator
2676 I = RegList.begin(), E = RegList.end(); I != E; ) {
2678 if (++I < E) OS << ", ";
2685 OS << "<vector_list " << VectorList.Count << " * "
2686 << VectorList.RegNum << ">";
2688 case k_VectorListAllLanes:
2689 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2690 << VectorList.RegNum << ">";
2692 case k_VectorListIndexed:
2693 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2694 << VectorList.Count << " * " << VectorList.RegNum << ">";
2697 OS << "'" << getToken() << "'";
2700 OS << "<vectorindex " << getVectorIndex() << ">";
2705 /// @name Auto-generated Match Functions
2708 static unsigned MatchRegisterName(StringRef Name);
2712 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2713 SMLoc &StartLoc, SMLoc &EndLoc) {
2714 StartLoc = Parser.getTok().getLoc();
2715 EndLoc = Parser.getTok().getEndLoc();
2716 RegNo = tryParseRegister();
2718 return (RegNo == (unsigned)-1);
2721 /// Try to parse a register name. The token must be an Identifier when called,
2722 /// and if it is a register name the token is eaten and the register number is
2723 /// returned. Otherwise return -1.
2725 int ARMAsmParser::tryParseRegister() {
2726 const AsmToken &Tok = Parser.getTok();
2727 if (Tok.isNot(AsmToken::Identifier)) return -1;
2729 std::string lowerCase = Tok.getString().lower();
2730 unsigned RegNum = MatchRegisterName(lowerCase);
2732 RegNum = StringSwitch<unsigned>(lowerCase)
2733 .Case("r13", ARM::SP)
2734 .Case("r14", ARM::LR)
2735 .Case("r15", ARM::PC)
2736 .Case("ip", ARM::R12)
2737 // Additional register name aliases for 'gas' compatibility.
2738 .Case("a1", ARM::R0)
2739 .Case("a2", ARM::R1)
2740 .Case("a3", ARM::R2)
2741 .Case("a4", ARM::R3)
2742 .Case("v1", ARM::R4)
2743 .Case("v2", ARM::R5)
2744 .Case("v3", ARM::R6)
2745 .Case("v4", ARM::R7)
2746 .Case("v5", ARM::R8)
2747 .Case("v6", ARM::R9)
2748 .Case("v7", ARM::R10)
2749 .Case("v8", ARM::R11)
2750 .Case("sb", ARM::R9)
2751 .Case("sl", ARM::R10)
2752 .Case("fp", ARM::R11)
2756 // Check for aliases registered via .req. Canonicalize to lower case.
2757 // That's more consistent since register names are case insensitive, and
2758 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2759 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2760 // If no match, return failure.
2761 if (Entry == RegisterReqs.end())
2763 Parser.Lex(); // Eat identifier token.
2764 return Entry->getValue();
2767 Parser.Lex(); // Eat identifier token.
2772 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2773 // If a recoverable error occurs, return 1. If an irrecoverable error
2774 // occurs, return -1. An irrecoverable error is one where tokens have been
2775 // consumed in the process of trying to parse the shifter (i.e., when it is
2776 // indeed a shifter operand, but malformed).
2777 int ARMAsmParser::tryParseShiftRegister(
2778 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2779 SMLoc S = Parser.getTok().getLoc();
2780 const AsmToken &Tok = Parser.getTok();
2781 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2783 std::string lowerCase = Tok.getString().lower();
2784 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2785 .Case("asl", ARM_AM::lsl)
2786 .Case("lsl", ARM_AM::lsl)
2787 .Case("lsr", ARM_AM::lsr)
2788 .Case("asr", ARM_AM::asr)
2789 .Case("ror", ARM_AM::ror)
2790 .Case("rrx", ARM_AM::rrx)
2791 .Default(ARM_AM::no_shift);
2793 if (ShiftTy == ARM_AM::no_shift)
2796 Parser.Lex(); // Eat the operator.
2798 // The source register for the shift has already been added to the
2799 // operand list, so we need to pop it off and combine it into the shifted
2800 // register operand instead.
2801 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2802 if (!PrevOp->isReg())
2803 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2804 int SrcReg = PrevOp->getReg();
2809 if (ShiftTy == ARM_AM::rrx) {
2810 // RRX Doesn't have an explicit shift amount. The encoder expects
2811 // the shift register to be the same as the source register. Seems odd,
2815 // Figure out if this is shifted by a constant or a register (for non-RRX).
2816 if (Parser.getTok().is(AsmToken::Hash) ||
2817 Parser.getTok().is(AsmToken::Dollar)) {
2818 Parser.Lex(); // Eat hash.
2819 SMLoc ImmLoc = Parser.getTok().getLoc();
2820 const MCExpr *ShiftExpr = 0;
2821 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2822 Error(ImmLoc, "invalid immediate shift value");
2825 // The expression must be evaluatable as an immediate.
2826 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2828 Error(ImmLoc, "invalid immediate shift value");
2831 // Range check the immediate.
2832 // lsl, ror: 0 <= imm <= 31
2833 // lsr, asr: 0 <= imm <= 32
2834 Imm = CE->getValue();
2836 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2837 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2838 Error(ImmLoc, "immediate shift value out of range");
2841 // shift by zero is a nop. Always send it through as lsl.
2842 // ('as' compatibility)
2844 ShiftTy = ARM_AM::lsl;
2845 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2846 SMLoc L = Parser.getTok().getLoc();
2847 EndLoc = Parser.getTok().getEndLoc();
2848 ShiftReg = tryParseRegister();
2849 if (ShiftReg == -1) {
2850 Error (L, "expected immediate or register in shift operand");
2854 Error (Parser.getTok().getLoc(),
2855 "expected immediate or register in shift operand");
2860 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2861 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2865 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2872 /// Try to parse a register name. The token must be an Identifier when called.
2873 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2874 /// if there is a "writeback". 'true' if it's not a register.
2876 /// TODO this is likely to change to allow different register types and or to
2877 /// parse for a specific register type.
2879 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2880 const AsmToken &RegTok = Parser.getTok();
2881 int RegNo = tryParseRegister();
2885 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2886 RegTok.getEndLoc()));
2888 const AsmToken &ExclaimTok = Parser.getTok();
2889 if (ExclaimTok.is(AsmToken::Exclaim)) {
2890 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2891 ExclaimTok.getLoc()));
2892 Parser.Lex(); // Eat exclaim token
2896 // Also check for an index operand. This is only legal for vector registers,
2897 // but that'll get caught OK in operand matching, so we don't need to
2898 // explicitly filter everything else out here.
2899 if (Parser.getTok().is(AsmToken::LBrac)) {
2900 SMLoc SIdx = Parser.getTok().getLoc();
2901 Parser.Lex(); // Eat left bracket token.
2903 const MCExpr *ImmVal;
2904 if (getParser().parseExpression(ImmVal))
2906 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2908 return TokError("immediate value expected for vector index");
2910 if (Parser.getTok().isNot(AsmToken::RBrac))
2911 return Error(Parser.getTok().getLoc(), "']' expected");
2913 SMLoc E = Parser.getTok().getEndLoc();
2914 Parser.Lex(); // Eat right bracket token.
2916 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2924 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2925 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2927 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2928 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2930 switch (Name.size()) {
2933 if (Name[0] != CoprocOp)
2949 if (Name[0] != CoprocOp || Name[1] != '1')
2953 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
2954 case '0': return CoprocOp == 'p'? -1: 10;
2955 case '1': return CoprocOp == 'p'? -1: 11;
2956 case '2': return 12;
2957 case '3': return 13;
2958 case '4': return 14;
2959 case '5': return 15;
2964 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2965 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2966 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2967 SMLoc S = Parser.getTok().getLoc();
2968 const AsmToken &Tok = Parser.getTok();
2969 if (!Tok.is(AsmToken::Identifier))
2970 return MatchOperand_NoMatch;
2971 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2972 .Case("eq", ARMCC::EQ)
2973 .Case("ne", ARMCC::NE)
2974 .Case("hs", ARMCC::HS)
2975 .Case("cs", ARMCC::HS)
2976 .Case("lo", ARMCC::LO)
2977 .Case("cc", ARMCC::LO)
2978 .Case("mi", ARMCC::MI)
2979 .Case("pl", ARMCC::PL)
2980 .Case("vs", ARMCC::VS)
2981 .Case("vc", ARMCC::VC)
2982 .Case("hi", ARMCC::HI)
2983 .Case("ls", ARMCC::LS)
2984 .Case("ge", ARMCC::GE)
2985 .Case("lt", ARMCC::LT)
2986 .Case("gt", ARMCC::GT)
2987 .Case("le", ARMCC::LE)
2988 .Case("al", ARMCC::AL)
2991 return MatchOperand_NoMatch;
2992 Parser.Lex(); // Eat the token.
2994 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2996 return MatchOperand_Success;
2999 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
3000 /// token must be an Identifier when called, and if it is a coprocessor
3001 /// number, the token is eaten and the operand is added to the operand list.
3002 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3003 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3004 SMLoc S = Parser.getTok().getLoc();
3005 const AsmToken &Tok = Parser.getTok();
3006 if (Tok.isNot(AsmToken::Identifier))
3007 return MatchOperand_NoMatch;
3009 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
3011 return MatchOperand_NoMatch;
3013 Parser.Lex(); // Eat identifier token.
3014 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
3015 return MatchOperand_Success;
3018 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
3019 /// token must be an Identifier when called, and if it is a coprocessor
3020 /// number, the token is eaten and the operand is added to the operand list.
3021 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3022 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3023 SMLoc S = Parser.getTok().getLoc();
3024 const AsmToken &Tok = Parser.getTok();
3025 if (Tok.isNot(AsmToken::Identifier))
3026 return MatchOperand_NoMatch;
3028 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3030 return MatchOperand_NoMatch;
3032 Parser.Lex(); // Eat identifier token.
3033 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
3034 return MatchOperand_Success;
3037 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3038 /// coproc_option : '{' imm0_255 '}'
3039 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3040 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3041 SMLoc S = Parser.getTok().getLoc();
3043 // If this isn't a '{', this isn't a coprocessor immediate operand.
3044 if (Parser.getTok().isNot(AsmToken::LCurly))
3045 return MatchOperand_NoMatch;
3046 Parser.Lex(); // Eat the '{'
3049 SMLoc Loc = Parser.getTok().getLoc();
3050 if (getParser().parseExpression(Expr)) {
3051 Error(Loc, "illegal expression");
3052 return MatchOperand_ParseFail;
3054 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3055 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3056 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3057 return MatchOperand_ParseFail;
3059 int Val = CE->getValue();
3061 // Check for and consume the closing '}'
3062 if (Parser.getTok().isNot(AsmToken::RCurly))
3063 return MatchOperand_ParseFail;
3064 SMLoc E = Parser.getTok().getEndLoc();
3065 Parser.Lex(); // Eat the '}'
3067 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3068 return MatchOperand_Success;
3071 // For register list parsing, we need to map from raw GPR register numbering
3072 // to the enumeration values. The enumeration values aren't sorted by
3073 // register number due to our using "sp", "lr" and "pc" as canonical names.
3074 static unsigned getNextRegister(unsigned Reg) {
3075 // If this is a GPR, we need to do it manually, otherwise we can rely
3076 // on the sort ordering of the enumeration since the other reg-classes
3078 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3081 default: llvm_unreachable("Invalid GPR number!");
3082 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3083 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3084 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3085 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3086 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3087 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3088 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3089 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3093 // Return the low-subreg of a given Q register.
3094 static unsigned getDRegFromQReg(unsigned QReg) {
3096 default: llvm_unreachable("expected a Q register!");
3097 case ARM::Q0: return ARM::D0;
3098 case ARM::Q1: return ARM::D2;
3099 case ARM::Q2: return ARM::D4;
3100 case ARM::Q3: return ARM::D6;
3101 case ARM::Q4: return ARM::D8;
3102 case ARM::Q5: return ARM::D10;
3103 case ARM::Q6: return ARM::D12;
3104 case ARM::Q7: return ARM::D14;
3105 case ARM::Q8: return ARM::D16;
3106 case ARM::Q9: return ARM::D18;
3107 case ARM::Q10: return ARM::D20;
3108 case ARM::Q11: return ARM::D22;
3109 case ARM::Q12: return ARM::D24;
3110 case ARM::Q13: return ARM::D26;
3111 case ARM::Q14: return ARM::D28;
3112 case ARM::Q15: return ARM::D30;
3116 /// Parse a register list.
3118 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3119 assert(Parser.getTok().is(AsmToken::LCurly) &&
3120 "Token is not a Left Curly Brace");
3121 SMLoc S = Parser.getTok().getLoc();
3122 Parser.Lex(); // Eat '{' token.
3123 SMLoc RegLoc = Parser.getTok().getLoc();
3125 // Check the first register in the list to see what register class
3126 // this is a list of.
3127 int Reg = tryParseRegister();
3129 return Error(RegLoc, "register expected");
3131 // The reglist instructions have at most 16 registers, so reserve
3132 // space for that many.
3134 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3136 // Allow Q regs and just interpret them as the two D sub-registers.
3137 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3138 Reg = getDRegFromQReg(Reg);
3139 EReg = MRI->getEncodingValue(Reg);
3140 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3143 const MCRegisterClass *RC;
3144 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3145 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3146 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3147 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3148 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3149 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3151 return Error(RegLoc, "invalid register in register list");
3153 // Store the register.
3154 EReg = MRI->getEncodingValue(Reg);
3155 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3157 // This starts immediately after the first register token in the list,
3158 // so we can see either a comma or a minus (range separator) as a legal
3160 while (Parser.getTok().is(AsmToken::Comma) ||
3161 Parser.getTok().is(AsmToken::Minus)) {
3162 if (Parser.getTok().is(AsmToken::Minus)) {
3163 Parser.Lex(); // Eat the minus.
3164 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3165 int EndReg = tryParseRegister();
3167 return Error(AfterMinusLoc, "register expected");
3168 // Allow Q regs and just interpret them as the two D sub-registers.
3169 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3170 EndReg = getDRegFromQReg(EndReg) + 1;
3171 // If the register is the same as the start reg, there's nothing
3175 // The register must be in the same register class as the first.
3176 if (!RC->contains(EndReg))
3177 return Error(AfterMinusLoc, "invalid register in register list");
3178 // Ranges must go from low to high.
3179 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3180 return Error(AfterMinusLoc, "bad range in register list");
3182 // Add all the registers in the range to the register list.
3183 while (Reg != EndReg) {
3184 Reg = getNextRegister(Reg);
3185 EReg = MRI->getEncodingValue(Reg);
3186 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3190 Parser.Lex(); // Eat the comma.
3191 RegLoc = Parser.getTok().getLoc();
3193 const AsmToken RegTok = Parser.getTok();
3194 Reg = tryParseRegister();
3196 return Error(RegLoc, "register expected");
3197 // Allow Q regs and just interpret them as the two D sub-registers.
3198 bool isQReg = false;
3199 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3200 Reg = getDRegFromQReg(Reg);
3203 // The register must be in the same register class as the first.
3204 if (!RC->contains(Reg))
3205 return Error(RegLoc, "invalid register in register list");
3206 // List must be monotonically increasing.
3207 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3208 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3209 Warning(RegLoc, "register list not in ascending order");
3211 return Error(RegLoc, "register list not in ascending order");
3213 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3214 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3215 ") in register list");
3218 // VFP register lists must also be contiguous.
3219 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3221 return Error(RegLoc, "non-contiguous register range");
3222 EReg = MRI->getEncodingValue(Reg);
3223 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3225 EReg = MRI->getEncodingValue(++Reg);
3226 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3230 if (Parser.getTok().isNot(AsmToken::RCurly))
3231 return Error(Parser.getTok().getLoc(), "'}' expected");
3232 SMLoc E = Parser.getTok().getEndLoc();
3233 Parser.Lex(); // Eat '}' token.
3235 // Push the register list operand.
3236 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3238 // The ARM system instruction variants for LDM/STM have a '^' token here.
3239 if (Parser.getTok().is(AsmToken::Caret)) {
3240 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3241 Parser.Lex(); // Eat '^' token.
3247 // Helper function to parse the lane index for vector lists.
3248 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3249 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3250 Index = 0; // Always return a defined index value.
3251 if (Parser.getTok().is(AsmToken::LBrac)) {
3252 Parser.Lex(); // Eat the '['.
3253 if (Parser.getTok().is(AsmToken::RBrac)) {
3254 // "Dn[]" is the 'all lanes' syntax.
3255 LaneKind = AllLanes;
3256 EndLoc = Parser.getTok().getEndLoc();
3257 Parser.Lex(); // Eat the ']'.
3258 return MatchOperand_Success;
3261 // There's an optional '#' token here. Normally there wouldn't be, but
3262 // inline assemble puts one in, and it's friendly to accept that.
3263 if (Parser.getTok().is(AsmToken::Hash))
3264 Parser.Lex(); // Eat '#' or '$'.
3266 const MCExpr *LaneIndex;
3267 SMLoc Loc = Parser.getTok().getLoc();
3268 if (getParser().parseExpression(LaneIndex)) {
3269 Error(Loc, "illegal expression");
3270 return MatchOperand_ParseFail;
3272 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3274 Error(Loc, "lane index must be empty or an integer");
3275 return MatchOperand_ParseFail;
3277 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3278 Error(Parser.getTok().getLoc(), "']' expected");
3279 return MatchOperand_ParseFail;
3281 EndLoc = Parser.getTok().getEndLoc();
3282 Parser.Lex(); // Eat the ']'.
3283 int64_t Val = CE->getValue();
3285 // FIXME: Make this range check context sensitive for .8, .16, .32.
3286 if (Val < 0 || Val > 7) {
3287 Error(Parser.getTok().getLoc(), "lane index out of range");
3288 return MatchOperand_ParseFail;
3291 LaneKind = IndexedLane;
3292 return MatchOperand_Success;
3295 return MatchOperand_Success;
3298 // parse a vector register list
3299 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3300 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3301 VectorLaneTy LaneKind;
3303 SMLoc S = Parser.getTok().getLoc();
3304 // As an extension (to match gas), support a plain D register or Q register
3305 // (without encosing curly braces) as a single or double entry list,
3307 if (Parser.getTok().is(AsmToken::Identifier)) {
3308 SMLoc E = Parser.getTok().getEndLoc();
3309 int Reg = tryParseRegister();
3311 return MatchOperand_NoMatch;
3312 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3313 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3314 if (Res != MatchOperand_Success)
3318 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3321 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3325 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3330 return MatchOperand_Success;
3332 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3333 Reg = getDRegFromQReg(Reg);
3334 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3335 if (Res != MatchOperand_Success)
3339 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3340 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3341 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3344 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3345 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3346 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3350 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3355 return MatchOperand_Success;
3357 Error(S, "vector register expected");
3358 return MatchOperand_ParseFail;
3361 if (Parser.getTok().isNot(AsmToken::LCurly))
3362 return MatchOperand_NoMatch;
3364 Parser.Lex(); // Eat '{' token.
3365 SMLoc RegLoc = Parser.getTok().getLoc();
3367 int Reg = tryParseRegister();
3369 Error(RegLoc, "register expected");
3370 return MatchOperand_ParseFail;
3374 unsigned FirstReg = Reg;
3375 // The list is of D registers, but we also allow Q regs and just interpret
3376 // them as the two D sub-registers.
3377 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3378 FirstReg = Reg = getDRegFromQReg(Reg);
3379 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3380 // it's ambiguous with four-register single spaced.
3386 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3387 return MatchOperand_ParseFail;
3389 while (Parser.getTok().is(AsmToken::Comma) ||
3390 Parser.getTok().is(AsmToken::Minus)) {
3391 if (Parser.getTok().is(AsmToken::Minus)) {
3393 Spacing = 1; // Register range implies a single spaced list.
3394 else if (Spacing == 2) {
3395 Error(Parser.getTok().getLoc(),
3396 "sequential registers in double spaced list");
3397 return MatchOperand_ParseFail;
3399 Parser.Lex(); // Eat the minus.
3400 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3401 int EndReg = tryParseRegister();
3403 Error(AfterMinusLoc, "register expected");
3404 return MatchOperand_ParseFail;
3406 // Allow Q regs and just interpret them as the two D sub-registers.
3407 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3408 EndReg = getDRegFromQReg(EndReg) + 1;
3409 // If the register is the same as the start reg, there's nothing
3413 // The register must be in the same register class as the first.
3414 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3415 Error(AfterMinusLoc, "invalid register in register list");
3416 return MatchOperand_ParseFail;
3418 // Ranges must go from low to high.
3420 Error(AfterMinusLoc, "bad range in register list");
3421 return MatchOperand_ParseFail;
3423 // Parse the lane specifier if present.
3424 VectorLaneTy NextLaneKind;
3425 unsigned NextLaneIndex;
3426 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3427 MatchOperand_Success)
3428 return MatchOperand_ParseFail;
3429 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3430 Error(AfterMinusLoc, "mismatched lane index in register list");
3431 return MatchOperand_ParseFail;
3434 // Add all the registers in the range to the register list.
3435 Count += EndReg - Reg;
3439 Parser.Lex(); // Eat the comma.
3440 RegLoc = Parser.getTok().getLoc();
3442 Reg = tryParseRegister();
3444 Error(RegLoc, "register expected");
3445 return MatchOperand_ParseFail;
3447 // vector register lists must be contiguous.
3448 // It's OK to use the enumeration values directly here rather, as the
3449 // VFP register classes have the enum sorted properly.
3451 // The list is of D registers, but we also allow Q regs and just interpret
3452 // them as the two D sub-registers.
3453 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3455 Spacing = 1; // Register range implies a single spaced list.
3456 else if (Spacing == 2) {
3458 "invalid register in double-spaced list (must be 'D' register')");
3459 return MatchOperand_ParseFail;
3461 Reg = getDRegFromQReg(Reg);
3462 if (Reg != OldReg + 1) {
3463 Error(RegLoc, "non-contiguous register range");
3464 return MatchOperand_ParseFail;
3468 // Parse the lane specifier if present.
3469 VectorLaneTy NextLaneKind;
3470 unsigned NextLaneIndex;
3471 SMLoc LaneLoc = Parser.getTok().getLoc();
3472 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3473 MatchOperand_Success)
3474 return MatchOperand_ParseFail;
3475 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3476 Error(LaneLoc, "mismatched lane index in register list");
3477 return MatchOperand_ParseFail;
3481 // Normal D register.
3482 // Figure out the register spacing (single or double) of the list if
3483 // we don't know it already.
3485 Spacing = 1 + (Reg == OldReg + 2);
3487 // Just check that it's contiguous and keep going.
3488 if (Reg != OldReg + Spacing) {
3489 Error(RegLoc, "non-contiguous register range");
3490 return MatchOperand_ParseFail;
3493 // Parse the lane specifier if present.
3494 VectorLaneTy NextLaneKind;
3495 unsigned NextLaneIndex;
3496 SMLoc EndLoc = Parser.getTok().getLoc();
3497 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3498 return MatchOperand_ParseFail;
3499 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3500 Error(EndLoc, "mismatched lane index in register list");
3501 return MatchOperand_ParseFail;
3505 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3506 Error(Parser.getTok().getLoc(), "'}' expected");
3507 return MatchOperand_ParseFail;
3509 E = Parser.getTok().getEndLoc();
3510 Parser.Lex(); // Eat '}' token.
3514 // Two-register operands have been converted to the
3515 // composite register classes.
3517 const MCRegisterClass *RC = (Spacing == 1) ?
3518 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3519 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3520 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3523 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3524 (Spacing == 2), S, E));
3527 // Two-register operands have been converted to the
3528 // composite register classes.
3530 const MCRegisterClass *RC = (Spacing == 1) ?
3531 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3532 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3533 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3535 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3540 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3546 return MatchOperand_Success;
3549 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3550 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3551 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3552 SMLoc S = Parser.getTok().getLoc();
3553 const AsmToken &Tok = Parser.getTok();
3556 if (Tok.is(AsmToken::Identifier)) {
3557 StringRef OptStr = Tok.getString();
3559 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3560 .Case("sy", ARM_MB::SY)
3561 .Case("st", ARM_MB::ST)
3562 .Case("ld", ARM_MB::LD)
3563 .Case("sh", ARM_MB::ISH)
3564 .Case("ish", ARM_MB::ISH)
3565 .Case("shst", ARM_MB::ISHST)
3566 .Case("ishst", ARM_MB::ISHST)
3567 .Case("ishld", ARM_MB::ISHLD)
3568 .Case("nsh", ARM_MB::NSH)
3569 .Case("un", ARM_MB::NSH)
3570 .Case("nshst", ARM_MB::NSHST)
3571 .Case("nshld", ARM_MB::NSHLD)
3572 .Case("unst", ARM_MB::NSHST)
3573 .Case("osh", ARM_MB::OSH)
3574 .Case("oshst", ARM_MB::OSHST)
3575 .Case("oshld", ARM_MB::OSHLD)
3578 // ishld, oshld, nshld and ld are only available from ARMv8.
3579 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3580 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3584 return MatchOperand_NoMatch;
3586 Parser.Lex(); // Eat identifier token.
3587 } else if (Tok.is(AsmToken::Hash) ||
3588 Tok.is(AsmToken::Dollar) ||
3589 Tok.is(AsmToken::Integer)) {
3590 if (Parser.getTok().isNot(AsmToken::Integer))
3591 Parser.Lex(); // Eat '#' or '$'.
3592 SMLoc Loc = Parser.getTok().getLoc();
3594 const MCExpr *MemBarrierID;
3595 if (getParser().parseExpression(MemBarrierID)) {
3596 Error(Loc, "illegal expression");
3597 return MatchOperand_ParseFail;
3600 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3602 Error(Loc, "constant expression expected");
3603 return MatchOperand_ParseFail;
3606 int Val = CE->getValue();
3608 Error(Loc, "immediate value out of range");
3609 return MatchOperand_ParseFail;
3612 Opt = ARM_MB::RESERVED_0 + Val;
3614 return MatchOperand_ParseFail;
3616 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3617 return MatchOperand_Success;
3620 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3621 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3622 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3623 SMLoc S = Parser.getTok().getLoc();
3624 const AsmToken &Tok = Parser.getTok();
3627 if (Tok.is(AsmToken::Identifier)) {
3628 StringRef OptStr = Tok.getString();
3630 if (OptStr.equals_lower("sy"))
3633 return MatchOperand_NoMatch;
3635 Parser.Lex(); // Eat identifier token.
3636 } else if (Tok.is(AsmToken::Hash) ||
3637 Tok.is(AsmToken::Dollar) ||
3638 Tok.is(AsmToken::Integer)) {
3639 if (Parser.getTok().isNot(AsmToken::Integer))
3640 Parser.Lex(); // Eat '#' or '$'.
3641 SMLoc Loc = Parser.getTok().getLoc();
3643 const MCExpr *ISBarrierID;
3644 if (getParser().parseExpression(ISBarrierID)) {
3645 Error(Loc, "illegal expression");
3646 return MatchOperand_ParseFail;
3649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3651 Error(Loc, "constant expression expected");
3652 return MatchOperand_ParseFail;
3655 int Val = CE->getValue();
3657 Error(Loc, "immediate value out of range");
3658 return MatchOperand_ParseFail;
3661 Opt = ARM_ISB::RESERVED_0 + Val;
3663 return MatchOperand_ParseFail;
3665 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3666 (ARM_ISB::InstSyncBOpt)Opt, S));
3667 return MatchOperand_Success;
3671 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3672 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3673 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3674 SMLoc S = Parser.getTok().getLoc();
3675 const AsmToken &Tok = Parser.getTok();
3676 if (!Tok.is(AsmToken::Identifier))
3677 return MatchOperand_NoMatch;
3678 StringRef IFlagsStr = Tok.getString();
3680 // An iflags string of "none" is interpreted to mean that none of the AIF
3681 // bits are set. Not a terribly useful instruction, but a valid encoding.
3682 unsigned IFlags = 0;
3683 if (IFlagsStr != "none") {
3684 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3685 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3686 .Case("a", ARM_PROC::A)
3687 .Case("i", ARM_PROC::I)
3688 .Case("f", ARM_PROC::F)
3691 // If some specific iflag is already set, it means that some letter is
3692 // present more than once, this is not acceptable.
3693 if (Flag == ~0U || (IFlags & Flag))
3694 return MatchOperand_NoMatch;
3700 Parser.Lex(); // Eat identifier token.
3701 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3702 return MatchOperand_Success;
3705 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3706 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3707 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3708 SMLoc S = Parser.getTok().getLoc();
3709 const AsmToken &Tok = Parser.getTok();
3710 if (!Tok.is(AsmToken::Identifier))
3711 return MatchOperand_NoMatch;
3712 StringRef Mask = Tok.getString();
3715 // See ARMv6-M 10.1.1
3716 std::string Name = Mask.lower();
3717 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3718 // Note: in the documentation:
3719 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3720 // for MSR APSR_nzcvq.
3721 // but we do make it an alias here. This is so to get the "mask encoding"
3722 // bits correct on MSR APSR writes.
3724 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3725 // should really only be allowed when writing a special register. Note
3726 // they get dropped in the MRS instruction reading a special register as
3727 // the SYSm field is only 8 bits.
3729 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3730 // includes the DSP extension but that is not checked.
3731 .Case("apsr", 0x800)
3732 .Case("apsr_nzcvq", 0x800)
3733 .Case("apsr_g", 0x400)
3734 .Case("apsr_nzcvqg", 0xc00)
3735 .Case("iapsr", 0x801)
3736 .Case("iapsr_nzcvq", 0x801)
3737 .Case("iapsr_g", 0x401)
3738 .Case("iapsr_nzcvqg", 0xc01)
3739 .Case("eapsr", 0x802)
3740 .Case("eapsr_nzcvq", 0x802)
3741 .Case("eapsr_g", 0x402)
3742 .Case("eapsr_nzcvqg", 0xc02)
3743 .Case("xpsr", 0x803)
3744 .Case("xpsr_nzcvq", 0x803)
3745 .Case("xpsr_g", 0x403)
3746 .Case("xpsr_nzcvqg", 0xc03)
3747 .Case("ipsr", 0x805)
3748 .Case("epsr", 0x806)
3749 .Case("iepsr", 0x807)
3752 .Case("primask", 0x810)
3753 .Case("basepri", 0x811)
3754 .Case("basepri_max", 0x812)
3755 .Case("faultmask", 0x813)
3756 .Case("control", 0x814)
3759 if (FlagsVal == ~0U)
3760 return MatchOperand_NoMatch;
3762 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3763 // basepri, basepri_max and faultmask only valid for V7m.
3764 return MatchOperand_NoMatch;
3766 Parser.Lex(); // Eat identifier token.
3767 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3768 return MatchOperand_Success;
3771 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3772 size_t Start = 0, Next = Mask.find('_');
3773 StringRef Flags = "";
3774 std::string SpecReg = Mask.slice(Start, Next).lower();
3775 if (Next != StringRef::npos)
3776 Flags = Mask.slice(Next+1, Mask.size());
3778 // FlagsVal contains the complete mask:
3780 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3781 unsigned FlagsVal = 0;
3783 if (SpecReg == "apsr") {
3784 FlagsVal = StringSwitch<unsigned>(Flags)
3785 .Case("nzcvq", 0x8) // same as CPSR_f
3786 .Case("g", 0x4) // same as CPSR_s
3787 .Case("nzcvqg", 0xc) // same as CPSR_fs
3790 if (FlagsVal == ~0U) {
3792 return MatchOperand_NoMatch;
3794 FlagsVal = 8; // No flag
3796 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3797 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3798 if (Flags == "all" || Flags == "")
3800 for (int i = 0, e = Flags.size(); i != e; ++i) {
3801 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3808 // If some specific flag is already set, it means that some letter is
3809 // present more than once, this is not acceptable.
3810 if (FlagsVal == ~0U || (FlagsVal & Flag))
3811 return MatchOperand_NoMatch;
3814 } else // No match for special register.
3815 return MatchOperand_NoMatch;
3817 // Special register without flags is NOT equivalent to "fc" flags.
3818 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3819 // two lines would enable gas compatibility at the expense of breaking
3825 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3826 if (SpecReg == "spsr")
3829 Parser.Lex(); // Eat identifier token.
3830 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3831 return MatchOperand_Success;
3834 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3835 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3836 int Low, int High) {
3837 const AsmToken &Tok = Parser.getTok();
3838 if (Tok.isNot(AsmToken::Identifier)) {
3839 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3840 return MatchOperand_ParseFail;
3842 StringRef ShiftName = Tok.getString();
3843 std::string LowerOp = Op.lower();
3844 std::string UpperOp = Op.upper();
3845 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3846 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3847 return MatchOperand_ParseFail;
3849 Parser.Lex(); // Eat shift type token.
3851 // There must be a '#' and a shift amount.
3852 if (Parser.getTok().isNot(AsmToken::Hash) &&
3853 Parser.getTok().isNot(AsmToken::Dollar)) {
3854 Error(Parser.getTok().getLoc(), "'#' expected");
3855 return MatchOperand_ParseFail;
3857 Parser.Lex(); // Eat hash token.
3859 const MCExpr *ShiftAmount;
3860 SMLoc Loc = Parser.getTok().getLoc();
3862 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3863 Error(Loc, "illegal expression");
3864 return MatchOperand_ParseFail;
3866 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3868 Error(Loc, "constant expression expected");
3869 return MatchOperand_ParseFail;
3871 int Val = CE->getValue();
3872 if (Val < Low || Val > High) {
3873 Error(Loc, "immediate value out of range");
3874 return MatchOperand_ParseFail;
3877 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3879 return MatchOperand_Success;
3882 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3883 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3884 const AsmToken &Tok = Parser.getTok();
3885 SMLoc S = Tok.getLoc();
3886 if (Tok.isNot(AsmToken::Identifier)) {
3887 Error(S, "'be' or 'le' operand expected");
3888 return MatchOperand_ParseFail;
3890 int Val = StringSwitch<int>(Tok.getString().lower())
3894 Parser.Lex(); // Eat the token.
3897 Error(S, "'be' or 'le' operand expected");
3898 return MatchOperand_ParseFail;
3900 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3902 S, Tok.getEndLoc()));
3903 return MatchOperand_Success;
3906 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3907 /// instructions. Legal values are:
3908 /// lsl #n 'n' in [0,31]
3909 /// asr #n 'n' in [1,32]
3910 /// n == 32 encoded as n == 0.
3911 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3912 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3913 const AsmToken &Tok = Parser.getTok();
3914 SMLoc S = Tok.getLoc();
3915 if (Tok.isNot(AsmToken::Identifier)) {
3916 Error(S, "shift operator 'asr' or 'lsl' expected");
3917 return MatchOperand_ParseFail;
3919 StringRef ShiftName = Tok.getString();
3921 if (ShiftName == "lsl" || ShiftName == "LSL")
3923 else if (ShiftName == "asr" || ShiftName == "ASR")
3926 Error(S, "shift operator 'asr' or 'lsl' expected");
3927 return MatchOperand_ParseFail;
3929 Parser.Lex(); // Eat the operator.
3931 // A '#' and a shift amount.
3932 if (Parser.getTok().isNot(AsmToken::Hash) &&
3933 Parser.getTok().isNot(AsmToken::Dollar)) {
3934 Error(Parser.getTok().getLoc(), "'#' expected");
3935 return MatchOperand_ParseFail;
3937 Parser.Lex(); // Eat hash token.
3938 SMLoc ExLoc = Parser.getTok().getLoc();
3940 const MCExpr *ShiftAmount;
3942 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3943 Error(ExLoc, "malformed shift expression");
3944 return MatchOperand_ParseFail;
3946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3948 Error(ExLoc, "shift amount must be an immediate");
3949 return MatchOperand_ParseFail;
3952 int64_t Val = CE->getValue();
3954 // Shift amount must be in [1,32]
3955 if (Val < 1 || Val > 32) {
3956 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3957 return MatchOperand_ParseFail;
3959 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3960 if (isThumb() && Val == 32) {
3961 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3962 return MatchOperand_ParseFail;
3964 if (Val == 32) Val = 0;
3966 // Shift amount must be in [1,32]
3967 if (Val < 0 || Val > 31) {
3968 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3969 return MatchOperand_ParseFail;
3973 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3975 return MatchOperand_Success;
3978 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3979 /// of instructions. Legal values are:
3980 /// ror #n 'n' in {0, 8, 16, 24}
3981 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3982 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3983 const AsmToken &Tok = Parser.getTok();
3984 SMLoc S = Tok.getLoc();
3985 if (Tok.isNot(AsmToken::Identifier))
3986 return MatchOperand_NoMatch;
3987 StringRef ShiftName = Tok.getString();
3988 if (ShiftName != "ror" && ShiftName != "ROR")
3989 return MatchOperand_NoMatch;
3990 Parser.Lex(); // Eat the operator.
3992 // A '#' and a rotate amount.
3993 if (Parser.getTok().isNot(AsmToken::Hash) &&
3994 Parser.getTok().isNot(AsmToken::Dollar)) {
3995 Error(Parser.getTok().getLoc(), "'#' expected");
3996 return MatchOperand_ParseFail;
3998 Parser.Lex(); // Eat hash token.
3999 SMLoc ExLoc = Parser.getTok().getLoc();
4001 const MCExpr *ShiftAmount;
4003 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
4004 Error(ExLoc, "malformed rotate expression");
4005 return MatchOperand_ParseFail;
4007 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4009 Error(ExLoc, "rotate amount must be an immediate");
4010 return MatchOperand_ParseFail;
4013 int64_t Val = CE->getValue();
4014 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4015 // normally, zero is represented in asm by omitting the rotate operand
4017 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
4018 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
4019 return MatchOperand_ParseFail;
4022 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
4024 return MatchOperand_Success;
4027 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4028 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4029 SMLoc S = Parser.getTok().getLoc();
4030 // The bitfield descriptor is really two operands, the LSB and the width.
4031 if (Parser.getTok().isNot(AsmToken::Hash) &&
4032 Parser.getTok().isNot(AsmToken::Dollar)) {
4033 Error(Parser.getTok().getLoc(), "'#' expected");
4034 return MatchOperand_ParseFail;
4036 Parser.Lex(); // Eat hash token.
4038 const MCExpr *LSBExpr;
4039 SMLoc E = Parser.getTok().getLoc();
4040 if (getParser().parseExpression(LSBExpr)) {
4041 Error(E, "malformed immediate expression");
4042 return MatchOperand_ParseFail;
4044 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4046 Error(E, "'lsb' operand must be an immediate");
4047 return MatchOperand_ParseFail;
4050 int64_t LSB = CE->getValue();
4051 // The LSB must be in the range [0,31]
4052 if (LSB < 0 || LSB > 31) {
4053 Error(E, "'lsb' operand must be in the range [0,31]");
4054 return MatchOperand_ParseFail;
4056 E = Parser.getTok().getLoc();
4058 // Expect another immediate operand.
4059 if (Parser.getTok().isNot(AsmToken::Comma)) {
4060 Error(Parser.getTok().getLoc(), "too few operands");
4061 return MatchOperand_ParseFail;
4063 Parser.Lex(); // Eat hash token.
4064 if (Parser.getTok().isNot(AsmToken::Hash) &&
4065 Parser.getTok().isNot(AsmToken::Dollar)) {
4066 Error(Parser.getTok().getLoc(), "'#' expected");
4067 return MatchOperand_ParseFail;
4069 Parser.Lex(); // Eat hash token.
4071 const MCExpr *WidthExpr;
4073 if (getParser().parseExpression(WidthExpr, EndLoc)) {
4074 Error(E, "malformed immediate expression");
4075 return MatchOperand_ParseFail;
4077 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4079 Error(E, "'width' operand must be an immediate");
4080 return MatchOperand_ParseFail;
4083 int64_t Width = CE->getValue();
4084 // The LSB must be in the range [1,32-lsb]
4085 if (Width < 1 || Width > 32 - LSB) {
4086 Error(E, "'width' operand must be in the range [1,32-lsb]");
4087 return MatchOperand_ParseFail;
4090 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
4092 return MatchOperand_Success;
4095 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4096 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4097 // Check for a post-index addressing register operand. Specifically:
4098 // postidx_reg := '+' register {, shift}
4099 // | '-' register {, shift}
4100 // | register {, shift}
4102 // This method must return MatchOperand_NoMatch without consuming any tokens
4103 // in the case where there is no match, as other alternatives take other
4105 AsmToken Tok = Parser.getTok();
4106 SMLoc S = Tok.getLoc();
4107 bool haveEaten = false;
4109 if (Tok.is(AsmToken::Plus)) {
4110 Parser.Lex(); // Eat the '+' token.
4112 } else if (Tok.is(AsmToken::Minus)) {
4113 Parser.Lex(); // Eat the '-' token.
4118 SMLoc E = Parser.getTok().getEndLoc();
4119 int Reg = tryParseRegister();
4122 return MatchOperand_NoMatch;
4123 Error(Parser.getTok().getLoc(), "register expected");
4124 return MatchOperand_ParseFail;
4127 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4128 unsigned ShiftImm = 0;
4129 if (Parser.getTok().is(AsmToken::Comma)) {
4130 Parser.Lex(); // Eat the ','.
4131 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4132 return MatchOperand_ParseFail;
4134 // FIXME: Only approximates end...may include intervening whitespace.
4135 E = Parser.getTok().getLoc();
4138 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4141 return MatchOperand_Success;
4144 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4145 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4146 // Check for a post-index addressing register operand. Specifically:
4147 // am3offset := '+' register
4154 // This method must return MatchOperand_NoMatch without consuming any tokens
4155 // in the case where there is no match, as other alternatives take other
4157 AsmToken Tok = Parser.getTok();
4158 SMLoc S = Tok.getLoc();
4160 // Do immediates first, as we always parse those if we have a '#'.
4161 if (Parser.getTok().is(AsmToken::Hash) ||
4162 Parser.getTok().is(AsmToken::Dollar)) {
4163 Parser.Lex(); // Eat '#' or '$'.
4164 // Explicitly look for a '-', as we need to encode negative zero
4166 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4167 const MCExpr *Offset;
4169 if (getParser().parseExpression(Offset, E))
4170 return MatchOperand_ParseFail;
4171 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4173 Error(S, "constant expression expected");
4174 return MatchOperand_ParseFail;
4176 // Negative zero is encoded as the flag value INT32_MIN.
4177 int32_t Val = CE->getValue();
4178 if (isNegative && Val == 0)
4182 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4184 return MatchOperand_Success;
4188 bool haveEaten = false;
4190 if (Tok.is(AsmToken::Plus)) {
4191 Parser.Lex(); // Eat the '+' token.
4193 } else if (Tok.is(AsmToken::Minus)) {
4194 Parser.Lex(); // Eat the '-' token.
4199 Tok = Parser.getTok();
4200 int Reg = tryParseRegister();
4203 return MatchOperand_NoMatch;
4204 Error(Tok.getLoc(), "register expected");
4205 return MatchOperand_ParseFail;
4208 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4209 0, S, Tok.getEndLoc()));
4211 return MatchOperand_Success;
4214 /// Convert parsed operands to MCInst. Needed here because this instruction
4215 /// only has two register operands, but multiplication is commutative so
4216 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4218 cvtThumbMultiply(MCInst &Inst,
4219 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4220 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4221 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4222 // If we have a three-operand form, make sure to set Rn to be the operand
4223 // that isn't the same as Rd.
4225 if (Operands.size() == 6 &&
4226 ((ARMOperand*)Operands[4])->getReg() ==
4227 ((ARMOperand*)Operands[3])->getReg())
4229 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4230 Inst.addOperand(Inst.getOperand(0));
4231 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4235 cvtThumbBranches(MCInst &Inst,
4236 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4237 int CondOp = -1, ImmOp = -1;
4238 switch(Inst.getOpcode()) {
4240 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4243 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4245 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4247 // first decide whether or not the branch should be conditional
4248 // by looking at it's location relative to an IT block
4250 // inside an IT block we cannot have any conditional branches. any
4251 // such instructions needs to be converted to unconditional form
4252 switch(Inst.getOpcode()) {
4253 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4254 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4257 // outside IT blocks we can only have unconditional branches with AL
4258 // condition code or conditional branches with non-AL condition code
4259 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4260 switch(Inst.getOpcode()) {
4263 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4267 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4272 // now decide on encoding size based on branch target range
4273 switch(Inst.getOpcode()) {
4274 // classify tB as either t2B or t1B based on range of immediate operand
4276 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4277 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4278 Inst.setOpcode(ARM::t2B);
4281 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4283 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4284 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4285 Inst.setOpcode(ARM::t2Bcc);
4289 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4290 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4293 /// Parse an ARM memory expression, return false if successful else return true
4294 /// or an error. The first token must be a '[' when called.
4296 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4298 assert(Parser.getTok().is(AsmToken::LBrac) &&
4299 "Token is not a Left Bracket");
4300 S = Parser.getTok().getLoc();
4301 Parser.Lex(); // Eat left bracket token.
4303 const AsmToken &BaseRegTok = Parser.getTok();
4304 int BaseRegNum = tryParseRegister();
4305 if (BaseRegNum == -1)
4306 return Error(BaseRegTok.getLoc(), "register expected");
4308 // The next token must either be a comma, a colon or a closing bracket.
4309 const AsmToken &Tok = Parser.getTok();
4310 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4311 !Tok.is(AsmToken::RBrac))
4312 return Error(Tok.getLoc(), "malformed memory operand");
4314 if (Tok.is(AsmToken::RBrac)) {
4315 E = Tok.getEndLoc();
4316 Parser.Lex(); // Eat right bracket token.
4318 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4319 0, 0, false, S, E));
4321 // If there's a pre-indexing writeback marker, '!', just add it as a token
4322 // operand. It's rather odd, but syntactically valid.
4323 if (Parser.getTok().is(AsmToken::Exclaim)) {
4324 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4325 Parser.Lex(); // Eat the '!'.
4331 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4332 "Lost colon or comma in memory operand?!");
4333 if (Tok.is(AsmToken::Comma)) {
4334 Parser.Lex(); // Eat the comma.
4337 // If we have a ':', it's an alignment specifier.
4338 if (Parser.getTok().is(AsmToken::Colon)) {
4339 Parser.Lex(); // Eat the ':'.
4340 E = Parser.getTok().getLoc();
4343 if (getParser().parseExpression(Expr))
4346 // The expression has to be a constant. Memory references with relocations
4347 // don't come through here, as they use the <label> forms of the relevant
4349 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4351 return Error (E, "constant expression expected");
4354 switch (CE->getValue()) {
4357 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4358 case 16: Align = 2; break;
4359 case 32: Align = 4; break;
4360 case 64: Align = 8; break;
4361 case 128: Align = 16; break;
4362 case 256: Align = 32; break;
4365 // Now we should have the closing ']'
4366 if (Parser.getTok().isNot(AsmToken::RBrac))
4367 return Error(Parser.getTok().getLoc(), "']' expected");
4368 E = Parser.getTok().getEndLoc();
4369 Parser.Lex(); // Eat right bracket token.
4371 // Don't worry about range checking the value here. That's handled by
4372 // the is*() predicates.
4373 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4374 ARM_AM::no_shift, 0, Align,
4377 // If there's a pre-indexing writeback marker, '!', just add it as a token
4379 if (Parser.getTok().is(AsmToken::Exclaim)) {
4380 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4381 Parser.Lex(); // Eat the '!'.
4387 // If we have a '#', it's an immediate offset, else assume it's a register
4388 // offset. Be friendly and also accept a plain integer (without a leading
4389 // hash) for gas compatibility.
4390 if (Parser.getTok().is(AsmToken::Hash) ||
4391 Parser.getTok().is(AsmToken::Dollar) ||
4392 Parser.getTok().is(AsmToken::Integer)) {
4393 if (Parser.getTok().isNot(AsmToken::Integer))
4394 Parser.Lex(); // Eat '#' or '$'.
4395 E = Parser.getTok().getLoc();
4397 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4398 const MCExpr *Offset;
4399 if (getParser().parseExpression(Offset))
4402 // The expression has to be a constant. Memory references with relocations
4403 // don't come through here, as they use the <label> forms of the relevant
4405 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4407 return Error (E, "constant expression expected");
4409 // If the constant was #-0, represent it as INT32_MIN.
4410 int32_t Val = CE->getValue();
4411 if (isNegative && Val == 0)
4412 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4414 // Now we should have the closing ']'
4415 if (Parser.getTok().isNot(AsmToken::RBrac))
4416 return Error(Parser.getTok().getLoc(), "']' expected");
4417 E = Parser.getTok().getEndLoc();
4418 Parser.Lex(); // Eat right bracket token.
4420 // Don't worry about range checking the value here. That's handled by
4421 // the is*() predicates.
4422 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4423 ARM_AM::no_shift, 0, 0,
4426 // If there's a pre-indexing writeback marker, '!', just add it as a token
4428 if (Parser.getTok().is(AsmToken::Exclaim)) {
4429 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4430 Parser.Lex(); // Eat the '!'.
4436 // The register offset is optionally preceded by a '+' or '-'
4437 bool isNegative = false;
4438 if (Parser.getTok().is(AsmToken::Minus)) {
4440 Parser.Lex(); // Eat the '-'.
4441 } else if (Parser.getTok().is(AsmToken::Plus)) {
4443 Parser.Lex(); // Eat the '+'.
4446 E = Parser.getTok().getLoc();
4447 int OffsetRegNum = tryParseRegister();
4448 if (OffsetRegNum == -1)
4449 return Error(E, "register expected");
4451 // If there's a shift operator, handle it.
4452 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4453 unsigned ShiftImm = 0;
4454 if (Parser.getTok().is(AsmToken::Comma)) {
4455 Parser.Lex(); // Eat the ','.
4456 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4460 // Now we should have the closing ']'
4461 if (Parser.getTok().isNot(AsmToken::RBrac))
4462 return Error(Parser.getTok().getLoc(), "']' expected");
4463 E = Parser.getTok().getEndLoc();
4464 Parser.Lex(); // Eat right bracket token.
4466 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4467 ShiftType, ShiftImm, 0, isNegative,
4470 // If there's a pre-indexing writeback marker, '!', just add it as a token
4472 if (Parser.getTok().is(AsmToken::Exclaim)) {
4473 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4474 Parser.Lex(); // Eat the '!'.
4480 /// parseMemRegOffsetShift - one of these two:
4481 /// ( lsl | lsr | asr | ror ) , # shift_amount
4483 /// return true if it parses a shift otherwise it returns false.
4484 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4486 SMLoc Loc = Parser.getTok().getLoc();
4487 const AsmToken &Tok = Parser.getTok();
4488 if (Tok.isNot(AsmToken::Identifier))
4490 StringRef ShiftName = Tok.getString();
4491 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4492 ShiftName == "asl" || ShiftName == "ASL")
4494 else if (ShiftName == "lsr" || ShiftName == "LSR")
4496 else if (ShiftName == "asr" || ShiftName == "ASR")
4498 else if (ShiftName == "ror" || ShiftName == "ROR")
4500 else if (ShiftName == "rrx" || ShiftName == "RRX")
4503 return Error(Loc, "illegal shift operator");
4504 Parser.Lex(); // Eat shift type token.
4506 // rrx stands alone.
4508 if (St != ARM_AM::rrx) {
4509 Loc = Parser.getTok().getLoc();
4510 // A '#' and a shift amount.
4511 const AsmToken &HashTok = Parser.getTok();
4512 if (HashTok.isNot(AsmToken::Hash) &&
4513 HashTok.isNot(AsmToken::Dollar))
4514 return Error(HashTok.getLoc(), "'#' expected");
4515 Parser.Lex(); // Eat hash token.
4518 if (getParser().parseExpression(Expr))
4520 // Range check the immediate.
4521 // lsl, ror: 0 <= imm <= 31
4522 // lsr, asr: 0 <= imm <= 32
4523 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4525 return Error(Loc, "shift amount must be an immediate");
4526 int64_t Imm = CE->getValue();
4528 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4529 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4530 return Error(Loc, "immediate shift value out of range");
4531 // If <ShiftTy> #0, turn it into a no_shift.
4534 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4543 /// parseFPImm - A floating point immediate expression operand.
4544 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4545 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4546 // Anything that can accept a floating point constant as an operand
4547 // needs to go through here, as the regular parseExpression is
4550 // This routine still creates a generic Immediate operand, containing
4551 // a bitcast of the 64-bit floating point value. The various operands
4552 // that accept floats can check whether the value is valid for them
4553 // via the standard is*() predicates.
4555 SMLoc S = Parser.getTok().getLoc();
4557 if (Parser.getTok().isNot(AsmToken::Hash) &&
4558 Parser.getTok().isNot(AsmToken::Dollar))
4559 return MatchOperand_NoMatch;
4561 // Disambiguate the VMOV forms that can accept an FP immediate.
4562 // vmov.f32 <sreg>, #imm
4563 // vmov.f64 <dreg>, #imm
4564 // vmov.f32 <dreg>, #imm @ vector f32x2
4565 // vmov.f32 <qreg>, #imm @ vector f32x4
4567 // There are also the NEON VMOV instructions which expect an
4568 // integer constant. Make sure we don't try to parse an FPImm
4570 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4571 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4572 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4573 TyOp->getToken() != ".f64"))
4574 return MatchOperand_NoMatch;
4576 Parser.Lex(); // Eat '#' or '$'.
4578 // Handle negation, as that still comes through as a separate token.
4579 bool isNegative = false;
4580 if (Parser.getTok().is(AsmToken::Minus)) {
4584 const AsmToken &Tok = Parser.getTok();
4585 SMLoc Loc = Tok.getLoc();
4586 if (Tok.is(AsmToken::Real)) {
4587 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4588 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4589 // If we had a '-' in front, toggle the sign bit.
4590 IntVal ^= (uint64_t)isNegative << 31;
4591 Parser.Lex(); // Eat the token.
4592 Operands.push_back(ARMOperand::CreateImm(
4593 MCConstantExpr::Create(IntVal, getContext()),
4594 S, Parser.getTok().getLoc()));
4595 return MatchOperand_Success;
4597 // Also handle plain integers. Instructions which allow floating point
4598 // immediates also allow a raw encoded 8-bit value.
4599 if (Tok.is(AsmToken::Integer)) {
4600 int64_t Val = Tok.getIntVal();
4601 Parser.Lex(); // Eat the token.
4602 if (Val > 255 || Val < 0) {
4603 Error(Loc, "encoded floating point value out of range");
4604 return MatchOperand_ParseFail;
4606 double RealVal = ARM_AM::getFPImmFloat(Val);
4607 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4608 Operands.push_back(ARMOperand::CreateImm(
4609 MCConstantExpr::Create(Val, getContext()), S,
4610 Parser.getTok().getLoc()));
4611 return MatchOperand_Success;
4614 Error(Loc, "invalid floating point immediate");
4615 return MatchOperand_ParseFail;
4618 /// Parse a arm instruction operand. For now this parses the operand regardless
4619 /// of the mnemonic.
4620 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4621 StringRef Mnemonic) {
4624 // Check if the current operand has a custom associated parser, if so, try to
4625 // custom parse the operand, or fallback to the general approach.
4626 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4627 if (ResTy == MatchOperand_Success)
4629 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4630 // there was a match, but an error occurred, in which case, just return that
4631 // the operand parsing failed.
4632 if (ResTy == MatchOperand_ParseFail)
4635 switch (getLexer().getKind()) {
4637 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4639 case AsmToken::Identifier: {
4640 // If we've seen a branch mnemonic, the next operand must be a label. This
4641 // is true even if the label is a register name. So "br r1" means branch to
4643 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4645 if (!tryParseRegisterWithWriteBack(Operands))
4647 int Res = tryParseShiftRegister(Operands);
4648 if (Res == 0) // success
4650 else if (Res == -1) // irrecoverable error
4652 // If this is VMRS, check for the apsr_nzcv operand.
4653 if (Mnemonic == "vmrs" &&
4654 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4655 S = Parser.getTok().getLoc();
4657 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4662 // Fall though for the Identifier case that is not a register or a
4665 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4666 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4667 case AsmToken::String: // quoted label names.
4668 case AsmToken::Dot: { // . as a branch target
4669 // This was not a register so parse other operands that start with an
4670 // identifier (like labels) as expressions and create them as immediates.
4671 const MCExpr *IdVal;
4672 S = Parser.getTok().getLoc();
4673 if (getParser().parseExpression(IdVal))
4675 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4676 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4679 case AsmToken::LBrac:
4680 return parseMemory(Operands);
4681 case AsmToken::LCurly:
4682 return parseRegisterList(Operands);
4683 case AsmToken::Dollar:
4684 case AsmToken::Hash: {
4685 // #42 -> immediate.
4686 S = Parser.getTok().getLoc();
4689 if (Parser.getTok().isNot(AsmToken::Colon)) {
4690 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4691 const MCExpr *ImmVal;
4692 if (getParser().parseExpression(ImmVal))
4694 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4696 int32_t Val = CE->getValue();
4697 if (isNegative && Val == 0)
4698 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4700 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4701 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4703 // There can be a trailing '!' on operands that we want as a separate
4704 // '!' Token operand. Handle that here. For example, the compatibilty
4705 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4706 if (Parser.getTok().is(AsmToken::Exclaim)) {
4707 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4708 Parser.getTok().getLoc()));
4709 Parser.Lex(); // Eat exclaim token
4713 // w/ a ':' after the '#', it's just like a plain ':'.
4716 case AsmToken::Colon: {
4717 // ":lower16:" and ":upper16:" expression prefixes
4718 // FIXME: Check it's an expression prefix,
4719 // e.g. (FOO - :lower16:BAR) isn't legal.
4720 ARMMCExpr::VariantKind RefKind;
4721 if (parsePrefix(RefKind))
4724 const MCExpr *SubExprVal;
4725 if (getParser().parseExpression(SubExprVal))
4728 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4730 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4731 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4734 case AsmToken::Equal: {
4735 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4736 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4738 const MCSection *Section =
4739 getParser().getStreamer().getCurrentSection().first;
4741 Parser.Lex(); // Eat '='
4742 const MCExpr *SubExprVal;
4743 if (getParser().parseExpression(SubExprVal))
4745 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4747 const MCExpr *CPLoc =
4748 getOrCreateConstantPool(Section).addEntry(SubExprVal, getContext());
4749 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4755 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4756 // :lower16: and :upper16:.
4757 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4758 RefKind = ARMMCExpr::VK_ARM_None;
4760 // :lower16: and :upper16: modifiers
4761 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4762 Parser.Lex(); // Eat ':'
4764 if (getLexer().isNot(AsmToken::Identifier)) {
4765 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4769 StringRef IDVal = Parser.getTok().getIdentifier();
4770 if (IDVal == "lower16") {
4771 RefKind = ARMMCExpr::VK_ARM_LO16;
4772 } else if (IDVal == "upper16") {
4773 RefKind = ARMMCExpr::VK_ARM_HI16;
4775 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4780 if (getLexer().isNot(AsmToken::Colon)) {
4781 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4784 Parser.Lex(); // Eat the last ':'
4788 /// \brief Given a mnemonic, split out possible predication code and carry
4789 /// setting letters to form a canonical mnemonic and flags.
4791 // FIXME: Would be nice to autogen this.
4792 // FIXME: This is a bit of a maze of special cases.
4793 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4794 unsigned &PredicationCode,
4796 unsigned &ProcessorIMod,
4797 StringRef &ITMask) {
4798 PredicationCode = ARMCC::AL;
4799 CarrySetting = false;
4802 // Ignore some mnemonics we know aren't predicated forms.
4804 // FIXME: Would be nice to autogen this.
4805 if ((Mnemonic == "movs" && isThumb()) ||
4806 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4807 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4808 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4809 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4810 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
4811 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4812 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4813 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4814 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
4815 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4816 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4817 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
4820 // First, split out any predication code. Ignore mnemonics we know aren't
4821 // predicated but do have a carry-set and so weren't caught above.
4822 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4823 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4824 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4825 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4826 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4827 .Case("eq", ARMCC::EQ)
4828 .Case("ne", ARMCC::NE)
4829 .Case("hs", ARMCC::HS)
4830 .Case("cs", ARMCC::HS)
4831 .Case("lo", ARMCC::LO)
4832 .Case("cc", ARMCC::LO)
4833 .Case("mi", ARMCC::MI)
4834 .Case("pl", ARMCC::PL)
4835 .Case("vs", ARMCC::VS)
4836 .Case("vc", ARMCC::VC)
4837 .Case("hi", ARMCC::HI)
4838 .Case("ls", ARMCC::LS)
4839 .Case("ge", ARMCC::GE)
4840 .Case("lt", ARMCC::LT)
4841 .Case("gt", ARMCC::GT)
4842 .Case("le", ARMCC::LE)
4843 .Case("al", ARMCC::AL)
4846 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4847 PredicationCode = CC;
4851 // Next, determine if we have a carry setting bit. We explicitly ignore all
4852 // the instructions we know end in 's'.
4853 if (Mnemonic.endswith("s") &&
4854 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4855 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4856 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4857 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4858 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4859 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4860 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4861 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4862 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4863 (Mnemonic == "movs" && isThumb()))) {
4864 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4865 CarrySetting = true;
4868 // The "cps" instruction can have a interrupt mode operand which is glued into
4869 // the mnemonic. Check if this is the case, split it and parse the imod op
4870 if (Mnemonic.startswith("cps")) {
4871 // Split out any imod code.
4873 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4874 .Case("ie", ARM_PROC::IE)
4875 .Case("id", ARM_PROC::ID)
4878 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4879 ProcessorIMod = IMod;
4883 // The "it" instruction has the condition mask on the end of the mnemonic.
4884 if (Mnemonic.startswith("it")) {
4885 ITMask = Mnemonic.slice(2, Mnemonic.size());
4886 Mnemonic = Mnemonic.slice(0, 2);
4892 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4893 /// inclusion of carry set or predication code operands.
4895 // FIXME: It would be nice to autogen this.
4897 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4898 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
4899 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4900 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4901 Mnemonic == "add" || Mnemonic == "adc" ||
4902 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4903 Mnemonic == "orr" || Mnemonic == "mvn" ||
4904 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4905 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4906 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4907 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4908 Mnemonic == "mla" || Mnemonic == "smlal" ||
4909 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4910 CanAcceptCarrySet = true;
4912 CanAcceptCarrySet = false;
4914 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4915 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4916 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
4917 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4918 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
4919 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4920 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4921 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4922 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4923 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
4924 // These mnemonics are never predicable
4925 CanAcceptPredicationCode = false;
4926 } else if (!isThumb()) {
4927 // Some instructions are only predicable in Thumb mode
4928 CanAcceptPredicationCode
4929 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4930 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4931 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4932 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4933 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4934 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4935 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4936 } else if (isThumbOne()) {
4938 CanAcceptPredicationCode = Mnemonic != "movs";
4940 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4942 CanAcceptPredicationCode = true;
4945 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4946 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4947 // FIXME: This is all horribly hacky. We really need a better way to deal
4948 // with optional operands like this in the matcher table.
4950 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4951 // another does not. Specifically, the MOVW instruction does not. So we
4952 // special case it here and remove the defaulted (non-setting) cc_out
4953 // operand if that's the instruction we're trying to match.
4955 // We do this as post-processing of the explicit operands rather than just
4956 // conditionally adding the cc_out in the first place because we need
4957 // to check the type of the parsed immediate operand.
4958 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4959 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4960 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4961 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4964 // Register-register 'add' for thumb does not have a cc_out operand
4965 // when there are only two register operands.
4966 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4967 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4968 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4969 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4971 // Register-register 'add' for thumb does not have a cc_out operand
4972 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4973 // have to check the immediate range here since Thumb2 has a variant
4974 // that can handle a different range and has a cc_out operand.
4975 if (((isThumb() && Mnemonic == "add") ||
4976 (isThumbTwo() && Mnemonic == "sub")) &&
4977 Operands.size() == 6 &&
4978 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4979 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4980 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4981 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4982 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4983 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4985 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4986 // imm0_4095 variant. That's the least-preferred variant when
4987 // selecting via the generic "add" mnemonic, so to know that we
4988 // should remove the cc_out operand, we have to explicitly check that
4989 // it's not one of the other variants. Ugh.
4990 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4991 Operands.size() == 6 &&
4992 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4993 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4994 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4995 // Nest conditions rather than one big 'if' statement for readability.
4997 // If both registers are low, we're in an IT block, and the immediate is
4998 // in range, we should use encoding T1 instead, which has a cc_out.
5000 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5001 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5002 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5004 // Check against T3. If the second register is the PC, this is an
5005 // alternate form of ADR, which uses encoding T4, so check for that too.
5006 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5007 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5010 // Otherwise, we use encoding T4, which does not have a cc_out
5015 // The thumb2 multiply instruction doesn't have a CCOut register, so
5016 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5017 // use the 16-bit encoding or not.
5018 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5019 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5020 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5021 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5022 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5023 // If the registers aren't low regs, the destination reg isn't the
5024 // same as one of the source regs, or the cc_out operand is zero
5025 // outside of an IT block, we have to use the 32-bit encoding, so
5026 // remove the cc_out operand.
5027 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5028 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5029 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
5031 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5032 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5033 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5034 static_cast<ARMOperand*>(Operands[4])->getReg())))
5037 // Also check the 'mul' syntax variant that doesn't specify an explicit
5038 // destination register.
5039 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5040 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5041 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5042 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5043 // If the registers aren't low regs or the cc_out operand is zero
5044 // outside of an IT block, we have to use the 32-bit encoding, so
5045 // remove the cc_out operand.
5046 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5047 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5053 // Register-register 'add/sub' for thumb does not have a cc_out operand
5054 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5055 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5056 // right, this will result in better diagnostics (which operand is off)
5058 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5059 (Operands.size() == 5 || Operands.size() == 6) &&
5060 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5061 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
5062 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5063 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5064 (Operands.size() == 6 &&
5065 static_cast<ARMOperand*>(Operands[5])->isImm())))
5071 bool ARMAsmParser::shouldOmitPredicateOperand(
5072 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
5073 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5074 unsigned RegIdx = 3;
5075 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5076 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
5077 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
5078 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
5081 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
5082 (ARMMCRegisterClasses[ARM::DPRRegClassID]
5083 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
5084 ARMMCRegisterClasses[ARM::QPRRegClassID]
5085 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
5091 static bool isDataTypeToken(StringRef Tok) {
5092 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5093 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5094 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5095 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5096 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5097 Tok == ".f" || Tok == ".d";
5100 // FIXME: This bit should probably be handled via an explicit match class
5101 // in the .td files that matches the suffix instead of having it be
5102 // a literal string token the way it is now.
5103 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5104 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5106 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5107 unsigned VariantID);
5108 /// Parse an arm instruction mnemonic followed by its operands.
5109 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5111 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5112 // Apply mnemonic aliases before doing anything else, as the destination
5113 // mnemnonic may include suffices and we want to handle them normally.
5114 // The generic tblgen'erated code does this later, at the start of
5115 // MatchInstructionImpl(), but that's too late for aliases that include
5116 // any sort of suffix.
5117 unsigned AvailableFeatures = getAvailableFeatures();
5118 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5119 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5121 // First check for the ARM-specific .req directive.
5122 if (Parser.getTok().is(AsmToken::Identifier) &&
5123 Parser.getTok().getIdentifier() == ".req") {
5124 parseDirectiveReq(Name, NameLoc);
5125 // We always return 'error' for this, as we're done with this
5126 // statement and don't need to match the 'instruction."
5130 // Create the leading tokens for the mnemonic, split by '.' characters.
5131 size_t Start = 0, Next = Name.find('.');
5132 StringRef Mnemonic = Name.slice(Start, Next);
5134 // Split out the predication code and carry setting flag from the mnemonic.
5135 unsigned PredicationCode;
5136 unsigned ProcessorIMod;
5139 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5140 ProcessorIMod, ITMask);
5142 // In Thumb1, only the branch (B) instruction can be predicated.
5143 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5144 Parser.eatToEndOfStatement();
5145 return Error(NameLoc, "conditional execution not supported in Thumb1");
5148 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5150 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5151 // is the mask as it will be for the IT encoding if the conditional
5152 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5153 // where the conditional bit0 is zero, the instruction post-processing
5154 // will adjust the mask accordingly.
5155 if (Mnemonic == "it") {
5156 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5157 if (ITMask.size() > 3) {
5158 Parser.eatToEndOfStatement();
5159 return Error(Loc, "too many conditions on IT instruction");
5162 for (unsigned i = ITMask.size(); i != 0; --i) {
5163 char pos = ITMask[i - 1];
5164 if (pos != 't' && pos != 'e') {
5165 Parser.eatToEndOfStatement();
5166 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5169 if (ITMask[i - 1] == 't')
5172 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5175 // FIXME: This is all a pretty gross hack. We should automatically handle
5176 // optional operands like this via tblgen.
5178 // Next, add the CCOut and ConditionCode operands, if needed.
5180 // For mnemonics which can ever incorporate a carry setting bit or predication
5181 // code, our matching model involves us always generating CCOut and
5182 // ConditionCode operands to match the mnemonic "as written" and then we let
5183 // the matcher deal with finding the right instruction or generating an
5184 // appropriate error.
5185 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5186 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5188 // If we had a carry-set on an instruction that can't do that, issue an
5190 if (!CanAcceptCarrySet && CarrySetting) {
5191 Parser.eatToEndOfStatement();
5192 return Error(NameLoc, "instruction '" + Mnemonic +
5193 "' can not set flags, but 's' suffix specified");
5195 // If we had a predication code on an instruction that can't do that, issue an
5197 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5198 Parser.eatToEndOfStatement();
5199 return Error(NameLoc, "instruction '" + Mnemonic +
5200 "' is not predicable, but condition code specified");
5203 // Add the carry setting operand, if necessary.
5204 if (CanAcceptCarrySet) {
5205 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5206 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5210 // Add the predication code operand, if necessary.
5211 if (CanAcceptPredicationCode) {
5212 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5214 Operands.push_back(ARMOperand::CreateCondCode(
5215 ARMCC::CondCodes(PredicationCode), Loc));
5218 // Add the processor imod operand, if necessary.
5219 if (ProcessorIMod) {
5220 Operands.push_back(ARMOperand::CreateImm(
5221 MCConstantExpr::Create(ProcessorIMod, getContext()),
5225 // Add the remaining tokens in the mnemonic.
5226 while (Next != StringRef::npos) {
5228 Next = Name.find('.', Start + 1);
5229 StringRef ExtraToken = Name.slice(Start, Next);
5231 // Some NEON instructions have an optional datatype suffix that is
5232 // completely ignored. Check for that.
5233 if (isDataTypeToken(ExtraToken) &&
5234 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5237 // For for ARM mode generate an error if the .n qualifier is used.
5238 if (ExtraToken == ".n" && !isThumb()) {
5239 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5240 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5244 // The .n qualifier is always discarded as that is what the tables
5245 // and matcher expect. In ARM mode the .w qualifier has no effect,
5246 // so discard it to avoid errors that can be caused by the matcher.
5247 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5248 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5249 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5253 // Read the remaining operands.
5254 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5255 // Read the first operand.
5256 if (parseOperand(Operands, Mnemonic)) {
5257 Parser.eatToEndOfStatement();
5261 while (getLexer().is(AsmToken::Comma)) {
5262 Parser.Lex(); // Eat the comma.
5264 // Parse and remember the operand.
5265 if (parseOperand(Operands, Mnemonic)) {
5266 Parser.eatToEndOfStatement();
5272 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5273 SMLoc Loc = getLexer().getLoc();
5274 Parser.eatToEndOfStatement();
5275 return Error(Loc, "unexpected token in argument list");
5278 Parser.Lex(); // Consume the EndOfStatement
5280 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5281 // do and don't have a cc_out optional-def operand. With some spot-checks
5282 // of the operand list, we can figure out which variant we're trying to
5283 // parse and adjust accordingly before actually matching. We shouldn't ever
5284 // try to remove a cc_out operand that was explicitly set on the the
5285 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5286 // table driven matcher doesn't fit well with the ARM instruction set.
5287 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5288 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5289 Operands.erase(Operands.begin() + 1);
5293 // Some instructions have the same mnemonic, but don't always
5294 // have a predicate. Distinguish them here and delete the
5295 // predicate if needed.
5296 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5297 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5298 Operands.erase(Operands.begin() + 1);
5302 // ARM mode 'blx' need special handling, as the register operand version
5303 // is predicable, but the label operand version is not. So, we can't rely
5304 // on the Mnemonic based checking to correctly figure out when to put
5305 // a k_CondCode operand in the list. If we're trying to match the label
5306 // version, remove the k_CondCode operand here.
5307 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5308 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5309 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5310 Operands.erase(Operands.begin() + 1);
5314 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5315 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5316 // a single GPRPair reg operand is used in the .td file to replace the two
5317 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5318 // expressed as a GPRPair, so we have to manually merge them.
5319 // FIXME: We would really like to be able to tablegen'erate this.
5320 if (!isThumb() && Operands.size() > 4 &&
5321 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5322 Mnemonic == "stlexd")) {
5323 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5324 unsigned Idx = isLoad ? 2 : 3;
5325 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5326 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5328 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5329 // Adjust only if Op1 and Op2 are GPRs.
5330 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5331 MRC.contains(Op2->getReg())) {
5332 unsigned Reg1 = Op1->getReg();
5333 unsigned Reg2 = Op2->getReg();
5334 unsigned Rt = MRI->getEncodingValue(Reg1);
5335 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5337 // Rt2 must be Rt + 1 and Rt must be even.
5338 if (Rt + 1 != Rt2 || (Rt & 1)) {
5339 Error(Op2->getStartLoc(), isLoad ?
5340 "destination operands must be sequential" :
5341 "source operands must be sequential");
5344 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5345 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5346 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5347 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5348 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5354 // FIXME: As said above, this is all a pretty gross hack. This instruction
5355 // does not fit with other "subs" and tblgen.
5356 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5357 // so the Mnemonic is the original name "subs" and delete the predicate
5358 // operand so it will match the table entry.
5359 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5360 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5361 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5362 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5363 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5364 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5365 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5366 Operands.erase(Operands.begin());
5368 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5370 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5371 Operands.erase(Operands.begin() + 1);
5377 // Validate context-sensitive operand constraints.
5379 // return 'true' if register list contains non-low GPR registers,
5380 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5381 // 'containsReg' to true.
5382 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5383 unsigned HiReg, bool &containsReg) {
5384 containsReg = false;
5385 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5386 unsigned OpReg = Inst.getOperand(i).getReg();
5389 // Anything other than a low register isn't legal here.
5390 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5396 // Check if the specified regisgter is in the register list of the inst,
5397 // starting at the indicated operand number.
5398 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5399 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5400 unsigned OpReg = Inst.getOperand(i).getReg();
5407 // Return true if instruction has the interesting property of being
5408 // allowed in IT blocks, but not being predicable.
5409 static bool instIsBreakpoint(const MCInst &Inst) {
5410 return Inst.getOpcode() == ARM::tBKPT ||
5411 Inst.getOpcode() == ARM::BKPT ||
5412 Inst.getOpcode() == ARM::tHLT ||
5413 Inst.getOpcode() == ARM::HLT;
5417 // FIXME: We would really like to be able to tablegen'erate this.
5419 validateInstruction(MCInst &Inst,
5420 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5421 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
5422 SMLoc Loc = Operands[0]->getStartLoc();
5424 // Check the IT block state first.
5425 // NOTE: BKPT and HLT instructions have the interesting property of being
5426 // allowed in IT blocks, but not being predicable. They just always execute.
5427 if (inITBlock() && !instIsBreakpoint(Inst)) {
5429 if (ITState.FirstCond)
5430 ITState.FirstCond = false;
5432 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5433 // The instruction must be predicable.
5434 if (!MCID.isPredicable())
5435 return Error(Loc, "instructions in IT block must be predicable");
5436 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5437 unsigned ITCond = Bit ? ITState.Cond :
5438 ARMCC::getOppositeCondition(ITState.Cond);
5439 if (Cond != ITCond) {
5440 // Find the condition code Operand to get its SMLoc information.
5442 for (unsigned I = 1; I < Operands.size(); ++I)
5443 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5444 CondLoc = Operands[I]->getStartLoc();
5445 return Error(CondLoc, "incorrect condition in IT block; got '" +
5446 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5447 "', but expected '" +
5448 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5450 // Check for non-'al' condition codes outside of the IT block.
5451 } else if (isThumbTwo() && MCID.isPredicable() &&
5452 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5453 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5454 Inst.getOpcode() != ARM::t2Bcc)
5455 return Error(Loc, "predicated instructions must be in IT block");
5457 const unsigned Opcode = Inst.getOpcode();
5461 case ARM::LDRD_POST: {
5462 const unsigned RtReg = Inst.getOperand(0).getReg();
5465 if (RtReg == ARM::LR)
5466 return Error(Operands[3]->getStartLoc(),
5469 const unsigned Rt = MRI->getEncodingValue(RtReg);
5470 // Rt must be even-numbered.
5472 return Error(Operands[3]->getStartLoc(),
5473 "Rt must be even-numbered");
5475 // Rt2 must be Rt + 1.
5476 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5478 return Error(Operands[3]->getStartLoc(),
5479 "destination operands must be sequential");
5481 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5482 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5483 // For addressing modes with writeback, the base register needs to be
5484 // different from the destination registers.
5485 if (Rn == Rt || Rn == Rt2)
5486 return Error(Operands[3]->getStartLoc(),
5487 "base register needs to be different from destination "
5494 case ARM::t2LDRD_PRE:
5495 case ARM::t2LDRD_POST: {
5496 // Rt2 must be different from Rt.
5497 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5498 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5500 return Error(Operands[3]->getStartLoc(),
5501 "destination operands can't be identical");
5505 // Rt2 must be Rt + 1.
5506 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5507 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5509 return Error(Operands[3]->getStartLoc(),
5510 "source operands must be sequential");
5514 case ARM::STRD_POST: {
5515 // Rt2 must be Rt + 1.
5516 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5517 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5519 return Error(Operands[3]->getStartLoc(),
5520 "source operands must be sequential");
5525 // Width must be in range [1, 32-lsb].
5526 unsigned LSB = Inst.getOperand(2).getImm();
5527 unsigned Widthm1 = Inst.getOperand(3).getImm();
5528 if (Widthm1 >= 32 - LSB)
5529 return Error(Operands[5]->getStartLoc(),
5530 "bitfield width must be in range [1,32-lsb]");
5533 // Notionally handles ARM::tLDMIA_UPD too.
5535 // If we're parsing Thumb2, the .w variant is available and handles
5536 // most cases that are normally illegal for a Thumb1 LDM instruction.
5537 // We'll make the transformation in processInstruction() if necessary.
5539 // Thumb LDM instructions are writeback iff the base register is not
5540 // in the register list.
5541 unsigned Rn = Inst.getOperand(0).getReg();
5542 bool HasWritebackToken =
5543 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5544 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5545 bool ListContainsBase;
5546 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5547 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
5548 "registers must be in range r0-r7");
5549 // If we should have writeback, then there should be a '!' token.
5550 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
5551 return Error(Operands[2]->getStartLoc(),
5552 "writeback operator '!' expected");
5553 // If we should not have writeback, there must not be a '!'. This is
5554 // true even for the 32-bit wide encodings.
5555 if (ListContainsBase && HasWritebackToken)
5556 return Error(Operands[3]->getStartLoc(),
5557 "writeback operator '!' not allowed when base register "
5558 "in register list");
5562 case ARM::LDMIA_UPD:
5563 case ARM::LDMDB_UPD:
5564 case ARM::LDMIB_UPD:
5565 case ARM::LDMDA_UPD:
5566 // ARM variants loading and updating the same register are only officially
5567 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5571 case ARM::t2LDMIA_UPD:
5572 case ARM::t2LDMDB_UPD:
5573 case ARM::t2STMIA_UPD:
5574 case ARM::t2STMDB_UPD: {
5575 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5576 return Error(Operands.back()->getStartLoc(),
5577 "writeback register not allowed in register list");
5580 case ARM::sysLDMIA_UPD:
5581 case ARM::sysLDMDA_UPD:
5582 case ARM::sysLDMDB_UPD:
5583 case ARM::sysLDMIB_UPD:
5584 if (!listContainsReg(Inst, 3, ARM::PC))
5585 return Error(Operands[4]->getStartLoc(),
5586 "writeback register only allowed on system LDM "
5587 "if PC in register-list");
5589 case ARM::sysSTMIA_UPD:
5590 case ARM::sysSTMDA_UPD:
5591 case ARM::sysSTMDB_UPD:
5592 case ARM::sysSTMIB_UPD:
5593 return Error(Operands[2]->getStartLoc(),
5594 "system STM cannot have writeback register");
5597 // The second source operand must be the same register as the destination
5600 // In this case, we must directly check the parsed operands because the
5601 // cvtThumbMultiply() function is written in such a way that it guarantees
5602 // this first statement is always true for the new Inst. Essentially, the
5603 // destination is unconditionally copied into the second source operand
5604 // without checking to see if it matches what we actually parsed.
5605 if (Operands.size() == 6 &&
5606 (((ARMOperand*)Operands[3])->getReg() !=
5607 ((ARMOperand*)Operands[5])->getReg()) &&
5608 (((ARMOperand*)Operands[3])->getReg() !=
5609 ((ARMOperand*)Operands[4])->getReg())) {
5610 return Error(Operands[3]->getStartLoc(),
5611 "destination register must match source register");
5615 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5616 // so only issue a diagnostic for thumb1. The instructions will be
5617 // switched to the t2 encodings in processInstruction() if necessary.
5619 bool ListContainsBase;
5620 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
5622 return Error(Operands[2]->getStartLoc(),
5623 "registers must be in range r0-r7 or pc");
5627 bool ListContainsBase;
5628 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
5630 return Error(Operands[2]->getStartLoc(),
5631 "registers must be in range r0-r7 or lr");
5634 case ARM::tSTMIA_UPD: {
5635 bool ListContainsBase, InvalidLowList;
5636 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5637 0, ListContainsBase);
5638 if (InvalidLowList && !isThumbTwo())
5639 return Error(Operands[4]->getStartLoc(),
5640 "registers must be in range r0-r7");
5642 // This would be converted to a 32-bit stm, but that's not valid if the
5643 // writeback register is in the list.
5644 if (InvalidLowList && ListContainsBase)
5645 return Error(Operands[4]->getStartLoc(),
5646 "writeback operator '!' not allowed when base register "
5647 "in register list");
5650 case ARM::tADDrSP: {
5651 // If the non-SP source operand and the destination operand are not the
5652 // same, we need thumb2 (for the wide encoding), or we have an error.
5653 if (!isThumbTwo() &&
5654 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5655 return Error(Operands[4]->getStartLoc(),
5656 "source register must be the same as destination");
5660 // Final range checking for Thumb unconditional branch instructions.
5662 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5663 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5666 int op = (Operands[2]->isImm()) ? 2 : 3;
5667 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5668 return Error(Operands[op]->getStartLoc(), "branch target out of range");
5671 // Final range checking for Thumb conditional branch instructions.
5673 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5674 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5677 int Op = (Operands[2]->isImm()) ? 2 : 3;
5678 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5679 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
5687 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5689 default: llvm_unreachable("unexpected opcode!");
5691 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5692 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5693 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5694 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5695 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5696 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5697 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5698 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5699 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5702 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5703 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5704 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5705 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5706 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5708 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5709 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5710 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5711 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5712 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5714 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5715 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5716 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5717 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5718 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5721 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5722 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5723 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5724 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5725 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5726 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5727 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5728 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5729 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5730 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5731 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5732 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5733 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5734 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5735 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5738 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5739 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5740 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5741 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5742 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5743 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5744 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5745 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5746 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5747 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5748 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5749 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5750 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5751 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5752 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5753 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5754 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5755 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5758 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5759 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5760 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5761 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5762 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5763 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5764 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5765 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5766 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5767 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5768 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5769 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5770 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5771 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5772 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5775 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5776 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5777 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5778 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5779 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5780 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5781 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5782 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5783 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5784 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5785 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5786 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5787 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5788 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5789 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5790 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5791 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5792 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5796 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5798 default: llvm_unreachable("unexpected opcode!");
5800 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5801 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5802 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5803 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5804 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5805 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5806 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5807 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5808 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5811 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5812 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5813 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5814 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5815 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5816 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5817 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5818 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5819 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5820 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5821 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5822 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5823 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5824 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5825 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5828 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5829 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5830 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5831 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5832 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5833 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5834 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5835 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5836 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5837 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5838 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5839 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5840 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5841 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5842 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5843 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5844 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5845 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5848 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5849 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5850 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5851 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5852 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5853 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5854 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5855 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5856 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5857 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5858 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5859 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5860 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5861 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5862 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5865 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5866 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5867 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5868 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5869 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5870 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5871 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5872 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5873 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5874 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5875 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5876 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5877 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5878 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5879 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5880 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5881 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5882 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5885 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5886 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5887 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5888 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5889 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5890 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5891 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5892 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5893 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5894 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5895 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5896 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5897 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5898 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5899 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5902 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5903 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5904 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5905 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5906 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5907 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5908 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5909 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5910 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5911 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5912 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5913 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5914 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5915 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5916 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5917 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5918 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5919 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5922 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5923 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5924 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5925 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5926 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5927 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5928 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5929 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5930 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5931 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5932 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5933 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5934 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5935 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5936 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5937 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5938 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5939 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5944 processInstruction(MCInst &Inst,
5945 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5946 switch (Inst.getOpcode()) {
5947 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5949 if (Inst.getOperand(1).getReg() != ARM::PC ||
5950 Inst.getOperand(5).getReg() != 0)
5953 TmpInst.setOpcode(ARM::ADR);
5954 TmpInst.addOperand(Inst.getOperand(0));
5955 TmpInst.addOperand(Inst.getOperand(2));
5956 TmpInst.addOperand(Inst.getOperand(3));
5957 TmpInst.addOperand(Inst.getOperand(4));
5961 // Aliases for alternate PC+imm syntax of LDR instructions.
5962 case ARM::t2LDRpcrel:
5963 // Select the narrow version if the immediate will fit.
5964 if (Inst.getOperand(1).getImm() > 0 &&
5965 Inst.getOperand(1).getImm() <= 0xff &&
5966 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5967 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
5968 Inst.setOpcode(ARM::tLDRpci);
5970 Inst.setOpcode(ARM::t2LDRpci);
5972 case ARM::t2LDRBpcrel:
5973 Inst.setOpcode(ARM::t2LDRBpci);
5975 case ARM::t2LDRHpcrel:
5976 Inst.setOpcode(ARM::t2LDRHpci);
5978 case ARM::t2LDRSBpcrel:
5979 Inst.setOpcode(ARM::t2LDRSBpci);
5981 case ARM::t2LDRSHpcrel:
5982 Inst.setOpcode(ARM::t2LDRSHpci);
5984 // Handle NEON VST complex aliases.
5985 case ARM::VST1LNdWB_register_Asm_8:
5986 case ARM::VST1LNdWB_register_Asm_16:
5987 case ARM::VST1LNdWB_register_Asm_32: {
5989 // Shuffle the operands around so the lane index operand is in the
5992 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5993 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5994 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5995 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5996 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5997 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5998 TmpInst.addOperand(Inst.getOperand(1)); // lane
5999 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6000 TmpInst.addOperand(Inst.getOperand(6));
6005 case ARM::VST2LNdWB_register_Asm_8:
6006 case ARM::VST2LNdWB_register_Asm_16:
6007 case ARM::VST2LNdWB_register_Asm_32:
6008 case ARM::VST2LNqWB_register_Asm_16:
6009 case ARM::VST2LNqWB_register_Asm_32: {
6011 // Shuffle the operands around so the lane index operand is in the
6014 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6015 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6016 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6017 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6018 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6019 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6020 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6022 TmpInst.addOperand(Inst.getOperand(1)); // lane
6023 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6024 TmpInst.addOperand(Inst.getOperand(6));
6029 case ARM::VST3LNdWB_register_Asm_8:
6030 case ARM::VST3LNdWB_register_Asm_16:
6031 case ARM::VST3LNdWB_register_Asm_32:
6032 case ARM::VST3LNqWB_register_Asm_16:
6033 case ARM::VST3LNqWB_register_Asm_32: {
6035 // Shuffle the operands around so the lane index operand is in the
6038 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6039 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6040 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6041 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6042 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6043 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6044 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6046 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6048 TmpInst.addOperand(Inst.getOperand(1)); // lane
6049 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6050 TmpInst.addOperand(Inst.getOperand(6));
6055 case ARM::VST4LNdWB_register_Asm_8:
6056 case ARM::VST4LNdWB_register_Asm_16:
6057 case ARM::VST4LNdWB_register_Asm_32:
6058 case ARM::VST4LNqWB_register_Asm_16:
6059 case ARM::VST4LNqWB_register_Asm_32: {
6061 // Shuffle the operands around so the lane index operand is in the
6064 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6065 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6066 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6067 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6068 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6069 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6070 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6072 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6074 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6076 TmpInst.addOperand(Inst.getOperand(1)); // lane
6077 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6078 TmpInst.addOperand(Inst.getOperand(6));
6083 case ARM::VST1LNdWB_fixed_Asm_8:
6084 case ARM::VST1LNdWB_fixed_Asm_16:
6085 case ARM::VST1LNdWB_fixed_Asm_32: {
6087 // Shuffle the operands around so the lane index operand is in the
6090 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6091 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6092 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6093 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6094 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6095 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6096 TmpInst.addOperand(Inst.getOperand(1)); // lane
6097 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6098 TmpInst.addOperand(Inst.getOperand(5));
6103 case ARM::VST2LNdWB_fixed_Asm_8:
6104 case ARM::VST2LNdWB_fixed_Asm_16:
6105 case ARM::VST2LNdWB_fixed_Asm_32:
6106 case ARM::VST2LNqWB_fixed_Asm_16:
6107 case ARM::VST2LNqWB_fixed_Asm_32: {
6109 // Shuffle the operands around so the lane index operand is in the
6112 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6113 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6114 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6115 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6116 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6117 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6118 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6120 TmpInst.addOperand(Inst.getOperand(1)); // lane
6121 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6122 TmpInst.addOperand(Inst.getOperand(5));
6127 case ARM::VST3LNdWB_fixed_Asm_8:
6128 case ARM::VST3LNdWB_fixed_Asm_16:
6129 case ARM::VST3LNdWB_fixed_Asm_32:
6130 case ARM::VST3LNqWB_fixed_Asm_16:
6131 case ARM::VST3LNqWB_fixed_Asm_32: {
6133 // Shuffle the operands around so the lane index operand is in the
6136 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6137 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6138 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6139 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6140 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6141 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6144 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6146 TmpInst.addOperand(Inst.getOperand(1)); // lane
6147 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6148 TmpInst.addOperand(Inst.getOperand(5));
6153 case ARM::VST4LNdWB_fixed_Asm_8:
6154 case ARM::VST4LNdWB_fixed_Asm_16:
6155 case ARM::VST4LNdWB_fixed_Asm_32:
6156 case ARM::VST4LNqWB_fixed_Asm_16:
6157 case ARM::VST4LNqWB_fixed_Asm_32: {
6159 // Shuffle the operands around so the lane index operand is in the
6162 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6163 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6164 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6165 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6166 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6167 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6168 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6170 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6172 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6174 TmpInst.addOperand(Inst.getOperand(1)); // lane
6175 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6176 TmpInst.addOperand(Inst.getOperand(5));
6181 case ARM::VST1LNdAsm_8:
6182 case ARM::VST1LNdAsm_16:
6183 case ARM::VST1LNdAsm_32: {
6185 // Shuffle the operands around so the lane index operand is in the
6188 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6189 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6190 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6191 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6192 TmpInst.addOperand(Inst.getOperand(1)); // lane
6193 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6194 TmpInst.addOperand(Inst.getOperand(5));
6199 case ARM::VST2LNdAsm_8:
6200 case ARM::VST2LNdAsm_16:
6201 case ARM::VST2LNdAsm_32:
6202 case ARM::VST2LNqAsm_16:
6203 case ARM::VST2LNqAsm_32: {
6205 // Shuffle the operands around so the lane index operand is in the
6208 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6209 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6210 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6211 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6212 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6214 TmpInst.addOperand(Inst.getOperand(1)); // lane
6215 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6216 TmpInst.addOperand(Inst.getOperand(5));
6221 case ARM::VST3LNdAsm_8:
6222 case ARM::VST3LNdAsm_16:
6223 case ARM::VST3LNdAsm_32:
6224 case ARM::VST3LNqAsm_16:
6225 case ARM::VST3LNqAsm_32: {
6227 // Shuffle the operands around so the lane index operand is in the
6230 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6231 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6232 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6233 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6234 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6236 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6238 TmpInst.addOperand(Inst.getOperand(1)); // lane
6239 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6240 TmpInst.addOperand(Inst.getOperand(5));
6245 case ARM::VST4LNdAsm_8:
6246 case ARM::VST4LNdAsm_16:
6247 case ARM::VST4LNdAsm_32:
6248 case ARM::VST4LNqAsm_16:
6249 case ARM::VST4LNqAsm_32: {
6251 // Shuffle the operands around so the lane index operand is in the
6254 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6255 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6256 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6257 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6258 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6260 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6262 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6264 TmpInst.addOperand(Inst.getOperand(1)); // lane
6265 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6266 TmpInst.addOperand(Inst.getOperand(5));
6271 // Handle NEON VLD complex aliases.
6272 case ARM::VLD1LNdWB_register_Asm_8:
6273 case ARM::VLD1LNdWB_register_Asm_16:
6274 case ARM::VLD1LNdWB_register_Asm_32: {
6276 // Shuffle the operands around so the lane index operand is in the
6279 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6280 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6281 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6282 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6283 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6284 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6285 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6286 TmpInst.addOperand(Inst.getOperand(1)); // lane
6287 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6288 TmpInst.addOperand(Inst.getOperand(6));
6293 case ARM::VLD2LNdWB_register_Asm_8:
6294 case ARM::VLD2LNdWB_register_Asm_16:
6295 case ARM::VLD2LNdWB_register_Asm_32:
6296 case ARM::VLD2LNqWB_register_Asm_16:
6297 case ARM::VLD2LNqWB_register_Asm_32: {
6299 // Shuffle the operands around so the lane index operand is in the
6302 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6303 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6306 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6307 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6308 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6309 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6310 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6311 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6313 TmpInst.addOperand(Inst.getOperand(1)); // lane
6314 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6315 TmpInst.addOperand(Inst.getOperand(6));
6320 case ARM::VLD3LNdWB_register_Asm_8:
6321 case ARM::VLD3LNdWB_register_Asm_16:
6322 case ARM::VLD3LNdWB_register_Asm_32:
6323 case ARM::VLD3LNqWB_register_Asm_16:
6324 case ARM::VLD3LNqWB_register_Asm_32: {
6326 // Shuffle the operands around so the lane index operand is in the
6329 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6330 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6331 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6335 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6336 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6337 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6338 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6339 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6340 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6342 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6344 TmpInst.addOperand(Inst.getOperand(1)); // lane
6345 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6346 TmpInst.addOperand(Inst.getOperand(6));
6351 case ARM::VLD4LNdWB_register_Asm_8:
6352 case ARM::VLD4LNdWB_register_Asm_16:
6353 case ARM::VLD4LNdWB_register_Asm_32:
6354 case ARM::VLD4LNqWB_register_Asm_16:
6355 case ARM::VLD4LNqWB_register_Asm_32: {
6357 // Shuffle the operands around so the lane index operand is in the
6360 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6361 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6362 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6368 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6369 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6370 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6371 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6372 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6375 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6377 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6379 TmpInst.addOperand(Inst.getOperand(1)); // lane
6380 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6381 TmpInst.addOperand(Inst.getOperand(6));
6386 case ARM::VLD1LNdWB_fixed_Asm_8:
6387 case ARM::VLD1LNdWB_fixed_Asm_16:
6388 case ARM::VLD1LNdWB_fixed_Asm_32: {
6390 // Shuffle the operands around so the lane index operand is in the
6393 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6394 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6395 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6396 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6397 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6398 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6399 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6400 TmpInst.addOperand(Inst.getOperand(1)); // lane
6401 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6402 TmpInst.addOperand(Inst.getOperand(5));
6407 case ARM::VLD2LNdWB_fixed_Asm_8:
6408 case ARM::VLD2LNdWB_fixed_Asm_16:
6409 case ARM::VLD2LNdWB_fixed_Asm_32:
6410 case ARM::VLD2LNqWB_fixed_Asm_16:
6411 case ARM::VLD2LNqWB_fixed_Asm_32: {
6413 // Shuffle the operands around so the lane index operand is in the
6416 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6417 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6418 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6420 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6421 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6422 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6423 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6424 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6425 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6427 TmpInst.addOperand(Inst.getOperand(1)); // lane
6428 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6429 TmpInst.addOperand(Inst.getOperand(5));
6434 case ARM::VLD3LNdWB_fixed_Asm_8:
6435 case ARM::VLD3LNdWB_fixed_Asm_16:
6436 case ARM::VLD3LNdWB_fixed_Asm_32:
6437 case ARM::VLD3LNqWB_fixed_Asm_16:
6438 case ARM::VLD3LNqWB_fixed_Asm_32: {
6440 // Shuffle the operands around so the lane index operand is in the
6443 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6444 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6445 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6447 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6449 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6450 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6451 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6452 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6453 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6454 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6456 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6458 TmpInst.addOperand(Inst.getOperand(1)); // lane
6459 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6460 TmpInst.addOperand(Inst.getOperand(5));
6465 case ARM::VLD4LNdWB_fixed_Asm_8:
6466 case ARM::VLD4LNdWB_fixed_Asm_16:
6467 case ARM::VLD4LNdWB_fixed_Asm_32:
6468 case ARM::VLD4LNqWB_fixed_Asm_16:
6469 case ARM::VLD4LNqWB_fixed_Asm_32: {
6471 // Shuffle the operands around so the lane index operand is in the
6474 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6475 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6476 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6478 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6480 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6482 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6483 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6484 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6485 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6486 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6487 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6489 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6491 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6493 TmpInst.addOperand(Inst.getOperand(1)); // lane
6494 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6495 TmpInst.addOperand(Inst.getOperand(5));
6500 case ARM::VLD1LNdAsm_8:
6501 case ARM::VLD1LNdAsm_16:
6502 case ARM::VLD1LNdAsm_32: {
6504 // Shuffle the operands around so the lane index operand is in the
6507 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6508 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6509 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6510 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6511 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6512 TmpInst.addOperand(Inst.getOperand(1)); // lane
6513 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6514 TmpInst.addOperand(Inst.getOperand(5));
6519 case ARM::VLD2LNdAsm_8:
6520 case ARM::VLD2LNdAsm_16:
6521 case ARM::VLD2LNdAsm_32:
6522 case ARM::VLD2LNqAsm_16:
6523 case ARM::VLD2LNqAsm_32: {
6525 // Shuffle the operands around so the lane index operand is in the
6528 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6529 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6532 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6533 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6534 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6535 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6537 TmpInst.addOperand(Inst.getOperand(1)); // lane
6538 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6539 TmpInst.addOperand(Inst.getOperand(5));
6544 case ARM::VLD3LNdAsm_8:
6545 case ARM::VLD3LNdAsm_16:
6546 case ARM::VLD3LNdAsm_32:
6547 case ARM::VLD3LNqAsm_16:
6548 case ARM::VLD3LNqAsm_32: {
6550 // Shuffle the operands around so the lane index operand is in the
6553 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6554 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6555 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6557 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6559 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6560 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6561 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6562 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6564 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6566 TmpInst.addOperand(Inst.getOperand(1)); // lane
6567 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6568 TmpInst.addOperand(Inst.getOperand(5));
6573 case ARM::VLD4LNdAsm_8:
6574 case ARM::VLD4LNdAsm_16:
6575 case ARM::VLD4LNdAsm_32:
6576 case ARM::VLD4LNqAsm_16:
6577 case ARM::VLD4LNqAsm_32: {
6579 // Shuffle the operands around so the lane index operand is in the
6582 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6583 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6584 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6586 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6588 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6590 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6591 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6592 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6593 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6599 TmpInst.addOperand(Inst.getOperand(1)); // lane
6600 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6601 TmpInst.addOperand(Inst.getOperand(5));
6606 // VLD3DUP single 3-element structure to all lanes instructions.
6607 case ARM::VLD3DUPdAsm_8:
6608 case ARM::VLD3DUPdAsm_16:
6609 case ARM::VLD3DUPdAsm_32:
6610 case ARM::VLD3DUPqAsm_8:
6611 case ARM::VLD3DUPqAsm_16:
6612 case ARM::VLD3DUPqAsm_32: {
6615 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6616 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6617 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6621 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6622 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6623 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6624 TmpInst.addOperand(Inst.getOperand(4));
6629 case ARM::VLD3DUPdWB_fixed_Asm_8:
6630 case ARM::VLD3DUPdWB_fixed_Asm_16:
6631 case ARM::VLD3DUPdWB_fixed_Asm_32:
6632 case ARM::VLD3DUPqWB_fixed_Asm_8:
6633 case ARM::VLD3DUPqWB_fixed_Asm_16:
6634 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6637 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6638 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6639 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6643 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6644 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6645 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6646 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6647 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6648 TmpInst.addOperand(Inst.getOperand(4));
6653 case ARM::VLD3DUPdWB_register_Asm_8:
6654 case ARM::VLD3DUPdWB_register_Asm_16:
6655 case ARM::VLD3DUPdWB_register_Asm_32:
6656 case ARM::VLD3DUPqWB_register_Asm_8:
6657 case ARM::VLD3DUPqWB_register_Asm_16:
6658 case ARM::VLD3DUPqWB_register_Asm_32: {
6661 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6662 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6663 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6665 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6667 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6668 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6669 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6670 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6671 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6672 TmpInst.addOperand(Inst.getOperand(5));
6677 // VLD3 multiple 3-element structure instructions.
6678 case ARM::VLD3dAsm_8:
6679 case ARM::VLD3dAsm_16:
6680 case ARM::VLD3dAsm_32:
6681 case ARM::VLD3qAsm_8:
6682 case ARM::VLD3qAsm_16:
6683 case ARM::VLD3qAsm_32: {
6686 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6687 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6688 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6690 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6692 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6693 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6694 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6695 TmpInst.addOperand(Inst.getOperand(4));
6700 case ARM::VLD3dWB_fixed_Asm_8:
6701 case ARM::VLD3dWB_fixed_Asm_16:
6702 case ARM::VLD3dWB_fixed_Asm_32:
6703 case ARM::VLD3qWB_fixed_Asm_8:
6704 case ARM::VLD3qWB_fixed_Asm_16:
6705 case ARM::VLD3qWB_fixed_Asm_32: {
6708 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6709 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6710 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6712 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6714 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6715 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6716 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6717 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6718 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6719 TmpInst.addOperand(Inst.getOperand(4));
6724 case ARM::VLD3dWB_register_Asm_8:
6725 case ARM::VLD3dWB_register_Asm_16:
6726 case ARM::VLD3dWB_register_Asm_32:
6727 case ARM::VLD3qWB_register_Asm_8:
6728 case ARM::VLD3qWB_register_Asm_16:
6729 case ARM::VLD3qWB_register_Asm_32: {
6732 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6733 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6734 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6736 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6738 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6739 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6740 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6741 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6742 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6743 TmpInst.addOperand(Inst.getOperand(5));
6748 // VLD4DUP single 3-element structure to all lanes instructions.
6749 case ARM::VLD4DUPdAsm_8:
6750 case ARM::VLD4DUPdAsm_16:
6751 case ARM::VLD4DUPdAsm_32:
6752 case ARM::VLD4DUPqAsm_8:
6753 case ARM::VLD4DUPqAsm_16:
6754 case ARM::VLD4DUPqAsm_32: {
6757 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6758 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6759 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6761 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6763 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6765 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6766 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6767 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6768 TmpInst.addOperand(Inst.getOperand(4));
6773 case ARM::VLD4DUPdWB_fixed_Asm_8:
6774 case ARM::VLD4DUPdWB_fixed_Asm_16:
6775 case ARM::VLD4DUPdWB_fixed_Asm_32:
6776 case ARM::VLD4DUPqWB_fixed_Asm_8:
6777 case ARM::VLD4DUPqWB_fixed_Asm_16:
6778 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6781 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6782 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6783 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6785 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6787 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6789 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6790 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6791 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6792 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6793 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6794 TmpInst.addOperand(Inst.getOperand(4));
6799 case ARM::VLD4DUPdWB_register_Asm_8:
6800 case ARM::VLD4DUPdWB_register_Asm_16:
6801 case ARM::VLD4DUPdWB_register_Asm_32:
6802 case ARM::VLD4DUPqWB_register_Asm_8:
6803 case ARM::VLD4DUPqWB_register_Asm_16:
6804 case ARM::VLD4DUPqWB_register_Asm_32: {
6807 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6808 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6809 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6811 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6813 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6815 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6816 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6817 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6818 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6819 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6820 TmpInst.addOperand(Inst.getOperand(5));
6825 // VLD4 multiple 4-element structure instructions.
6826 case ARM::VLD4dAsm_8:
6827 case ARM::VLD4dAsm_16:
6828 case ARM::VLD4dAsm_32:
6829 case ARM::VLD4qAsm_8:
6830 case ARM::VLD4qAsm_16:
6831 case ARM::VLD4qAsm_32: {
6834 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6835 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6836 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6838 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6840 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6842 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6843 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6844 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6845 TmpInst.addOperand(Inst.getOperand(4));
6850 case ARM::VLD4dWB_fixed_Asm_8:
6851 case ARM::VLD4dWB_fixed_Asm_16:
6852 case ARM::VLD4dWB_fixed_Asm_32:
6853 case ARM::VLD4qWB_fixed_Asm_8:
6854 case ARM::VLD4qWB_fixed_Asm_16:
6855 case ARM::VLD4qWB_fixed_Asm_32: {
6858 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6859 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6860 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6862 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6864 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6866 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6867 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6868 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6869 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6870 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6871 TmpInst.addOperand(Inst.getOperand(4));
6876 case ARM::VLD4dWB_register_Asm_8:
6877 case ARM::VLD4dWB_register_Asm_16:
6878 case ARM::VLD4dWB_register_Asm_32:
6879 case ARM::VLD4qWB_register_Asm_8:
6880 case ARM::VLD4qWB_register_Asm_16:
6881 case ARM::VLD4qWB_register_Asm_32: {
6884 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6885 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6886 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6888 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6890 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6892 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6893 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6894 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6895 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6896 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6897 TmpInst.addOperand(Inst.getOperand(5));
6902 // VST3 multiple 3-element structure instructions.
6903 case ARM::VST3dAsm_8:
6904 case ARM::VST3dAsm_16:
6905 case ARM::VST3dAsm_32:
6906 case ARM::VST3qAsm_8:
6907 case ARM::VST3qAsm_16:
6908 case ARM::VST3qAsm_32: {
6911 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6912 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6913 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6914 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6915 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6917 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6919 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6920 TmpInst.addOperand(Inst.getOperand(4));
6925 case ARM::VST3dWB_fixed_Asm_8:
6926 case ARM::VST3dWB_fixed_Asm_16:
6927 case ARM::VST3dWB_fixed_Asm_32:
6928 case ARM::VST3qWB_fixed_Asm_8:
6929 case ARM::VST3qWB_fixed_Asm_16:
6930 case ARM::VST3qWB_fixed_Asm_32: {
6933 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6934 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6935 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6936 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6937 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6938 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6939 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6941 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6943 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6944 TmpInst.addOperand(Inst.getOperand(4));
6949 case ARM::VST3dWB_register_Asm_8:
6950 case ARM::VST3dWB_register_Asm_16:
6951 case ARM::VST3dWB_register_Asm_32:
6952 case ARM::VST3qWB_register_Asm_8:
6953 case ARM::VST3qWB_register_Asm_16:
6954 case ARM::VST3qWB_register_Asm_32: {
6957 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6958 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6959 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6960 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6961 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6962 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6963 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6965 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6967 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6968 TmpInst.addOperand(Inst.getOperand(5));
6973 // VST4 multiple 3-element structure instructions.
6974 case ARM::VST4dAsm_8:
6975 case ARM::VST4dAsm_16:
6976 case ARM::VST4dAsm_32:
6977 case ARM::VST4qAsm_8:
6978 case ARM::VST4qAsm_16:
6979 case ARM::VST4qAsm_32: {
6982 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6983 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6984 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6985 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6986 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6988 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6990 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6992 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6993 TmpInst.addOperand(Inst.getOperand(4));
6998 case ARM::VST4dWB_fixed_Asm_8:
6999 case ARM::VST4dWB_fixed_Asm_16:
7000 case ARM::VST4dWB_fixed_Asm_32:
7001 case ARM::VST4qWB_fixed_Asm_8:
7002 case ARM::VST4qWB_fixed_Asm_16:
7003 case ARM::VST4qWB_fixed_Asm_32: {
7006 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7007 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7008 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7009 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7010 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7011 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7012 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7014 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7016 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7018 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7019 TmpInst.addOperand(Inst.getOperand(4));
7024 case ARM::VST4dWB_register_Asm_8:
7025 case ARM::VST4dWB_register_Asm_16:
7026 case ARM::VST4dWB_register_Asm_32:
7027 case ARM::VST4qWB_register_Asm_8:
7028 case ARM::VST4qWB_register_Asm_16:
7029 case ARM::VST4qWB_register_Asm_32: {
7032 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7033 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7034 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7035 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7036 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7037 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7038 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7040 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7042 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7044 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7045 TmpInst.addOperand(Inst.getOperand(5));
7050 // Handle encoding choice for the shift-immediate instructions.
7053 case ARM::t2ASRri: {
7054 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7055 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7056 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7057 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7058 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7060 switch (Inst.getOpcode()) {
7061 default: llvm_unreachable("unexpected opcode");
7062 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7063 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7064 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7066 // The Thumb1 operands aren't in the same order. Awesome, eh?
7068 TmpInst.setOpcode(NewOpc);
7069 TmpInst.addOperand(Inst.getOperand(0));
7070 TmpInst.addOperand(Inst.getOperand(5));
7071 TmpInst.addOperand(Inst.getOperand(1));
7072 TmpInst.addOperand(Inst.getOperand(2));
7073 TmpInst.addOperand(Inst.getOperand(3));
7074 TmpInst.addOperand(Inst.getOperand(4));
7081 // Handle the Thumb2 mode MOV complex aliases.
7083 case ARM::t2MOVSsr: {
7084 // Which instruction to expand to depends on the CCOut operand and
7085 // whether we're in an IT block if the register operands are low
7087 bool isNarrow = false;
7088 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7089 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7090 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7091 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7092 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7096 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7097 default: llvm_unreachable("unexpected opcode!");
7098 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7099 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7100 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7101 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7103 TmpInst.setOpcode(newOpc);
7104 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7106 TmpInst.addOperand(MCOperand::CreateReg(
7107 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7108 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7109 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7110 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7111 TmpInst.addOperand(Inst.getOperand(5));
7113 TmpInst.addOperand(MCOperand::CreateReg(
7114 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7119 case ARM::t2MOVSsi: {
7120 // Which instruction to expand to depends on the CCOut operand and
7121 // whether we're in an IT block if the register operands are low
7123 bool isNarrow = false;
7124 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7125 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7126 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7130 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7131 default: llvm_unreachable("unexpected opcode!");
7132 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7133 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7134 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7135 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7136 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7138 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7139 if (Amount == 32) Amount = 0;
7140 TmpInst.setOpcode(newOpc);
7141 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7143 TmpInst.addOperand(MCOperand::CreateReg(
7144 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7145 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7146 if (newOpc != ARM::t2RRX)
7147 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7148 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7149 TmpInst.addOperand(Inst.getOperand(4));
7151 TmpInst.addOperand(MCOperand::CreateReg(
7152 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7156 // Handle the ARM mode MOV complex aliases.
7161 ARM_AM::ShiftOpc ShiftTy;
7162 switch(Inst.getOpcode()) {
7163 default: llvm_unreachable("unexpected opcode!");
7164 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7165 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7166 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7167 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7169 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7171 TmpInst.setOpcode(ARM::MOVsr);
7172 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7173 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7174 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7175 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7176 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7177 TmpInst.addOperand(Inst.getOperand(4));
7178 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7186 ARM_AM::ShiftOpc ShiftTy;
7187 switch(Inst.getOpcode()) {
7188 default: llvm_unreachable("unexpected opcode!");
7189 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7190 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7191 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7192 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7194 // A shift by zero is a plain MOVr, not a MOVsi.
7195 unsigned Amt = Inst.getOperand(2).getImm();
7196 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7197 // A shift by 32 should be encoded as 0 when permitted
7198 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7200 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7202 TmpInst.setOpcode(Opc);
7203 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7204 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7205 if (Opc == ARM::MOVsi)
7206 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7207 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7208 TmpInst.addOperand(Inst.getOperand(4));
7209 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7214 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7216 TmpInst.setOpcode(ARM::MOVsi);
7217 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7218 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7219 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7220 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7221 TmpInst.addOperand(Inst.getOperand(3));
7222 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7226 case ARM::t2LDMIA_UPD: {
7227 // If this is a load of a single register, then we should use
7228 // a post-indexed LDR instruction instead, per the ARM ARM.
7229 if (Inst.getNumOperands() != 5)
7232 TmpInst.setOpcode(ARM::t2LDR_POST);
7233 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7234 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7235 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7236 TmpInst.addOperand(MCOperand::CreateImm(4));
7237 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7238 TmpInst.addOperand(Inst.getOperand(3));
7242 case ARM::t2STMDB_UPD: {
7243 // If this is a store of a single register, then we should use
7244 // a pre-indexed STR instruction instead, per the ARM ARM.
7245 if (Inst.getNumOperands() != 5)
7248 TmpInst.setOpcode(ARM::t2STR_PRE);
7249 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7250 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7251 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7252 TmpInst.addOperand(MCOperand::CreateImm(-4));
7253 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7254 TmpInst.addOperand(Inst.getOperand(3));
7258 case ARM::LDMIA_UPD:
7259 // If this is a load of a single register via a 'pop', then we should use
7260 // a post-indexed LDR instruction instead, per the ARM ARM.
7261 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7262 Inst.getNumOperands() == 5) {
7264 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7265 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7266 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7267 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7268 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7269 TmpInst.addOperand(MCOperand::CreateImm(4));
7270 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7271 TmpInst.addOperand(Inst.getOperand(3));
7276 case ARM::STMDB_UPD:
7277 // If this is a store of a single register via a 'push', then we should use
7278 // a pre-indexed STR instruction instead, per the ARM ARM.
7279 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7280 Inst.getNumOperands() == 5) {
7282 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7283 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7284 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7285 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7286 TmpInst.addOperand(MCOperand::CreateImm(-4));
7287 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7288 TmpInst.addOperand(Inst.getOperand(3));
7292 case ARM::t2ADDri12:
7293 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7294 // mnemonic was used (not "addw"), encoding T3 is preferred.
7295 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7296 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7298 Inst.setOpcode(ARM::t2ADDri);
7299 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7301 case ARM::t2SUBri12:
7302 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7303 // mnemonic was used (not "subw"), encoding T3 is preferred.
7304 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7305 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7307 Inst.setOpcode(ARM::t2SUBri);
7308 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7311 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7312 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7313 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7314 // to encoding T1 if <Rd> is omitted."
7315 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7316 Inst.setOpcode(ARM::tADDi3);
7321 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7322 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7323 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7324 // to encoding T1 if <Rd> is omitted."
7325 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7326 Inst.setOpcode(ARM::tSUBi3);
7331 case ARM::t2SUBri: {
7332 // If the destination and first source operand are the same, and
7333 // the flags are compatible with the current IT status, use encoding T2
7334 // instead of T3. For compatibility with the system 'as'. Make sure the
7335 // wide encoding wasn't explicit.
7336 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7337 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7338 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7339 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7340 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7341 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7342 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7345 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7346 ARM::tADDi8 : ARM::tSUBi8);
7347 TmpInst.addOperand(Inst.getOperand(0));
7348 TmpInst.addOperand(Inst.getOperand(5));
7349 TmpInst.addOperand(Inst.getOperand(0));
7350 TmpInst.addOperand(Inst.getOperand(2));
7351 TmpInst.addOperand(Inst.getOperand(3));
7352 TmpInst.addOperand(Inst.getOperand(4));
7356 case ARM::t2ADDrr: {
7357 // If the destination and first source operand are the same, and
7358 // there's no setting of the flags, use encoding T2 instead of T3.
7359 // Note that this is only for ADD, not SUB. This mirrors the system
7360 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7361 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7362 Inst.getOperand(5).getReg() != 0 ||
7363 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7364 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7367 TmpInst.setOpcode(ARM::tADDhirr);
7368 TmpInst.addOperand(Inst.getOperand(0));
7369 TmpInst.addOperand(Inst.getOperand(0));
7370 TmpInst.addOperand(Inst.getOperand(2));
7371 TmpInst.addOperand(Inst.getOperand(3));
7372 TmpInst.addOperand(Inst.getOperand(4));
7376 case ARM::tADDrSP: {
7377 // If the non-SP source operand and the destination operand are not the
7378 // same, we need to use the 32-bit encoding if it's available.
7379 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7380 Inst.setOpcode(ARM::t2ADDrr);
7381 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7387 // A Thumb conditional branch outside of an IT block is a tBcc.
7388 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7389 Inst.setOpcode(ARM::tBcc);
7394 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7395 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7396 Inst.setOpcode(ARM::t2Bcc);
7401 // If the conditional is AL or we're in an IT block, we really want t2B.
7402 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7403 Inst.setOpcode(ARM::t2B);
7408 // If the conditional is AL, we really want tB.
7409 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7410 Inst.setOpcode(ARM::tB);
7415 // If the register list contains any high registers, or if the writeback
7416 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7417 // instead if we're in Thumb2. Otherwise, this should have generated
7418 // an error in validateInstruction().
7419 unsigned Rn = Inst.getOperand(0).getReg();
7420 bool hasWritebackToken =
7421 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7422 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7423 bool listContainsBase;
7424 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7425 (!listContainsBase && !hasWritebackToken) ||
7426 (listContainsBase && hasWritebackToken)) {
7427 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7428 assert (isThumbTwo());
7429 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7430 // If we're switching to the updating version, we need to insert
7431 // the writeback tied operand.
7432 if (hasWritebackToken)
7433 Inst.insert(Inst.begin(),
7434 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7439 case ARM::tSTMIA_UPD: {
7440 // If the register list contains any high registers, we need to use
7441 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7442 // should have generated an error in validateInstruction().
7443 unsigned Rn = Inst.getOperand(0).getReg();
7444 bool listContainsBase;
7445 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7446 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7447 assert (isThumbTwo());
7448 Inst.setOpcode(ARM::t2STMIA_UPD);
7454 bool listContainsBase;
7455 // If the register list contains any high registers, we need to use
7456 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7457 // should have generated an error in validateInstruction().
7458 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7460 assert (isThumbTwo());
7461 Inst.setOpcode(ARM::t2LDMIA_UPD);
7462 // Add the base register and writeback operands.
7463 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7464 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7468 bool listContainsBase;
7469 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7471 assert (isThumbTwo());
7472 Inst.setOpcode(ARM::t2STMDB_UPD);
7473 // Add the base register and writeback operands.
7474 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7475 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7479 // If we can use the 16-bit encoding and the user didn't explicitly
7480 // request the 32-bit variant, transform it here.
7481 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7482 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7483 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7484 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7485 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7486 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7487 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7488 // The operands aren't in the same order for tMOVi8...
7490 TmpInst.setOpcode(ARM::tMOVi8);
7491 TmpInst.addOperand(Inst.getOperand(0));
7492 TmpInst.addOperand(Inst.getOperand(4));
7493 TmpInst.addOperand(Inst.getOperand(1));
7494 TmpInst.addOperand(Inst.getOperand(2));
7495 TmpInst.addOperand(Inst.getOperand(3));
7502 // If we can use the 16-bit encoding and the user didn't explicitly
7503 // request the 32-bit variant, transform it here.
7504 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7505 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7506 Inst.getOperand(2).getImm() == ARMCC::AL &&
7507 Inst.getOperand(4).getReg() == ARM::CPSR &&
7508 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7509 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7510 // The operands aren't the same for tMOV[S]r... (no cc_out)
7512 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7513 TmpInst.addOperand(Inst.getOperand(0));
7514 TmpInst.addOperand(Inst.getOperand(1));
7515 TmpInst.addOperand(Inst.getOperand(2));
7516 TmpInst.addOperand(Inst.getOperand(3));
7526 // If we can use the 16-bit encoding and the user didn't explicitly
7527 // request the 32-bit variant, transform it here.
7528 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7529 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7530 Inst.getOperand(2).getImm() == 0 &&
7531 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7532 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7534 switch (Inst.getOpcode()) {
7535 default: llvm_unreachable("Illegal opcode!");
7536 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7537 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7538 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7539 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7541 // The operands aren't the same for thumb1 (no rotate operand).
7543 TmpInst.setOpcode(NewOpc);
7544 TmpInst.addOperand(Inst.getOperand(0));
7545 TmpInst.addOperand(Inst.getOperand(1));
7546 TmpInst.addOperand(Inst.getOperand(3));
7547 TmpInst.addOperand(Inst.getOperand(4));
7554 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7555 // rrx shifts and asr/lsr of #32 is encoded as 0
7556 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7558 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7559 // Shifting by zero is accepted as a vanilla 'MOVr'
7561 TmpInst.setOpcode(ARM::MOVr);
7562 TmpInst.addOperand(Inst.getOperand(0));
7563 TmpInst.addOperand(Inst.getOperand(1));
7564 TmpInst.addOperand(Inst.getOperand(3));
7565 TmpInst.addOperand(Inst.getOperand(4));
7566 TmpInst.addOperand(Inst.getOperand(5));
7579 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7580 if (SOpc == ARM_AM::rrx) return false;
7581 switch (Inst.getOpcode()) {
7582 default: llvm_unreachable("unexpected opcode!");
7583 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7584 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7585 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7586 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7587 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7588 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7590 // If the shift is by zero, use the non-shifted instruction definition.
7591 // The exception is for right shifts, where 0 == 32
7592 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7593 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7595 TmpInst.setOpcode(newOpc);
7596 TmpInst.addOperand(Inst.getOperand(0));
7597 TmpInst.addOperand(Inst.getOperand(1));
7598 TmpInst.addOperand(Inst.getOperand(2));
7599 TmpInst.addOperand(Inst.getOperand(4));
7600 TmpInst.addOperand(Inst.getOperand(5));
7601 TmpInst.addOperand(Inst.getOperand(6));
7609 // The mask bits for all but the first condition are represented as
7610 // the low bit of the condition code value implies 't'. We currently
7611 // always have 1 implies 't', so XOR toggle the bits if the low bit
7612 // of the condition code is zero.
7613 MCOperand &MO = Inst.getOperand(1);
7614 unsigned Mask = MO.getImm();
7615 unsigned OrigMask = Mask;
7616 unsigned TZ = countTrailingZeros(Mask);
7617 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7618 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7619 Mask ^= (0xE << TZ) & 0xF;
7623 // Set up the IT block state according to the IT instruction we just
7625 assert(!inITBlock() && "nested IT blocks?!");
7626 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7627 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7628 ITState.CurPosition = 0;
7629 ITState.FirstCond = true;
7639 // Assemblers should use the narrow encodings of these instructions when permissible.
7640 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7641 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7642 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7643 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7644 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7645 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7646 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7648 switch (Inst.getOpcode()) {
7649 default: llvm_unreachable("unexpected opcode");
7650 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7651 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7652 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7653 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7654 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7655 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7658 TmpInst.setOpcode(NewOpc);
7659 TmpInst.addOperand(Inst.getOperand(0));
7660 TmpInst.addOperand(Inst.getOperand(5));
7661 TmpInst.addOperand(Inst.getOperand(1));
7662 TmpInst.addOperand(Inst.getOperand(2));
7663 TmpInst.addOperand(Inst.getOperand(3));
7664 TmpInst.addOperand(Inst.getOperand(4));
7675 // Assemblers should use the narrow encodings of these instructions when permissible.
7676 // These instructions are special in that they are commutable, so shorter encodings
7677 // are available more often.
7678 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7679 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7680 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7681 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7682 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7683 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7684 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7685 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7687 switch (Inst.getOpcode()) {
7688 default: llvm_unreachable("unexpected opcode");
7689 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7690 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7691 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7692 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7695 TmpInst.setOpcode(NewOpc);
7696 TmpInst.addOperand(Inst.getOperand(0));
7697 TmpInst.addOperand(Inst.getOperand(5));
7698 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7699 TmpInst.addOperand(Inst.getOperand(1));
7700 TmpInst.addOperand(Inst.getOperand(2));
7702 TmpInst.addOperand(Inst.getOperand(2));
7703 TmpInst.addOperand(Inst.getOperand(1));
7705 TmpInst.addOperand(Inst.getOperand(3));
7706 TmpInst.addOperand(Inst.getOperand(4));
7716 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7717 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7718 // suffix depending on whether they're in an IT block or not.
7719 unsigned Opc = Inst.getOpcode();
7720 const MCInstrDesc &MCID = MII.get(Opc);
7721 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7722 assert(MCID.hasOptionalDef() &&
7723 "optionally flag setting instruction missing optional def operand");
7724 assert(MCID.NumOperands == Inst.getNumOperands() &&
7725 "operand count mismatch!");
7726 // Find the optional-def operand (cc_out).
7729 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7732 // If we're parsing Thumb1, reject it completely.
7733 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7734 return Match_MnemonicFail;
7735 // If we're parsing Thumb2, which form is legal depends on whether we're
7737 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7739 return Match_RequiresITBlock;
7740 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7742 return Match_RequiresNotITBlock;
7744 // Some high-register supporting Thumb1 encodings only allow both registers
7745 // to be from r0-r7 when in Thumb2.
7746 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7747 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7748 isARMLowRegister(Inst.getOperand(2).getReg()))
7749 return Match_RequiresThumb2;
7750 // Others only require ARMv6 or later.
7751 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7752 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7753 isARMLowRegister(Inst.getOperand(1).getReg()))
7754 return Match_RequiresV6;
7755 return Match_Success;
7758 static const char *getSubtargetFeatureName(unsigned Val);
7760 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7761 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7762 MCStreamer &Out, unsigned &ErrorInfo,
7763 bool MatchingInlineAsm) {
7765 unsigned MatchResult;
7767 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7769 switch (MatchResult) {
7772 // Context sensitive operand constraints aren't handled by the matcher,
7773 // so check them here.
7774 if (validateInstruction(Inst, Operands)) {
7775 // Still progress the IT block, otherwise one wrong condition causes
7776 // nasty cascading errors.
7777 forwardITPosition();
7781 { // processInstruction() updates inITBlock state, we need to save it away
7782 bool wasInITBlock = inITBlock();
7784 // Some instructions need post-processing to, for example, tweak which
7785 // encoding is selected. Loop on it while changes happen so the
7786 // individual transformations can chain off each other. E.g.,
7787 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7788 while (processInstruction(Inst, Operands))
7791 // Only after the instruction is fully processed, we can validate it
7792 if (wasInITBlock && hasV8Ops() && isThumb() &&
7793 !isV8EligibleForIT(&Inst, 2)) {
7794 Warning(IDLoc, "deprecated instruction in IT block");
7798 // Only move forward at the very end so that everything in validate
7799 // and process gets a consistent answer about whether we're in an IT
7801 forwardITPosition();
7803 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7804 // doesn't actually encode.
7805 if (Inst.getOpcode() == ARM::ITasm)
7809 Out.EmitInstruction(Inst);
7811 case Match_MissingFeature: {
7812 assert(ErrorInfo && "Unknown missing feature!");
7813 // Special case the error message for the very common case where only
7814 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7815 std::string Msg = "instruction requires:";
7817 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7818 if (ErrorInfo & Mask) {
7820 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7824 return Error(IDLoc, Msg);
7826 case Match_InvalidOperand: {
7827 SMLoc ErrorLoc = IDLoc;
7828 if (ErrorInfo != ~0U) {
7829 if (ErrorInfo >= Operands.size())
7830 return Error(IDLoc, "too few operands for instruction");
7832 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7833 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7836 return Error(ErrorLoc, "invalid operand for instruction");
7838 case Match_MnemonicFail:
7839 return Error(IDLoc, "invalid instruction",
7840 ((ARMOperand*)Operands[0])->getLocRange());
7841 case Match_RequiresNotITBlock:
7842 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7843 case Match_RequiresITBlock:
7844 return Error(IDLoc, "instruction only valid inside IT block");
7845 case Match_RequiresV6:
7846 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7847 case Match_RequiresThumb2:
7848 return Error(IDLoc, "instruction variant requires Thumb2");
7849 case Match_ImmRange0_15: {
7850 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7851 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7852 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7854 case Match_ImmRange0_239: {
7855 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7856 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7857 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7861 llvm_unreachable("Implement any new match types added!");
7864 /// parseDirective parses the arm specific directives
7865 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7866 StringRef IDVal = DirectiveID.getIdentifier();
7867 if (IDVal == ".word")
7868 return parseDirectiveWord(4, DirectiveID.getLoc());
7869 else if (IDVal == ".thumb")
7870 return parseDirectiveThumb(DirectiveID.getLoc());
7871 else if (IDVal == ".arm")
7872 return parseDirectiveARM(DirectiveID.getLoc());
7873 else if (IDVal == ".thumb_func")
7874 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7875 else if (IDVal == ".code")
7876 return parseDirectiveCode(DirectiveID.getLoc());
7877 else if (IDVal == ".syntax")
7878 return parseDirectiveSyntax(DirectiveID.getLoc());
7879 else if (IDVal == ".unreq")
7880 return parseDirectiveUnreq(DirectiveID.getLoc());
7881 else if (IDVal == ".arch")
7882 return parseDirectiveArch(DirectiveID.getLoc());
7883 else if (IDVal == ".eabi_attribute")
7884 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7885 else if (IDVal == ".cpu")
7886 return parseDirectiveCPU(DirectiveID.getLoc());
7887 else if (IDVal == ".fpu")
7888 return parseDirectiveFPU(DirectiveID.getLoc());
7889 else if (IDVal == ".fnstart")
7890 return parseDirectiveFnStart(DirectiveID.getLoc());
7891 else if (IDVal == ".fnend")
7892 return parseDirectiveFnEnd(DirectiveID.getLoc());
7893 else if (IDVal == ".cantunwind")
7894 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7895 else if (IDVal == ".personality")
7896 return parseDirectivePersonality(DirectiveID.getLoc());
7897 else if (IDVal == ".handlerdata")
7898 return parseDirectiveHandlerData(DirectiveID.getLoc());
7899 else if (IDVal == ".setfp")
7900 return parseDirectiveSetFP(DirectiveID.getLoc());
7901 else if (IDVal == ".pad")
7902 return parseDirectivePad(DirectiveID.getLoc());
7903 else if (IDVal == ".save")
7904 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7905 else if (IDVal == ".vsave")
7906 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7907 else if (IDVal == ".inst")
7908 return parseDirectiveInst(DirectiveID.getLoc());
7909 else if (IDVal == ".inst.n")
7910 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
7911 else if (IDVal == ".inst.w")
7912 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
7913 else if (IDVal == ".ltorg")
7914 return parseDirectiveLtorg(DirectiveID.getLoc());
7918 /// parseDirectiveWord
7919 /// ::= .word [ expression (, expression)* ]
7920 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7921 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7923 const MCExpr *Value;
7924 if (getParser().parseExpression(Value))
7927 getParser().getStreamer().EmitValue(Value, Size);
7929 if (getLexer().is(AsmToken::EndOfStatement))
7932 // FIXME: Improve diagnostic.
7933 if (getLexer().isNot(AsmToken::Comma))
7934 return Error(L, "unexpected token in directive");
7943 /// parseDirectiveThumb
7945 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7946 if (getLexer().isNot(AsmToken::EndOfStatement))
7947 return Error(L, "unexpected token in directive");
7951 return Error(L, "target does not support Thumb mode");
7955 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7959 /// parseDirectiveARM
7961 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7962 if (getLexer().isNot(AsmToken::EndOfStatement))
7963 return Error(L, "unexpected token in directive");
7967 return Error(L, "target does not support ARM mode");
7971 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7975 void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
7976 if (NextSymbolIsThumb) {
7977 getParser().getStreamer().EmitThumbFunc(Symbol);
7978 NextSymbolIsThumb = false;
7982 /// parseDirectiveThumbFunc
7983 /// ::= .thumbfunc symbol_name
7984 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7985 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7986 bool isMachO = MAI->hasSubsectionsViaSymbols();
7988 // Darwin asm has (optionally) function name after .thumb_func direction
7991 const AsmToken &Tok = Parser.getTok();
7992 if (Tok.isNot(AsmToken::EndOfStatement)) {
7993 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7994 return Error(L, "unexpected token in .thumb_func directive");
7996 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
7997 getParser().getStreamer().EmitThumbFunc(Func);
7998 Parser.Lex(); // Consume the identifier token.
8003 if (getLexer().isNot(AsmToken::EndOfStatement))
8004 return Error(L, "unexpected token in directive");
8006 NextSymbolIsThumb = true;
8011 /// parseDirectiveSyntax
8012 /// ::= .syntax unified | divided
8013 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
8014 const AsmToken &Tok = Parser.getTok();
8015 if (Tok.isNot(AsmToken::Identifier))
8016 return Error(L, "unexpected token in .syntax directive");
8017 StringRef Mode = Tok.getString();
8018 if (Mode == "unified" || Mode == "UNIFIED")
8020 else if (Mode == "divided" || Mode == "DIVIDED")
8021 return Error(L, "'.syntax divided' arm asssembly not supported");
8023 return Error(L, "unrecognized syntax mode in .syntax directive");
8025 if (getLexer().isNot(AsmToken::EndOfStatement))
8026 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
8029 // TODO tell the MC streamer the mode
8030 // getParser().getStreamer().Emit???();
8034 /// parseDirectiveCode
8035 /// ::= .code 16 | 32
8036 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
8037 const AsmToken &Tok = Parser.getTok();
8038 if (Tok.isNot(AsmToken::Integer))
8039 return Error(L, "unexpected token in .code directive");
8040 int64_t Val = Parser.getTok().getIntVal();
8046 return Error(L, "invalid operand to .code directive");
8048 if (getLexer().isNot(AsmToken::EndOfStatement))
8049 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
8054 return Error(L, "target does not support Thumb mode");
8058 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8061 return Error(L, "target does not support ARM mode");
8065 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8071 /// parseDirectiveReq
8072 /// ::= name .req registername
8073 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8074 Parser.Lex(); // Eat the '.req' token.
8076 SMLoc SRegLoc, ERegLoc;
8077 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
8078 Parser.eatToEndOfStatement();
8079 return Error(SRegLoc, "register name expected");
8082 // Shouldn't be anything else.
8083 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
8084 Parser.eatToEndOfStatement();
8085 return Error(Parser.getTok().getLoc(),
8086 "unexpected input in .req directive.");
8089 Parser.Lex(); // Consume the EndOfStatement
8091 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
8092 return Error(SRegLoc, "redefinition of '" + Name +
8093 "' does not match original.");
8098 /// parseDirectiveUneq
8099 /// ::= .unreq registername
8100 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8101 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8102 Parser.eatToEndOfStatement();
8103 return Error(L, "unexpected input in .unreq directive.");
8105 RegisterReqs.erase(Parser.getTok().getIdentifier());
8106 Parser.Lex(); // Eat the identifier.
8110 /// parseDirectiveArch
8112 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8113 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8115 unsigned ID = StringSwitch<unsigned>(Arch)
8116 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8117 .Case(NAME, ARM::ID)
8118 #include "MCTargetDesc/ARMArchName.def"
8119 .Default(ARM::INVALID_ARCH);
8121 if (ID == ARM::INVALID_ARCH)
8122 return Error(L, "Unknown arch name");
8124 getTargetStreamer().emitArch(ID);
8128 /// parseDirectiveEabiAttr
8129 /// ::= .eabi_attribute int, int
8130 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8131 if (Parser.getTok().isNot(AsmToken::Integer))
8132 return Error(L, "integer expected");
8133 int64_t Tag = Parser.getTok().getIntVal();
8134 Parser.Lex(); // eat tag integer
8136 if (Parser.getTok().isNot(AsmToken::Comma))
8137 return Error(L, "comma expected");
8138 Parser.Lex(); // skip comma
8140 L = Parser.getTok().getLoc();
8141 if (Parser.getTok().isNot(AsmToken::Integer))
8142 return Error(L, "integer expected");
8143 int64_t Value = Parser.getTok().getIntVal();
8144 Parser.Lex(); // eat value integer
8146 getTargetStreamer().emitAttribute(Tag, Value);
8150 /// parseDirectiveCPU
8152 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8153 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8154 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8158 /// parseDirectiveFPU
8160 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8161 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8163 unsigned ID = StringSwitch<unsigned>(FPU)
8164 #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8165 #include "ARMFPUName.def"
8166 .Default(ARM::INVALID_FPU);
8168 if (ID == ARM::INVALID_FPU)
8169 return Error(L, "Unknown FPU name");
8171 getTargetStreamer().emitFPU(ID);
8175 /// parseDirectiveFnStart
8177 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8178 if (FnStartLoc.isValid()) {
8179 Error(L, ".fnstart starts before the end of previous one");
8180 Error(FnStartLoc, "previous .fnstart starts here");
8185 getTargetStreamer().emitFnStart();
8189 /// parseDirectiveFnEnd
8191 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8192 // Check the ordering of unwind directives
8193 if (!FnStartLoc.isValid())
8194 return Error(L, ".fnstart must precede .fnend directive");
8196 // Reset the unwind directives parser state
8197 resetUnwindDirectiveParserState();
8198 getTargetStreamer().emitFnEnd();
8202 /// parseDirectiveCantUnwind
8204 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8205 // Check the ordering of unwind directives
8207 if (!FnStartLoc.isValid())
8208 return Error(L, ".fnstart must precede .cantunwind directive");
8209 if (HandlerDataLoc.isValid()) {
8210 Error(L, ".cantunwind can't be used with .handlerdata directive");
8211 Error(HandlerDataLoc, ".handlerdata was specified here");
8214 if (PersonalityLoc.isValid()) {
8215 Error(L, ".cantunwind can't be used with .personality directive");
8216 Error(PersonalityLoc, ".personality was specified here");
8220 getTargetStreamer().emitCantUnwind();
8224 /// parseDirectivePersonality
8225 /// ::= .personality name
8226 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8227 // Check the ordering of unwind directives
8229 if (!FnStartLoc.isValid())
8230 return Error(L, ".fnstart must precede .personality directive");
8231 if (CantUnwindLoc.isValid()) {
8232 Error(L, ".personality can't be used with .cantunwind directive");
8233 Error(CantUnwindLoc, ".cantunwind was specified here");
8236 if (HandlerDataLoc.isValid()) {
8237 Error(L, ".personality must precede .handlerdata directive");
8238 Error(HandlerDataLoc, ".handlerdata was specified here");
8242 // Parse the name of the personality routine
8243 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8244 Parser.eatToEndOfStatement();
8245 return Error(L, "unexpected input in .personality directive.");
8247 StringRef Name(Parser.getTok().getIdentifier());
8250 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8251 getTargetStreamer().emitPersonality(PR);
8255 /// parseDirectiveHandlerData
8256 /// ::= .handlerdata
8257 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8258 // Check the ordering of unwind directives
8260 if (!FnStartLoc.isValid())
8261 return Error(L, ".fnstart must precede .personality directive");
8262 if (CantUnwindLoc.isValid()) {
8263 Error(L, ".handlerdata can't be used with .cantunwind directive");
8264 Error(CantUnwindLoc, ".cantunwind was specified here");
8268 getTargetStreamer().emitHandlerData();
8272 /// parseDirectiveSetFP
8273 /// ::= .setfp fpreg, spreg [, offset]
8274 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8275 // Check the ordering of unwind directives
8276 if (!FnStartLoc.isValid())
8277 return Error(L, ".fnstart must precede .setfp directive");
8278 if (HandlerDataLoc.isValid())
8279 return Error(L, ".setfp must precede .handlerdata directive");
8282 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8283 int NewFPReg = tryParseRegister();
8285 return Error(NewFPRegLoc, "frame pointer register expected");
8288 if (!Parser.getTok().is(AsmToken::Comma))
8289 return Error(Parser.getTok().getLoc(), "comma expected");
8290 Parser.Lex(); // skip comma
8293 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8294 int NewSPReg = tryParseRegister();
8296 return Error(NewSPRegLoc, "stack pointer register expected");
8298 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8299 return Error(NewSPRegLoc,
8300 "register should be either $sp or the latest fp register");
8302 // Update the frame pointer register
8307 if (Parser.getTok().is(AsmToken::Comma)) {
8308 Parser.Lex(); // skip comma
8310 if (Parser.getTok().isNot(AsmToken::Hash) &&
8311 Parser.getTok().isNot(AsmToken::Dollar)) {
8312 return Error(Parser.getTok().getLoc(), "'#' expected");
8314 Parser.Lex(); // skip hash token.
8316 const MCExpr *OffsetExpr;
8317 SMLoc ExLoc = Parser.getTok().getLoc();
8319 if (getParser().parseExpression(OffsetExpr, EndLoc))
8320 return Error(ExLoc, "malformed setfp offset");
8321 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8323 return Error(ExLoc, "setfp offset must be an immediate");
8325 Offset = CE->getValue();
8328 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8329 static_cast<unsigned>(NewSPReg), Offset);
8335 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8336 // Check the ordering of unwind directives
8337 if (!FnStartLoc.isValid())
8338 return Error(L, ".fnstart must precede .pad directive");
8339 if (HandlerDataLoc.isValid())
8340 return Error(L, ".pad must precede .handlerdata directive");
8343 if (Parser.getTok().isNot(AsmToken::Hash) &&
8344 Parser.getTok().isNot(AsmToken::Dollar)) {
8345 return Error(Parser.getTok().getLoc(), "'#' expected");
8347 Parser.Lex(); // skip hash token.
8349 const MCExpr *OffsetExpr;
8350 SMLoc ExLoc = Parser.getTok().getLoc();
8352 if (getParser().parseExpression(OffsetExpr, EndLoc))
8353 return Error(ExLoc, "malformed pad offset");
8354 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8356 return Error(ExLoc, "pad offset must be an immediate");
8358 getTargetStreamer().emitPad(CE->getValue());
8362 /// parseDirectiveRegSave
8363 /// ::= .save { registers }
8364 /// ::= .vsave { registers }
8365 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8366 // Check the ordering of unwind directives
8367 if (!FnStartLoc.isValid())
8368 return Error(L, ".fnstart must precede .save or .vsave directives");
8369 if (HandlerDataLoc.isValid())
8370 return Error(L, ".save or .vsave must precede .handlerdata directive");
8372 // RAII object to make sure parsed operands are deleted.
8373 struct CleanupObject {
8374 SmallVector<MCParsedAsmOperand *, 1> Operands;
8376 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8381 // Parse the register list
8382 if (parseRegisterList(CO.Operands))
8384 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
8385 if (!IsVector && !Op->isRegList())
8386 return Error(L, ".save expects GPR registers");
8387 if (IsVector && !Op->isDPRRegList())
8388 return Error(L, ".vsave expects DPR registers");
8390 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
8394 /// parseDirectiveInst
8395 /// ::= .inst opcode [, ...]
8396 /// ::= .inst.n opcode [, ...]
8397 /// ::= .inst.w opcode [, ...]
8398 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8410 Parser.eatToEndOfStatement();
8411 return Error(Loc, "cannot determine Thumb instruction size, "
8412 "use inst.n/inst.w instead");
8416 Parser.eatToEndOfStatement();
8417 return Error(Loc, "width suffixes are invalid in ARM mode");
8422 if (getLexer().is(AsmToken::EndOfStatement)) {
8423 Parser.eatToEndOfStatement();
8424 return Error(Loc, "expected expression following directive");
8430 if (getParser().parseExpression(Expr))
8431 return Error(Loc, "expected expression");
8433 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
8435 return Error(Loc, "expected constant expression");
8439 if (Value->getValue() > 0xffff)
8440 return Error(Loc, "inst.n operand is too big, use inst.w instead");
8443 if (Value->getValue() > 0xffffffff)
8445 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8448 llvm_unreachable("only supported widths are 2 and 4");
8451 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8453 if (getLexer().is(AsmToken::EndOfStatement))
8456 if (getLexer().isNot(AsmToken::Comma))
8457 return Error(Loc, "unexpected token in directive");
8466 /// parseDirectiveLtorg
8468 bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
8469 MCStreamer &Streamer = getParser().getStreamer();
8470 const MCSection *Section = Streamer.getCurrentSection().first;
8472 if (ConstantPool *CP = getConstantPool(Section)) {
8474 CP->emitEntries(Streamer);
8479 /// Force static initialization.
8480 extern "C" void LLVMInitializeARMAsmParser() {
8481 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8482 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8485 #define GET_REGISTER_MATCHER
8486 #define GET_SUBTARGET_FEATURE_NAME
8487 #define GET_MATCHER_IMPLEMENTATION
8488 #include "ARMGenAsmMatcher.inc"
8490 // Define this matcher function after the auto-generated include so we
8491 // have the match class enum definitions.
8492 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8494 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8495 // If the kind is a token for a literal immediate, check if our asm
8496 // operand matches. This is for InstAliases which have a fixed-value
8497 // immediate in the syntax.
8498 if (Kind == MCK__35_0 && Op->isImm()) {
8499 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8501 return Match_InvalidOperand;
8502 if (CE->getValue() == 0)
8503 return Match_Success;
8505 return Match_InvalidOperand;
8508 void ARMAsmParser::finishParse() {
8509 // Dump contents of assembler constant pools.
8510 MCStreamer &Streamer = getParser().getStreamer();
8511 for (ConstantPoolMapTy::iterator CPI = ConstantPools.begin(),
8512 CPE = ConstantPools.end();
8513 CPI != CPE; ++CPI) {
8514 const MCSection *Section = CPI->first;
8515 ConstantPool &CP = CPI->second;
8517 // Dump non-empty assembler constant pools at the end of the section.
8519 Streamer.SwitchSection(Section);
8520 CP.emitEntries(Streamer);